Java Q & A

             Core Java basic Questions and Answers



1. What is the most important feature of Java?
A. Java is a platform independent programming language.
------------------------------------------------------------------------------------------
2. What do you mean by platform independence?
A. Platform independence means that we can write once and compile the java code in one platform (eg        Windows) and can execute the class in any other supported platform . like linux,Mac etc.
-------------------------------------------------------------------------------------------
3. What is a JVM?
A. JVM stands for Java Virtual Machine which is a run time environment for the compiled java class files.
-------------------------------------------------------------------------------------------
4. Are JVM's platform independent?
A. It is not . JVM's are platform specific run time implementation provided by  the vendor . So JVM depends on OS
-------------------------------------------------------------------------------------------
5. difference between a JDK and a JVM?
A. JDK stands for Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence we will not be able to compile our source files using a JVM.
--------------------------------------------------------------------------------------------
6. What is the base class of all classes?
A. The base class is - java.lang.Object .
--------------------------------------------------------------------------------------------
7. Does Java support multiple inheritance?
A. Java doesn't support multiple inheritance.
--------------------------------------------------------------------------------------------
8. Is Java a pure object oriented language?
A. Java uses primitive data types and hence is not a pure object oriented language.but its support so many features of object oriented language.
----------------------------------------------------------------------------------------------
9. What are local variables?
A. Local varaiables are those which are declared within a block of code like methods. Local variables should be initialized before accessing them.
----------------------------------------------------------------------------------------------
10. What are instance variables?
A. Instance variables are those which are defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.
---------------------------------------------------------------------------------
11. How to define a constant variable in Java?
A. The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed .
Like eg, static final int PI = 2.14;
--------------------------------------------------------------------------------------------------
12. Should a main() method be compulsorily declared in all java classes?
A. No its not required. main() method should be defined only if the source class is a java application.
----------------------------------------------------------------------------------------------------
13. What is the return type of the main() method?
A. Main() method doesn't return anything hence declared void. Void is no return type.
-----------------------------------------------------------------------------------------------------
14. Why is the main() method declared static?
A. main() method is called by the JVM even before the instantiation of the class hence it is declared as static
-----------------------------------------------------------------------------------------------------
15. What is the argument of main() method?
A. main() method accepts an array of String object as argument .
-------------------------------------------------------------------------------------------------------

No comments:

Post a Comment