DEV Community

Jian Wei Tee
Jian Wei Tee

Posted on

Java Interview questions for Freshers (1-2)

Edited from: https://www.geeksforgeeks.org/java-interview-questions/

1. Is Java Platform Independent if then how?

Javac compiles the program into bytecode, which is stored in a .class file. This file can be executed on any operating system as long as a JVM (Java Virtual Machine) is preinstalled. Therefore, bytecode can be created on one system and executed on another, making Java platform-independent.

2. What are the top features of Java?

  • Simple: Java is simpler compared to other languages such as C and C++ because it eliminates the need to manually create and release allocated memory using pointers. Instead, Java implements a garbage collection mechanism to automatically release unused references.
  • Object-Oriented: Java is an object-oriented language that supports the concepts of classes and the four pillars of OOP (Object-Oriented Programming).

    • Encapsulation: Controls data access using access modifiers such as public, private, and protected.
    • Inheritance: Promotes code reuse by allowing a child class to inherit the properties and methods of a parent class.
    • Polymorphism: Enables a single method to behave differently based on the object that invokes it. This can be achieved through method overloading (compile-time polymorphism) and method overriding (runtime polymorphism).
    • Abstraction: Allows users to interact with an object through a well-defined interface without needing to understand its implementation details. This can be achieved using abstract classes and interfaces.
  • Multithreaded: Allows multiple threads to run concurrently within a program. A concurrency framework is provided under the java.util.concurrent package.

Top comments (0)