1. What is JDK, JRE, JVM and JIT? JDK: is JavaDevelopment Kit. It is a full-featured software development kit required to develop Java applications and applets. It includes the JRE (Java Runtime Environment), an interpreter/loader (Java), a compiler (javac), an archiver (jar), a documentation generator (Javadoc), and other tools needed for Java development. It’s used by developers for writing and compiling Java programs. (Compiler) JRE: is Java Runtime Environment. It provides the libraries, Java Virtual Machine (JVM), and other components to run Java applications. It doesn’t include tools for Java development like compilers. It’s used by end-users who just want to run Java applications. JVM: It converts bytecode (compiled Java code) into machine code that your computer's hardware can execute. It allows Java programs to be platform-independent, meaning you can run the same Java program on any device that has a JVM. (Interpreter) JIT: is Just In Time compiler. component of the JVM that improves the performance of Java applications. It combines the benefits of both interpretation and compilation, leading to optimized performance. Eg: JIT interprets a method once, if the same method is repeating again, it won’t interpret again. Instead it uses the already interpreted one before, thus saving time.

  2. What are variables? What are its types?

    A variable is a named location in memory that stores a value.(name of a memory address) In Java, variables can be declared and initialized in several ways.

    There are three types of variables in Java:

    1. Local: (defined within a block)

    2. Instance: (defined inside a class, outside a method)

    3. Static: (accessible by all methods of a class)

  3. What is the local variable? What is an instance variable? A local variable is declared inside a method or a block.(temporary variable) It can be used / accessed only within the method or block in which it is declared.(Local variables cannot be unassigned because there is no default value for local variables) An instance variable is declared inside a class but outside of any method. It is accessible to all the methods of the class.

  4. Difference between static and instance variable. 1) A static variable is declared with the static keyword. It is shared by all the instances of the class.

  1. Static variables are also known as class variables. We don’t need an object to access static variable.
  2. Static variables cannot be declared locally inside the method.
  3. Static variables are good for memory management.Static keyword creates/allocates memory during compile time. Static variables can be called inside all static methods, if the methods are within the same class.
  4. An instance variable is declared inside a class but outside of any method. It is accessible to all the methods of the class.(for object to object, different variable values in objects)
  5. Instance variables can be accessed only by creating objects.
  6. We initialize instance variables using constructors while creating an object.
  7. We may use access specifiers for instance variables. If not used, then it will be default.
  1. **What are data types? How many types?**Data types specify the different sizes and values that can be stored in the variable. There are two types of data types in Java:
  1. Primitive data type
  2. Non-primitive data type
  1. Primitive and non-primitive data types.

    Primitive data types are the eight basic data types in Java: boolean, char, byte, short, int, long, float, and double.

    Non-primitive data types are objects that are created using classes. They include classes, objects, interfaces, arrays, and strings.

    To Calculate range:

    -(2n-1) to +(2n-1-1)

    where ‘n’ is bits

    Java by default takes all numeric values as integers.

  2. **What is Java's primitive unsigned integral type?**char is the only unsigned primitive integral type. Unsigned means it can have only +ve values. Other integral types like byte, short, int and long have -ve values. char ranges from 0 to 65535.

  3. **What are conditional statements?**Conditional statements are used to make decisions in a program. It allows us to execute code based on whether a certain condition is true or false. There are two main types of conditional statements in Java:

  1. if statements (if, if else, if else if ladder, nested if)
  2. switch statements.
  1. Features of Java.

  2. What are classes and objects?

    A class is a group of objects which have common properties. It is a template or blueprint from which objects are created. It is a logical entity. It can't be physical (don’t have memory). A class encapsulates the data and the methods that operate on that data.

    Class is a combination of state and behavior. It is a keyword. It does not need memory allocation.

    State: variables and values

    Behavior: methods using that variables and values

    Object is a real time entity. It is a combination of state and behavior. It has both a logical and physical view. It has memory allocation.

    A class can contain:

    1. Methods

    2. Constructors

    3. Blocks

    4. Data types / Fields

    5. Interfaces and Nested classes

    An object is an instance of a class. It is a variable for a class.

    Classes and objects are essential building blocks of object-oriented programming. They allow us to create programs that are more organized, modular*(flexible)*, and maintainable.

  3. Difference between jump and break statements.

    They are used to control the flow of a program. The break statement is used to terminate a loop or a switch statement. Jump or Continue statement is used to skip a section and jump to the end of the loop.

  4. What are methods in Java? What are its types?

    A method is a block of code or collection of statements to perform certain operations or a task when it is called. It provides the reusability of code. The method is executed only when we call or invoke it.

    There are two types of methods in Java:

    1) User defined method: The method written by the programmer is known as a user-defined method. These methods are modified according to the requirement.

    2) Pre-defined method: Methods that are already defined in the Java class libraries are known as predefined methods.

  5. What is method signature?

    A method signature refers to the unique identifier of a method. Method Signature consists of the method name(Name of method) and its parameter list(arguments), return type(int, string, void, etc), access modifiers(public, private, protected), non-access modifiers(static, final, abstract), exceptions(throws IOException).

  6. How to use a method?

    In the case of a user defined method, First we have to define a method to perform a certain operation. Then, to use that method, we have to call that method by passing the parameters or simply calling it using the method name.

  7. What is the difference between a method and a function?

    A method and a function are both blocks of code that are executed when they are called.

    Methods are called using objects. Functions don’t need references to call.

    Methods are used within the class. Functions can be used anywhere.

  8. What is method overloading?

    A class having multiple methods with the same name but different in parameters, it is known as Method Overloading.

  9. What is a constructor? Types of overloading constructors.

    A constructor is a block of codes similar to the method. It is called when an instance of the class is created. It is a special type of method which is used to initialize the object.

    It(JVM) calls a default constructor if there is no constructor available in the class. Java compiler provides a default constructor by default.

    (At the time of calling the constructor, memory for the object is allocated in the memory.)

    There are two types of constructors in Java:

    1. no-arg constructor

    2. parameterized constructor

    Rues:

    A Java constructor cannot be abstract, static, final, and synchronized

    A Constructor does not have a return type

    Constructor name must be the same as its class name

    **Purpose:**To initialize objects with default values. To initialize the instance variable of the class. To inform about dependencies. In other words, using the constructor, we can request the user of that class for required dependencies.

  10. What is the ‘this’ keyword?

    this is a reference variable that refers to the current object.

    It is used to refer to the current instance variable.

    It is used in constructors to initialize object properties.

    this can be passed as an argument in the method call.

    this can be used to return the current class instance from the method.

  11. What is inheritance? What are its types?

    A class(sub-class) can acquire the properties and behaviors of its parent(base-class) class.

    We can create new classes that are built upon existing classes. When you inherit from an existing class, you can reuse methods and data types of the parent(base) class. Moreover, we can add new methods and data types in our current class also.

    There are 5 types of inheritance:

    1. single inheritance

    2. multilevel inheritance

    3. hierarchical inheritance

    4. hybrid inheritance

    5. multiple inheritance

  12. **Why is multiple inheritance not supported in java? Why do we use interface?**If a class inherits from two classes that have the same method name, there is no way to know which method to call when the inherited method is invoked. It will create confusion/ambiguity.Interfaces are used to achieve multiple inheritance in Java. An interface can be implemented by multiple classes, and each class can provide its own implementation of the interface methods. This allows a class to inherit the functionality of multiple interfaces without having to worry about conflicts between the implementations.