20 Basic Java Interview Questions - DevDummy


Views | Thoughts | Concepts | Techniques

Thursday, May 04, 2023

20 Basic Java Interview Questions


  1. What is Java? Java is a high-level, object-oriented programming language developed by Sun Microsystems. It is platform-independent and can run on any operating system that has a Java Virtual Machine (JVM) installed.

  2. What is the difference between JDK, JRE, and JVM? JDK (Java Development Kit) is a software development kit used to develop Java applications. JRE (Java Runtime Environment) is a software environment that provides the necessary runtime libraries and components required to run Java applications. JVM (Java Virtual Machine) is an abstract machine that provides the runtime environment in which Java bytecode is executed.

  3. What are the features of Java? Some of the features of Java are:

  • Platform independence
  • Object-oriented programming support
  • Robustness and reliability
  • Security
  • Multithreading
  • Dynamic memory allocation
  • Exception handling
  • Garbage collection

  1. What is a class in Java? A class in Java is a blueprint or template for creating objects. It contains data members (fields) and member functions (methods) that define the behavior of the objects created from it.

  2. What is an object in Java? An object in Java is an instance of a class. It has its own state (set of data) and behavior (set of methods) defined by the class.

  3. What is the difference between an interface and an abstract class? An interface is a collection of abstract methods (methods without a body) and constants that can be implemented by a class. An abstract class is a class that cannot be instantiated, but can have abstract methods and concrete methods with a body. A class can implement multiple interfaces, but can only inherit from one abstract class.

  4. What is inheritance in Java? Inheritance is a mechanism in which a new class is derived from an existing class. The new class inherits the data members and methods of the existing class and can add its own data members and methods. The existing class is called the superclass or base class, and the new class is called the subclass or derived class.

  5. What is polymorphism in Java? Polymorphism is the ability of an object to take on many forms. In Java, polymorphism can be achieved through method overloading and method overriding. Method overloading is when multiple methods have the same name but different parameters. Method overriding is when a subclass provides a specific implementation of a method that is already defined in its superclass.

  6. What is the difference between static and non-static methods? Static methods belong to the class rather than an instance of the class. They can be called without creating an object of the class. Non-static methods, on the other hand, belong to an instance of the class and can only be called on an object of the class.

  7. What is a package in Java? A package in Java is a mechanism for organizing related classes and interfaces into a single unit. It helps to avoid naming conflicts and provides better code organization and management.

  8. What is a constructor in Java? A constructor is a special method in a class that is used to initialize objects of that class. It has the same name as the class and does not have a return type.

  9. What is a method in Java? A method in Java is a set of instructions that perform a specific task. It can take input parameters and return a value.

  10. What is the difference between public, private, and protected access modifiers? Public members can be accessed from anywhere in the program. Private members can only be accessed within the same class. Protected members can be accessed within the same class and its subclasses.

  11. What is a static variable in Java? A static variable in Java belongs to the class rather than an instance of the class. It can be accessed without creating an object of the class

No comments:

Post a Comment