Skip to main content

Top 15 Java Interview Questions for 1–2 Years Experience – Real Answers

🟡 Top 15 Java Interview Questions for 1–2 Years Experience




If you're a Java developer with 1–2 years of experience, companies like TCS, Infosys, Capgemini, and Cognizant expect you to know Core Java, OOPs, Collections, and basic project-level concepts. Below are 15 most frequently asked questions with easy-to-remember answers.


Q1. What is the difference between JDK, JRE, and JVM?

 JVM (Java Virtual Machine)

  1. Definition: JVM is a virtual runtime environment that executes Java bytecode.

  2. Function: It converts bytecode (.class files) into machine-specific code, making Java platform-independent ("write once, run anywhere").

  3. Key Point: JVM doesn't understand .java files; it runs compiled .class files.

Example:
When you run a Java program using java MyClass, the JVM is what executes MyClass.class.


 JRE (Java Runtime Environment)

  1. Definition: JRE is a software package that contains JVM + core libraries + other components required to run Java applications.

  2. Function: It provides the environment to run already compiled Java programs.

  3. Key Point: It does NOT include development tools like the compiler (javac).

Use case:
If you're an end user just running a Java app (not developing), you only need JRE.


 JDK (Java Development Kit)

  1. Definition: JDK is a full-fledged development kit that includes everything in JRE plus development tools like javac, javadoc, javap, etc.

  2. Function: It is used to develop, compile, and debug Java applications.

  3. Key Point: JDK = JRE + Compiler + Debugger + Tools

Use case:
As a developer writing Java code, you need the JDK to compile .java files and produce .class files.

Q2. What is the difference between == and equals()?

Interview Answer: Difference Between == and equals() in Java

When you're asked in an interview about the difference between == and equals() in Java, here's a structured way to explain it confidently:


== Operator:

  • == is a reference comparison operator.

  • It checks whether two object references point to the same memory location.

  • For example:

    String s1 = new String("Java");
    String s2 = new String("Java");
    System.out.println(s1 == s2); // false
    

    Even though s1 and s2 have the same content, they are different objects in memory, so == returns false.


equals() Method:

  • equals() is a method defined in the Object class and is overridden by many classes like String, List, etc.

  • It is used to compare the actual content or value of two objects.

  • For example:

    System.out.println(s1.equals(s2)); // true
    

    This returns true because equals() checks the logical equality based on content.


📌 Key Differences:

Criteria == (Operator) equals() (Method)
Type Operator Method
Comparison Basis Reference (memory address) Content (logical equality)
Applicable On Primitives and Object References Objects (must override for custom classes)
Result true if references are same true if contents are same
Common Mistake Used accidentally for string comparison Recommended for string/value comparison


Q3. What are wrapper classes in Java?

Wrapper classes convert primitive types to objects. E.g., int → Integer, char → Character

Q4. What is method overloading?

When multiple methods in the same class have the same name but different parameters.

Q5. What is method overriding?

When a subclass provides a specific implementation of a method already defined in its superclass.

Q6. Difference between Abstract Class and Interface?

Interfaces support multiple inheritance and can’t have constructors. Abstract classes can have both abstract and non-abstract methods.

Q7. Difference between ArrayList and LinkedList?

ArrayList: Faster for accessing elements
LinkedList: Faster for inserting/deleting elements

Q8. What does the final keyword do?

It prevents change: final variable (constant), final method (can’t override), final class (can’t extend)

Q9. What is exception handling in Java?

Mechanism to handle runtime errors using try, catch, finally, and throws.

Q10. Checked vs Unchecked Exceptions?

Checked: Compile-time (e.g., IOException)
Unchecked: Runtime (e.g., NullPointerException)

Q11. What is String immutability?

Strings in Java are immutable. Once created, their values cannot be changed.

Q12. What are static methods and variables?

Belong to the class, not instance. Can be accessed without creating an object.

Q13. What is constructor overloading?

Creating multiple constructors in a class with different parameter lists.

Q14. What is garbage collection?

Automatic memory cleanup. Unused objects are removed by the Garbage Collector.

Q15. How to remove duplicates from an ArrayList?

Use LinkedHashSet to preserve order and remove duplicates.

Example logic: new ArrayList<>(new LinkedHashSet<>(list));


✅ Tips for Candidates:

  • Revise OOPs, Collections, Exception Handling
  • Be ready to explain your current project
  • Know how to write basic SQL queries

📅 Last Updated: 15 May 2025
📎 #JavaInterview #1YearExperience #JavaQnA

Comments

Popular posts from this blog

TCS Java Interview | Java | Spring Boot | Microservices | Database

TCS Java Interview | Java | Spring Boot | Microservices | Database This post is based on a Java backend developer interview simulation and provides direct transcript-based answers to help you prepare for similar interviews. 📺 This interview scenario was inspired by a video from the  YouTube channel:  CloudTech . 🔗 Watch the full video here:  https://www.youtube.com/watch?v=yVj2EgwZxk4 1. Can you introduce yourself and talk about your tech stack and domains? I have around 4.5 years of experience working as a Java developer. My core expertise is in Java and developing REST APIs using Spring Boot. I also have basic knowledge of microservices architecture. On the database side, I work with SQL and Oracle. Additionally, I have exposure to UI technologies like Angular, HTML, and CSS, but they are secondary skills. My primary focus is backend Java development. 2. Which version of Java are you currently working on? We are currently using Java 8 but are in the process of upgr...

Top 20 Spring Boot Microservices Architecture Interview Questions (With Speakable Answers)

Top 20 Spring Boot Microservices Architecture Interview Questions (With Speakable Answers) * * * 1. What is Microservices Architecture?   → Microservices architecture breaks an application into small, independent services. Each one handles a specific business function and can be developed, deployed, and scaled independently. They usually communicate over REST APIs or messaging queues. * * * 2. How does Spring Boot help in building microservices?   → Spring Boot offers embedded servers, auto-configuration, starter templates, and production-ready tools. It works well with Spring Cloud to provide service discovery, config management, load balancing, and more. * * * 3. What are the core components in a microservices setup?   → Key components include:   ✓ API Gateway   ✓ Eureka (Service Discovery)   ✓ Config Server   ✓ Kafka or RabbitMQ   ✓ Circuit Breaker (like Resilience4j)   ✓ Centralized logging and monitoring (ELK, Prometheus) * * * 4. What i...

Top 15 Spring Boot Interview Questions and Answers – Real Examples (2025)

Top 15 Spring Boot Interview Questions – 2025 Spring Boot is one of the most demanded frameworks for Java backend development. Whether you're interviewing for TCS, Infosys, or a product-based company, these Spring Boot questions will help you prepare like a pro. Here are 15 questions with detailed explanations for developers with 1–2 years of experience. Q1. What is Spring Boot? Answer: Spring Boot is a Java-based open-source framework built on top of the Spring Framework. It helps developers create stand-alone, production-ready Spring applications with minimal configuration. Its key features include: Auto-configuration Embedded servers (Tomcat, Jetty) Starter dependencies Production-ready tools (Actuator, Metrics, etc.) Example: You can create a REST API within minutes by using @RestController and spring-boot-starter-web — no need for external web server deployment. Q2. What is the role of @SpringBootApplication annotation? Answer: This annotation i...