Briefly explain why buffering could improve sequential file

Assignment Help Basic Computer Science
Reference no: EM13819518

1. Briefly explain one major advantage an if statement has over a switch statement and on significant advantage a switch statement has over an if statement.

  • If there are different conditions or complex condition, use if statement over switch.
  • If you are switching on the value of a single variable then use a switch every time, it's what the construct was made for.


2. Which of the following will cause an error message?

I. double x = 22.5;  int y = x;

II. double x = 22.5   int y = (int) x;

III. int x = 25;   double y = x;

A.    I only

B.    II only

C.    III only

D.    I and II only

E.    I and III only

3. List the three major looping constructs in Java and briefly explain the unique situation each is designed for.

Three Looping constructs in Java are:

  • For statement - executes group of Java statements as long as the boolean condition evaluates to true. it is pre test loop. The for loop is usually used when you need to iterate a given number of times. 


for(int i = 0; i < 100; i++)

{

    ...//do something for a 100 times.

}

  • While statement -The while loop is usually used when you need to repeat something until a given condition is true. The condition is determined at run time:

inputInvalid = true;

while(inputInvalid)

{

    //ask user for input

    invalidInput = checkValidInput();

}

  • Do while statement - A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time. 

The syntax of a do...while loop is:

do

{

   //Statements

}while(Boolean_expression);

4. What value would be output by the code segment below?

int x = 6 - 3 * 10 / 8 % 3;

System.out.println( x );

A.    -1
B.    0
C.    6
D.    -10
E.    5


5.  Briefly explain one significant advantage of using a get method to obtain the value of an instance variable vs reading the variable directly.
A get method can compute a value from several fields and return that value. This value cannot be calculated if variable is accessed directly.


6. Consider the following code segment.
int value = 17;

while ( value < 25 )

{

     System.out.println( value );

     value++;

}

What are the first and last numbers output by the code segment?

A.    17  24
B.    17  25
C.    18  24
D.    18  25
E.    18  26

7. Briefly explain the difference between a class instance variable and a method variable.

Instance variables belong to an instance of a class. Another way of saying that is instance variables belong to an object, since an object is an instance of a class. Every object has its own copy of the instance variables.

Method variables are local in method scope and they are not visible or accessible outside their scope which is determined by {} while instance variables are visible on all part of code based on their access modifier e.g. public , private or protected

8. Consider the following code.

public static void myFunc( int num )

 {

 int type1 = 0;

 int type2 = 0;
 int type3 = 0;

 for ( int i = 1; i <= num; i++ )

 {
if ( (i % 2 == 0 ) || ( i % 5 == 0 ) )

type1++;

if ( i % 2 == 0 )
type2++;

if ( i % 5 == 0 )

type3++;

}

System.out.println( type1 + "\t" + type2 + "\t" + type3 );

}

What is displayed as a result of the function call  myFunc( 50 )?
A.    5   20   5
B.    5   25   10
C.    30   25 10
D.    5   20   15

9. I want to create an array named myNumbers, of whole numbers which will hold the numbers zero through 10. Write a code snippet which will create and initialize this array.

Int my Numbers[]= {0,1,2,3,4,5,6,7,8,9,10};

10. Consider the following classes.

public class Parent

{

private int pData;

public Parent()



pData = 0; 

}

public Parent( int val )

{

pData = val;

}

}

 
public class child extends Parent

{

public Child()

{

super( 10 );

}

Which of the following statements will produce a complier error?

A.    Parent p = new Parent();
B.    Parent p = new Parent( 3 );
C.    Parent p = new Child();
D.    Child c = new Child();
E.    Child c = new Child( 5 );

11. Write a properly formatted if statement which checks if the contents of the String variable myName is the same as the String variable yourName. Have the code print Same if the contents are the same and Different if the contents are different. Assume the String variables have been previously defined and are not null.

If(myName.equals(yourName)) {

System.out.println("Same");

}else {

System.out.println("Different");

}

12. When designing a class hierarchy, which of the following should be true of a superclass?

A.    A superclass should be the most complex class in the hierarchy.
B.    The members of a superclass should be public in order to allow subclasses to access them.
C.    A superclass should contain attributes and functionality that are common to all subclasses.
D.    A superclass should contain the most specialized details of the class hierarchy.
E.    None of the above.

13. Briefly explain the restrictions imposed by three (3) of Java's scope (protection) modifiers.

Private - Methods, Variables and Constructors that are declared private can only be accessed within the declared class itself.
Variables that are declared private can be accessed outside the class if public getter methods are present in the class.

Public - A class, method, constructor, interface etc declared public can be accessed from any other class. Therefore fields, methods, blocks declared inside a public class can be accessed from any class belonging to the Java Universe.
Protected - Variables, methods and constructors which are declared protected in a superclass can be accessed only by the subclasses in other package or any class within the package of the protected members' class.

14. Consider the following class definitions. 


Public interface ClassA
{

public void methodA();


}


public class ClassB implements ClassA


{

public void methodA() { /* ... some code ... */ }

}

 

public class ClassC extends ClassB

{

public void methodC( ClassC obj ) { /* ... some code ... */ }

}


Which of the following statements would be valid in a client class?

I.    ClassA obj1 = new ClassB();

II.    ClassB obj2 = new ClassC();

III.    ClassA obj3 = new ClassC ();

A.    I only
B.    II only
C.    III only
D.    I and II only
E.    I, II, and III

15. Briefly explain the object oriented design concept of Containment.
Containment is where one object contains other objects - and it happens all over the place. A "town" object may, in a program, contain a number of "hotel" objects, a "location" object, zero or more "leisure" objects, "public transport hub" objects and so on.

16. Consider the following interface & class definitions.

public interface ClassA    

{

public void methodA();

}

 
public class ClassB implements ClassA

{

public void methodA() { /* ... some code ... */ }

}

 
public class ClassC extends ClassB

{

public void methodC( ClassC obj ) { /* ... some code ... */ }

}


Consider the following statements in a client class.

ClassC objC = new ClassC();

    ClassB objB = new ClassB(); 

Which of the following method calls would be permissible?

I.    objC.methodA();

II.    objB.methodC( objC );

III.    objC.methodC( objB );

 
A.    I only
B.    II only
C.    III only
D.    II and III only
E.    I, II, and III

17. Briefly explain one significant benefit of defining your own exceptions?
If you define your own exceptions, You can add extra context - so for example if you have your own AlreadyDownloadedException, say, that exception can have a method to retrieve the IP address from which the other download was started. Or an DownloadLimitExceededException could contain the current account download limit. Extra information in the custom exception allows you to potentially take a more well-informed response when catching it.

18.  The primary difference between a HashMap and a TreeMap is:

A.    The default size when an object of that type is created
B.    The types of objects they can hold
C.    How objects are stored internally
D.    The number and types of methods they implement
E.    The types of exceptions that may be thrown

19. Briefly explain why the Java code snippet below will not work as intended (and may produce a compile error)?

.... try

{ // myDumbMethod() could result in various different exceptions.

this.myDumbMethod();

}

catch (Exception except)

{

System.out.println("Exception: " + except.getMessage());

}

catch (IOException except)

{

System.out.println("IOException: " + except.getMessage());

}

......

Answer:

The specific type of exception should be caught first.  So the IOException should be first in catch hierarchy then the class Exception should be used

20.  Select the terms that best fit this sentence. The default size of a/an __________ object is __________ elements.

A.    LinkedList
B.    TreeMap
C.    32
D.    10
E.    ArrayList

Answer is no one, default size of LinkedList, TreeMap and ArrayList is 0 elemets.

Or the question is incorrect

21. Briefly explain the why buffering could improve sequential file input/output throughput.

In general, a Writer sends its output immediately to the underlying character or byte stream. Unless prompt output is required, it is advisable to wrap a BufferedWriter around any Writer whose write() operations may be costly, such as FileWriters and OutputStreamWriters For example,

 PrintWriter out    = new PrintWriter(new BufferedWriter(new 

FileWriter("foo.out")));   

will buffer the PrintWriter's output to the file. Without buffering, each invocation of a print() method would cause characters to be converted into bytes that would then be written immediately to the file, which can be very inefficient. 


22.  How many events are generated when a user selects a JComboBox item?

A.    1
B.    2
C.    3
D.    4
E.    5


23. Briefly explain how Java serialization is used.

Java provides Serialization API, a standard mechanism to handle object serialization. To persist an object in java, the first step is to flatten the object. For that the respective class should implement "java.io.Serializable" interface. Thats it. We dont need to implement any methods as this interface do not have any methods. This is a marker interface/tag interface. Marking a class as Serializable indicates the underlying API that this object can be flattened.


24. Objects that want to be notified when an event occurs are called __listeneres________. (one word, plural)

25. Briefly explain what major restriction Java applets have which normal Java programs do not and why this is the case.

Applets that are not signed are restricted to the security sandbox, and run only if the user accepts the applet. Applets that are signed by a certificate from a recognized certificate authority can either run only in the sandbox, or can request permission to run outside the sandbox. In either case, the user must accept the applet's security certificate, otherwise the applet is blocked from running.

Reference no: EM13819518

Questions Cloud

Explain how collaborative consultation model is different : Explain how the collaborative consultation model is different than the co-teaching model of inclusive education including its strengths and weakness in providing equal education.
Discusses the impact that regulations have on ethics : Write a one page paper discusses the impact that regulations, accounting and auditing standards, emerging issues, and the business environment have on ethics.
Determine whether or not this merger or acquisition : For The Corporation That Has Acquired Another Company, Merged With Another Company, Or Been Acquired By Another Company, Evaluate The Strategy That Led To The Merger Or Acquisition To Determine Whether Or Not This Merger Or Acquisition Was A Wise Cho..
Create a business scenario : Create a business scenario in which to hold a business meeting to solve a problem
Briefly explain why buffering could improve sequential file : Briefly explain how Java serialization is used. Briefly explain what major restriction Java applets have which normal Java programs do not and why this is the case. . Briefly explain the why buffering could improve sequential file input/output throug..
Diseases appear out of nowhere & rapidly : The text states that some diseases appear out of 'nowhere' & rapidly can become lethal. Research one of these diseases (ie: SARS, Group A Strep, E.Coli 0157:H7, drug-resistant TB, etc.) and share the information with the group (what causes it, sign/s..
Presentation for a venture capitalist : For a fictitious business you want to start, develop a PowerPoint presentation for a venture capitalist. Include a Notes view with the words you plan to use in the presentation
Write on assessment tool ethics in psychological assessment : Write about the assessment tool "Brief Intervention in College Settings", "Assessing Addiction: Concepts and Instruments" and "Ethics in Psychological Assessment".
Ethics that focus on the salesperson actions : There are many different approaches to ethics that focus on the salesperson's actions when utilizing these approaches. Give a specific example of what buyers might consider appropriate or inappropriate behavior

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd