1. briefly explain one major advantage

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;
    //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:

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 );
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 ) )
      if ( i % 2 == 0 )
      if ( i % 5 == 0 )
    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 myNumbers[]= {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)) {
      }else {

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.
catch (Exception except)
System.out.println(“Exception: “ + except.getMessage());
catch (IOException except)
System.out.println(“IOException: “ + except.getMessage());
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
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.

University Writings
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.


Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.


Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.


Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.


Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.