Java question set - 2

1) Why pointers are eliminated from java?

     a.Pointers lead to confusion for a programmer.

     b. Pointers may crash a program easily, for example, when we add two pointers, the program crashers
Immediately.

     c. Pointers break security. Using pointers, harmful programs like Virus and other hacking programs
Can be developed. Because of the above reasons, pointers have been eliminated from java.

2) What is the difference between a function and a method?

       A method is a function that is written in a class. We do not have functions in java; instead we Have methods. This means whenever a function is written in java. It should be written inside the class only. But if we take C++, we can write the functions inside as well as outside the class. So in C++, They are called member functions and not methods.

3) Which part of JVM will allocate the memory for a java program?

       Class loader subsystem of JVM will allocate the necessary memory needed by the java Program.

4). which algorithm is used by garbage collector to remove the unused variables or
Objects from memory?

      Garbage collector uses many algorithms but the most commonly used algorithm is mark and sweep.

5). How can you call the garbage collector?

       Garbage collector is automatically invoked when the program is being run. It can be also called by calling gc() method of Runtime class or System class in Java.

6) What is JIT Compiler?

       JIT compiler is the part of JVM which increases the speed of execution of a Java program.

7) What is an API document?

       An API document is an .html file that contains description of all the features of a software, a product, or a technology. API document is helpful for the user to understand how to use the software or technology.

8) What is the difference between #include and import statement?

      #include directive makes the compiler go to the C/C++ standard library and copy the code from the header files into the program. As a result, the program size increases, thus wasting memory and

Processor’s time. Import statement makes the JVM go to the Java standard library, execute the code there, and substitute the result into the program. Here, no code is copied and hence no waste of Memory or processor’s time.so import is an efficient mechanism than #include.
9) What is the difference between print( ) and println( ) method ?

      Both methods are used to display the results on the monitor . print( ) method displays the result and then retains the cursor in the same line, next to the end of the result. println( ) displays the result and then throws the cursor to the next line.

10) What happens if String args[] is not written in main( ) method ?

      When main( ) method is written without String args[] as: Public static void main( ) The code will compile but JVM cannot run the code because it cannot recognize the main( ) as the method from where it should start execution of the Java program. Remember JVM always looks for main( ) method with string type array as parameter.

11) What is the difference between float and double?

      Float can represent up to 7 digits accurately after decimal point, whereas double can represent up to 15 digits accurately after decimal point.

12) What is a Unicode system?

      Unicode system is an encoding standard that provides a unique number for every character, no matter what the platform, program, or language is. Unicode uses 2 bytes to represent a single character.

13) How are positive and negative numbers represented internally?

     Positive numbers are represented in binary using 1’s complement notation and negative numbers are represented by using 2’s complement notation.

14) What is the difference between >> and >>>?

     Both bitwise right shift operator ( >> ) and bitwise zero fill right shift operator( >>> ) are used to shift the bits towards right. The difference is that >> will protect the sign bit whereas the >>> operator will not protect the sign bit. It always fills 0 in the sign bit.

15) What are control statements?

      Control statements are the statements which alter the flow of execution and provide better control to the programmer on the flow of execution. They are useful to write better and complex programs.

16) Out of do..while and while - - which loop is efficient ?

      In a do-while loop, the statements are executed without testing the condition, the first time. From the second time only the condition is observed. This means that the programmer does not have control right from the beginning of its execution. In a while loop, the condition is tested first and then only the statements are executed. This means it provides better control right from the beginning. Hence, while loop is move efficient than do.. While loop.


17) What is a collection?

       A collection represents a group of elements like integer values or objects. Examples for collections are arrays and java.util_classes (stack, LinkedList, ;Vector, etc).

18) Why goto statements are not available in Java?

      Goto statements lead to confusion for a programmer. Especially in a large program, if several goto statements are used, the programmer would be preplexed while understanding the flow from where to where the control is jumping.

19) What is the difference between return and System.exit(0) ?

      Return statement is used inside a method to come out of it. System.exit( 0) is used in any method to come of the program.

20) What is the difference between System.out.exit(0) and System.exit(1) ?

      System.exit(0) terminates the program normally. Whereas System.exit(1) terminates the program because of some error encountered in the program.

No comments:

Post a Comment