1. What is Java?
Java is a high-level, object-oriented programming language developed by Sun Microsystems (now owned by Oracle). It is known for its platform independence, meaning that Java programs can run on any device that has a Java Virtual Machine (JVM).
2. What are the main features of Java?
Some of the main features of Java include: – Object-oriented: Java follows the object-oriented programming paradigm, making it easier to organize and manage complex code. – Platform independence: Java programs can run on any device that has a JVM, regardless of the underlying hardware and operating system. – Garbage collection: Java automatically manages memory allocation and deallocation, reducing the risk of memory leaks. – Exception handling: Java provides robust mechanisms for handling errors and exceptions, improving program reliability. – Multithreading: Java supports multithreading, allowing programs to execute multiple tasks simultaneously and efficiently utilize system resources
3. What is the difference between JDK, JRE, and JVM?
JDK (Java Development Kit) is a software development kit that includes tools for developing Java applications, such as the compiler and debugger. – JRE (Java Runtime Environment) is a runtime environment that is required to run Java applications. It includes the JVM and other libraries and components necessary for executing Java bytecode. – JVM (Java Virtual Machine) is an abstract computing machine that provides an environment for executing Java bytecode. It interprets the bytecode and translates it into machine code that can be executed by the underlying hardware.
4. What is the difference between == and .equals() method in Java?
The == operator in Java is used to compare the references of two objects, i.e., whether they refer to the same memory location. – The .equals() method, on the other hand, is a method defined in the Object class that is used to compare the contents of two objects for equality. It is often overridden in subclasses to provide custom equality comparison logic.
5. What is the difference between abstract class and interface in Java?
An abstract class in Java is a class that cannot be instantiated and may contain abstract methods (methods without a body) as well as concrete methods. Subclasses of an abstract class must implement all its abstract methods or be declared abstract themselves. – An interface in Java is a collection of abstract methods and constant declarations. Unlike abstract classes, interfaces cannot contain concrete methods or instance variables. Classes can implement multiple interfaces but can only extend one class.
6. What is the difference between checked and unchecked exceptions in Java?
Checked exceptions are exceptions that are checked at compile time. This means that the compiler will enforce handling of these exceptions either by using a try-catch block or by declaring them in the throws clause of the method signature. – Unchecked exceptions, on the other hand, are exceptions that are not checked at compile time. They typically occur due to programming errors such as null pointer dereferences or arithmetic overflows. Handling of unchecked exceptions is optional.These are just a few examples of Java interview questions. Depending on the level of the interview and the specific job requirements, questions may vary in complexity and focus.