CORE JAVA INTERVIEW QUESTIONS WITH ANSWERS
CORE JAVA, JAVA IMPORTANT AND VIVA QUESTIONS FOR B.Sc, MSc, MCA, B-TECH
1. Explain JDK, JRE, JVM.
- JVM: It is an acronym for Java virtual machine, which provides the runtime environment in which java byte code can be executed.
- JRE: It stands for Java Runtime Environment.It is the implementation of JVM and physically exists.
- JDK: It is an acronym for Java Development kit. It contains JRE development tools.
2. How many types of memory areas are allocated by JVM?
- Class(Method) Area
- Heap
- Stack
- Program Counter Register
- Native method Stack
- PC (Program Counter) Register
- Native Method Stack
3. What is a Platform? Difference between Java and other platforms.
- A Platform is basically the hardware or software environment in which a program runs. There are two types of platforms software - based and hardware - based. Java provides software - based platform.
4. What is the most important feature of Java?
- Java is a platform independent language.
5. What do you mean by Platform Independence?
- Platform independence means that we can write and compile the Java code in one platform and can execute the class in any other supported platform.
6. What is a pointer and does Java support pointers?
- Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn't support the usage of pointers.
7. Does Java support Multiple Inheritance.
- Java doesn't support multiple Inheritance. To overcome Multiple Inheritance we use a concept called Interface.
8. Are Arrays Primitive Datatypes?
- In Java arrays are object.
9. What is the difference between Path and Classpath?
- Path and Classpath are operating system level environment variables. Path is used to define where the system can find the executable files and classpath is used to specify the location.
10. What are local variables?
- Local variables are those which are declared within a block of code like methods. Local variables would be initialized before accessing them.
11. What gives Java its write once and run anywhere nature?
- The byte code. Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platform specific and hence can be fed to any platform.
12. What if i write static public void instead of public static void?
- It is empty. But not null.
13. What is Constructor?
- Constructor is just like a method that is used to initialize the state of an object. It is invoked at the time of object creation.
14. Does constructor return any value?
- Yes, that is current instance.
15. Is constructor inherited?
- No, constructor is not inherited.
16. What is static variable?
- Static variable is used to refer the common property of all objects. It gets memory only once in class area at the time of class loading.
17. What are Instance variables?
- 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.
18. Should a main() method be compulsorily declared in all java classes?
- No not required. It should be defined only if the source class is a java application.
19. What is return type of the main() method?
- Main() method doesn't return anything hence declare void.
20. Why is the main() method declared static?
- Main() method is called by the JVM even before the initiation of the class hence it is declared as static.
21. What is the argument of main() method?
- Main() method accepts an array of string object as argument.
22. Can a main() method be overloaded?
- YES.
23. Can a main() method be declared at last?
- YES. Any inheriting class will not be able to have it's own default main() method.
24. Can a source file contain more than one class declaration?
- Yes a single source file can contain any number of class declarations but only one of the class can be declared as public.
25. What is a Package?
- It is a collection of related classes and interfaces. Package declarations should be first statement in a java class.
26. What is the access scope of a protected method?
- A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.
27. Can you give few examples of final classes defined in Java API?
- java lang String, java lang Math are final classes.
28. When will you define a method as static?
- When a method needs to be accessed even before the creation of the object of the class the method as static.
29. I want to print "Hello" even before main() is executed. How will you achieve that?
- Print the statement inside a static block of code. Static blocks get executed when the class gets loaded into the memory and even before the creation of an object. Hence it will be executed before the main() method. And it will be executed only once.
30. When will you define method as static?
- When a method needs to be accessed even before the creation of the object of the class then we should declare the method as static.
No comments:
Post a Comment
May I Help you