🚀 50 Important Questions & Answers on Java Basics and Basic OOP (Without Inheritance)

A strong foundation in Java fundamentals is essential before moving into advanced topics like inheritance, polymorphism, and multithreading ☕

This article contains 50 carefully structured questions and answers divided into two major sections:

  • 🟢 Section 1: Java Basics (25 Questions)
  • 🔵 Section 2: Loops and Basic OOP (25 Questions)

These questions are ideal for:

  • 📘 Exam preparation
  • 🎤 Viva preparation
  • 💻 Practical revision
  • 🧠 Concept strengthening

🟢 SECTION 1: 25 QUESTIONS ON JAVA BASICS


1️⃣ What is Java?

Java is a high-level, object-oriented, platform-independent programming language developed by Sun Microsystems (now Oracle).


2️⃣ What are the features of Java?

  • Platform Independent 🌍
  • Object-Oriented
  • Secure 🔐
  • Robust
  • Multithreaded
  • Portable

3️⃣ What is JVM?

JVM (Java Virtual Machine) executes Java bytecode and converts it into machine code.


4️⃣ What is JRE?

JRE (Java Runtime Environment) provides libraries and JVM required to run Java programs.


5️⃣ What is JDK?

JDK (Java Development Kit) is used to develop Java applications.

📌 JDK = JRE + Development Tools


6️⃣ What is bytecode?

Bytecode is the intermediate code generated after compilation, executed by JVM.


7️⃣ What are primitive data types in Java?

  • byte
  • short
  • int
  • long
  • float
  • double
  • char
  • boolean

8️⃣ What is the size of int in Java?

int occupies 4 bytes (32 bits).


9️⃣ What is the difference between float and double?

  • float → 4 bytes
  • double → 8 bytes
  • double has more precision

🔟 What is a variable?

A variable is a named memory location used to store data.


1️⃣1️⃣ What is type casting?

Type casting converts one data type to another.

Example:

int a = (int) 5.5;

1️⃣2️⃣ What is an operator?

Operators perform operations on variables.

Types:

  • Arithmetic (+, -, *, /)
  • Relational
  • Logical
  • Assignment

1️⃣3️⃣ What is the difference between == and equals()?

  • == compares references
  • equals() compares content

1️⃣4️⃣ What is the main method?

Entry point of Java program:

public static void main(String[] args)

1️⃣5️⃣ Why is main method static?

Because JVM calls it without creating an object.


1️⃣6️⃣ What is a package?

A package is a group of related classes.

Example:

package mypackage;

1️⃣7️⃣ What is the default value of int?

Default value of int is 0.


1️⃣8️⃣ What is garbage collection?

Automatic memory cleanup process handled by JVM 🧹


1️⃣9️⃣ What is the difference between JDK, JRE, and JVM?

| JDK | Development |
| JRE | Runtime |
| JVM | Execution |


2️⃣0️⃣ What is a constant?

A constant is declared using final.

final int x = 10;

2️⃣1️⃣ What is String in Java?

String is a class used to store text.


2️⃣2️⃣ Is String mutable?

No. String is immutable.


2️⃣3️⃣ What is Scanner class?

Scanner is used for user input.

Scanner sc = new Scanner(System.in);

2️⃣4️⃣ What is an array?

An array stores multiple values of same type.


2️⃣5️⃣ What is compilation in Java?

Process of converting source code (.java) into bytecode (.class).


🔵 SECTION 2: 25 QUESTIONS ON LOOPS AND BASIC OOP


2️⃣6️⃣ What is a loop?

A loop is used to repeat a block of code 🔁


2️⃣7️⃣ Types of loops in Java?

  • for loop
  • while loop
  • do-while loop

2️⃣8️⃣ Difference between while and do-while?

  • while → checks condition first
  • do-while → executes once before checking

2️⃣9️⃣ What is an infinite loop?

A loop that never ends due to wrong condition.


3️⃣0️⃣ What is break statement?

Terminates loop immediately.


3️⃣1️⃣ What is continue statement?

Skips current iteration.


3️⃣2️⃣ What is nested loop?

A loop inside another loop.


3️⃣3️⃣ What is a class?

A blueprint used to create objects 🏗️


3️⃣4️⃣ What is an object?

An instance of a class 🎯


3️⃣5️⃣ What is the new keyword?

Creates object and allocates memory.


3️⃣6️⃣ What is a method?

A block of code that performs a task 🧩


3️⃣7️⃣ What is method overloading?

Same method name with different parameters.


3️⃣8️⃣ What is a constructor?

Special method used to initialize object.


3️⃣9️⃣ What is default constructor?

Constructor provided automatically if none defined.


4️⃣0️⃣ What is the this keyword?

Refers to current object.


4️⃣1️⃣ What is static variable?

Shared among all objects.


4️⃣2️⃣ What is static method?

Belongs to class and can be called without object.


4️⃣3️⃣ Can static method access non-static variables?

No ❌


4️⃣4️⃣ What are access modifiers?

private, default, protected, public


4️⃣5️⃣ What is encapsulation?

Data hiding using private variables and public methods 🔐


4️⃣6️⃣ What is an abstract class?

A class declared with abstract keyword that cannot be instantiated.


4️⃣7️⃣ What is recursion?

A method calling itself.


4️⃣8️⃣ What is method signature?

Method name + parameter list.


4️⃣9️⃣ Difference between local and instance variable?

  • Local → inside method
  • Instance → inside class

5️⃣0️⃣ What is memory allocation in Java?

  • Stack → stores local variables
  • Heap → stores objects

🎯 Final Revision Summary

This 50-question set covers:

✔ Java environment
✔ Data types
✔ Operators
✔ Strings
✔ Loops
✔ Classes & Objects
✔ Methods
✔ Constructors
✔ Static
✔ Encapsulation
✔ Memory basics


✅ Conclusion

Strong command over Java basics and core OOP concepts builds confidence for:

  • 📘 University exams
  • 💻 Practical labs
  • 🎤 Viva sessions
  • 🚀 Advanced topics

Before learning inheritance and advanced OOP, these 50 questions should be thoroughly understood and revised.

Clear fundamentals lead to powerful programming skills 💪

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *