What is Java?

    Java is a multi-platform, object-oriented, and network-centric language that can be used as a platform in itself. It is a fast, secure, reliable programming language for coding everything from mobile apps and enterprise software to big data applications and server-side technologies.

    What is Java Virtual Machine?

    The Java Virtual Machine acts as an additional abstraction layer between the Java platform and the underlying machine hardware. Java source code can run only on those machines that have JVM installed on them. The answer to why the Java Virtual Machine is needed lies in the history of programming.

    What is Oops?

    Oops is concept which is used to convert real world entities into object and classes.

    OOPS concepts are as follows:

    1. Class
    2. Object
    3. Method and method passing
    4. Pillars of OOPs
      • Abstraction
      • Encapsulation
      • Inheritance
      • Polymorphism
        • Compile-time polymorphism
        • Runtime polymorphism
      • Association
      • Aggregation
      • Composition

    What is Collections in Java?

    The Collection in Java is a framework that provides an architecture to store and manipulate the group of objects.

    Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion.

    Java Collection means a single unit of objects. Java Collection framework provides many interfaces (Set, List, Queue, Deque) and classes (ArrayList, Vector, LinkedList, PriorityQueue, HashSet, LinkedHashSet, TreeSet).

    • The primary advantages of a collections framework are that it:
      1. Reduces programming effort by providing data structures and algorithms so you don't have to write them yourself.
      2. Increases performance by providing high-performance implementations of data structures and algorithms. Because the various implementations of each interface are interchangeable, programs can be tuned by switching implementations.
      3. Provides interoperability between unrelated APIs by establishing a common language to pass collections back and forth.
      4. Reduces the effort required to learn APIs by requiring you to learn multiple ad hoc collection APIs.
      5. Reduces the effort required to design and implement APIs by not requiring you to produce ad hoc collections APIs.
      6. Fosters software reuse by providing a standard interface for collections and algorithms with which to manipulate them.

    What is Multithreading?

    Multithreading is a process of executing two or more threads simultaneously for maximum utilization of the CPU. A thread in Java is a lightweight process requiring fewer resources to create and share the process resources.

    Multithreading and Multiprocessing are used for multitasking in Java, but we prefer multithreading over multiprocessing. This is because the threads use a shared memory area which helps to save memory, and also, the content-switching between the threads is a bit faster than the process.

    Few more advantages of Multithreading are:

    • Multithreading saves time as you can perform multiple operations together.
    • The threads are independent, so it does not block the user to perform multiple operations at the same time and also, if an exception occurs in a single thread, it does not affect other threads.
    Life Cycle of a Thread

    There are five states a thread has to go through in its life cycle. This life cycle is controlled by JVM (Java Virtual Machine). These states are:

    1. New
    2. Runnable
    3. Running
    4. Non-Runnable (Blocked)
    5. Terminated

    1. New

    In this state, a new thread begins its life cycle. This is also called a born thread. The thread is in the new state if you create an instance of Thread class but before the invocation of the start() method.

    2. Runnable

    A thread becomes runnable after a newly born thread is started. In this state, a thread would be executing its task.

    3. Running

    When the thread scheduler selects the thread then, that thread would be in a running state.

    4. Non-Runnable (Blocked)

    The thread is still alive in this state, but currently, it is not eligible to run.

    5. Terminated

    A thread is terminated due to the following reasons:

    • Either its run() method exists normally, i.e., the thread’s code has executed the program.
    • Or due to some unusual errors like segmentation fault or an unhandled exception.

    A thread that is in a terminated state does not consume ant cycle of the CPU.