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

  Electronic communications privacy act ecpa

Electronic Communications Privacy Act (ECPA)

  Determine how to diagnose and reseat the ram

A user complains that her computer is responding very slowly. She also says that when booting the PC, it reports a lower value for memory than she assumed is available. You investigate and consider the idea that one of the RAM sticks in her PC may..

  Demonstrate ability to integrate and apply information

demonstrate ability to integrate and apply information from various topics and to apply understanding and knowledge to a practical situation.

  Describe how to use d

Suppose you have two nonempty stacks S and T and a deque D. Describe how to use D so that S stores all the elements of T below all of its original elements, with both sets of elements still in their original order.

  Write a program perform using mars - assembly language

Write a program which will perform the following " using MARS - Assembly language" a. Read in a string from the user b

  What are some business uses for inserting a canvas

Write a response that answers the following: What are some business uses for inserting a canvas in a Microsoft® Word document. From these uses, propose a strategy that may help users overcome formatting issues.

  Design a modified priority encoder

Design a modified priority encoder that receives an 8-bit input, A7:0, and produces two 3-bit outputsm Y2:0 and Z 2:0 Y indicates the most significant bit of the input that is TRUE

  Using positive edge triggered t

Using positive edge triggered T flip flops, show the design of a modulo 7 asynchronous counter that counts 0,1...6,0, etc. You may assume that your flip flop

  Explain the five activities of systems analysis

In a one-page paper: explain the five activities of systems analysis and offer any additional activities you feel should be added (from your reading or experience).

  Show the musical instrument inventory

2. Stefan lano needs displays that will show the musical instrument inventory in his chain of music stores that caters to musicians playing in world-class symphomy orchestras in basel, Switzerland; Buenos aires, argentina; and Philadelphia and..

  Write a java program to demonstrate the use of linked-lists

Once you have processed the d4.dat file and the d4.delete file, it is a simple matter of iterating over the list and writing the object data to the outputfile. The output file size will be 22,725 or 27,270 bytes depending on platform and methods u..

  What are some of the more popular database management system

What are some of the more popular database management systems? Why use Oracle?

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