Java Interview Guide: Section 1 & 2.
1. Introduction to Java
1. What is the most important feature of Java?\ Platform independence: Java code can run on any
platform with a JVM.
2. What do you mean by platform independent?\ Compiled Java bytecode can run on any OS using JVM.
3. What is a JVM?\ Java Virtual Machine executes Java bytecode and provides runtime services.
4. Are JVMs platform independent?\ No. JVMs are platform-specific, but bytecode is platform-independent.
5. What is the difference between a JDK and a JVM?
• JVM: Runs Java programs
• JDK: Contains tools to develop, compile, and run Java applications (includes JVM).
6. What is a pointer, and does Java support pointers?\ A pointer stores memory address. Java does not
support them directly.
7. What is JIT compiler?\ Just-In-Time compiler converts bytecode into native code at runtime to improve
performance.
2.1 Java Basic Programming Elements
1. Why do we need objects in Java?\ Objects help organize code around real-world entities and support
reusability.
2. What is an Object?\ An instance of a class containing fields and methods.
3. What is an instance?\ A specific object created from a class.
4. Difference between class, interface, and enum?
• Class: Blueprint of objects
• Interface: Contract for classes (no implementation)
• Enum: Fixed set of constants
5. Why enum?\ To define constants in a type-safe way.
6. Is main method mandatory for compilation or execution?\ Not for compilation, but required for
execution.
1
7. What is a user-defined method and predefined method?
• User-defined: Created by programmer
• Predefined: Provided by Java
8. What is a user-defined class and predefined class?
• User-defined: Made by developer
• Predefined: Provided by Java libraries
9. Does JVM execute user-defined methods automatically?\ No. It only executes the main method.
10. Definition of main method?\ public static void main(String[] args)
11. How many user-defined methods can we define in a class?\ Any number.
12. Order of execution of user-defined methods?\ Depends on calling order in main() or other methods.
13. Difference between [Link]() and [Link]()?
• println(): Adds new line after output
• print(): No newline
14. Why Coding Standards?\ Improves readability, maintainability, and reduces errors.
15. If we don’t follow coding standards, will it cause errors?\ No compilation/runtime errors, but it leads
to poor readability.
16. What is base class of all classes?\ [Link]
17. Does Java support multiple inheritance?\ Not through classes, but supports via interfaces.
18. Is array primitive data type?\ No, it's an object.
19. Difference between Path and Classpath?
• Path: OS uses it to find executables
• Classpath: JVM uses it to find .class files
20. What are local variables?\ Declared inside methods, used only within those methods.
21. How to define constant variable in Java?\ Use final keyword.
22. Should main() method be in all classes?\ No. Only required in the entry point class.
23. What is return type of main() method?\ void
2
24. Why is main() static?\ So JVM can call it without creating an object.
25. What is argument of main method?\ String[] args (Command-line arguments)
26. Can main() method be overloaded?\ Yes, but JVM only calls the standard main method.
27. Can main() be declared final?\ Yes, but it doesn't affect execution.
28. Does order of public/static matter?\ No. public static and static public both are valid.
29. Can a source file contain more than one class?\ Yes, but only one public class.
30. What is a package?\ A group of related classes.
31. Which package is imported by default?\ [Link]
32. Can a class be declared protected?\ Top-level classes cannot be protected .
yes