Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

Java Interview Questions

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Java Interview Questions

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Java Interview Questions

Java Basic

JVM, JDK, JRE


Can you explain the difference between the JVM, JDK, and JRE ?

What is the JVM and what is its role in running Java applications ?

Why is the JVM considered platform-independent ?

reference:

Java™ Platform Overview (oracle.com)

Java SE - Technologies | Oracle Technology Network | Oracle

Description of Java Conceptual Diagram (oracle.com)

Heap, Stack Memory

What is the difference between heap memory and stack memory in Java ?
How are objects stored in heap memory ?

Can you explain how stack memory works in method execution ?


What happens to stack memory when a method call is completed ?

What happens to stack memory when an exception is thrown ?

reference:

Chapter 2. The Structure of the Java Virtual Machine (oracle.com)

Data Type
What are the different primitive data types in Java?

How do primitive data types differ from reference types in Java?

Can you give examples of implicit and explicit type casting with primitive data types?

Describle wrapper class in Java ?

What is Autoboxing and Unboxing ?

reference:

Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language
Basics) (oracle.com)

The Numbers Classes (The Java™ Tutorials > Learning the Java Language >
Numbers and Strings) (oracle.com)

Autoboxing and Unboxing (The Java™ Tutorials > Learning the Java Language >
Numbers and Strings) (oracle.com)

Variable
How many type of variables in Java ? Can you differ among us ?

What does static keyword mean in Java ?

Can you distinguish between static variable and non-static variable ?

Can you distinguish between static method and non-static method ?

What is a constant in Java and how is it declared ?

Can we declare a constant method or a constant class ?

reference:

Variables (The Java™ Tutorials > Learning the Java Language > Language Basics)

(oracle.com) Operator, Default Value

What are the different types of operators available in Java?

What is the default value for uninitialized variables of different data types ?

What is the default value for uninitialized variables of different variable type ?

reference:
Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)

(oracle.com) Array

How do you declare, initialize, and access elements in an array in Java ?

What is maximum length of array ?

Difference between anonymous array and named array ?

Can an array change it's elements when it is declared as a constant ?

How to create a copy of array ?

How to compare two arrays to determine if they are equal or not ?

How to fill an array to place a specific value at each index ?

How to convert an array to a string, each element of the array to a string, separates them with
commas, then surrounds them with brackets ?

Reference:

Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

(oracle.com) Control Flow

What are the different control flow statements in Java?

How do if-else statements work in Java?

Can you explain the use of switch statements with an example?

How do loops (for, while, do-while) function in Java?

Reference:
Control Flow Statements (The Java™ Tutorials > Learning the Java Language >
Language Basics) (oracle.com)

OOP Concepts
Class and Object
How do you define a class, its member variables, methods, constructors in Java ?

How to pass information to a method or a constructor ?

Can you explain how to create and use objects of a class in Java ?

How to control Access to Members of a Class

Reference:
What Is an Object? (The Java™ Tutorials > Learning the Java Language > Object-
Oriented Programming Concepts) (oracle.com)

What Is a Class? (The Java™ Tutorials > Learning the Java Language > Object-
Oriented Programming Concepts) (oracle.com)

OOP Principle
What are the four principles of OOP ?

Reference:

Overview of Java (oracle.com)

Encapsulation
Can you distinguish encapsulation, data hiding, immutabily ?

Can you describe all access modifiers in Java ?

Reference:

Controlling Access to Members of a Class (The Java™ Tutorials > Learning the Java
Language > Classes and Objects) (oracle.com)

Inheritance
Can you explain The Java Platform Class Hierarchy ?

What You Can Do in a Subclass ?

How private members work in a superclass ?

How to cast objects in inheritance relationship ?

What is Multiple Inheritance of State, Implementation, and Type ?

Why the Java programming language does not permit you to extend more than one class ?

Does Java support multiple inheritance of implementation with Interface ?

What is Overriding and Hiding Methods in Inheritance with Instance methods, Static methods, Interface
Methods, Modifiers ?

Can we redclare field in subclass with same name of superclass ?

Reference:

Inheritance (The Java™ Tutorials > Learning the Java Language > Interfaces and
Inheritance) (oracle.com)

Multiple Inheritance of State, Implementation, and Type (The Java™ Tutorials >
Learning the Java Language > Interfaces and Inheritance) (oracle.com)

Overriding and Hiding Methods (The Java™ Tutorials > Learning the Java
Language > Interfaces and Inheritance) (oracle.com)
Polymorphism
What is abstraction in Java and how is it achieved ?

Can you provide a code example demonstrating polymorphism in Java ?

Can you compare overloading and overriding ?

What does final class and method mean ?

Reference:

Polymorphism (The Java™ Tutorials > Learning the Java Language >
Interfaces and Inheritance) (oracle.com)

Writing Final Classes and Methods (The Java™ Tutorials > Learning the Java
Language > Interfaces and Inheritance) (oracle.com)

Abstraction
What is interface in Java ?

How to declare interface and its member ?

What happen if one interface extends with another interface ?

What is abstract class in Java ?

What is abstract method in Java ?

Compare abstract class to interface ?

What if an Abstract Class Implements an Interface ?

Reference:

Interfaces (The Java™ Tutorials > Learning the Java Language > Interfaces and
Inheritance) (oracle.com)

Abstract Methods and Classes (The Java™ Tutorials > Learning the Java Language >
Interfaces and Inheritance) (oracle.com)

String
String
What is a String in Java and how is it different from other data types?

What is the String pool in Java?

Why are String objects immutable in Java?

What is the difference between String s = "abc"; and String s = new String("abc"); ?

What is the intern() method in the String class ?

Reference:

String (Java Platform SE 8 ) (oracle.com)

Why String Is Immutable in Java? | Baeldung

StringBuilder, and StringBuffer


What is the difference between String, StringBuilder, and StringBuffer in Java?

When would you use String Builder or StringBuffer ?

Reference:
- The StringBuilder Class (The Java™ Tutorials > Learning the Java Language >
Numbers and Strings) (oracle.com)
- StringBuilder (Java Platform SE 8 ) (oracle.com)

Collections
Collection overview
What is a Collections Framework ?

Can you draw Collection Framework Hierachy ?

Benefits of the Java Collections Framework ?

What is collection interface ?

Reference:

Lesson: Introduction to Collections (The Java™ Tutorials > Collections)

(oracle.com) Outline of the Collections Framework (oracle.com)

Lesson: Interfaces (The Java™ Tutorials > Collections) (oracle.com)

List
What is the List Interface ?

What is the ArrayList class ?

What is the LinkedList class ?

When should we use ArrayList or LinkedList ?

Compare ArrayList and Vector class ?

What is Stack class ?

Reference:

The List Interface (The Java™ Tutorials > Collections > Interfaces) (oracle.com)
ArrayList (Java Platform SE 8 ) (oracle.com)

LinkedList (Java Platform SE 8 ) (oracle.com)


Vector (Java Platform SE 8 ) (oracle.com)

The Queue Interface (The Java™ Tutorials > Collections > Interfaces)

(oracle.com) Stack (Java Platform SE 8 ) (oracle.com)

Queue
What is the Queue Interface ?

Method of queue ?

What is the Dequeue Interface ?

Reference:

The Queue Interface (The Java™ Tutorials > Collections > Interfaces)

(oracle.com) The Deque Interface (The Java™ Tutorials > Collections >

Interfaces) (oracle.com)

Set
What is the Set interface ?

How does the Set interface check duplicated element ?

Describe HashSet and LinkedHashSet ? Use case ?

Describe TreeSet ? Use case ?

Reference:

The Set Interface (The Java™ Tutorials > Collections > Interfaces)

(oracle.com) HashSet (Java Platform SE 8 ) (oracle.com)

LinkedHashSet (Java Platform SE 8 ) (oracle.com)

TreeSet (Java Platform SE 8 ) (oracle.com)

Map
What is the Map interface ?

Why does Map not extend Collection interface ?

How to create Multimaps ?

Describe HashMap and LinkedHashMap ? Use case ?

How HashMap work internally ?

Describe TreeMap ? Use case ?

Reference :

The Map Interface (The Java™ Tutorials > Collections > Interfaces)

(oracle.com) HashMap (Java Platform SE 8 ) (oracle.com)

LinkedHashMap (Java Platform SE 8 ) (oracle.com)

TreeMap (Java Platform SE 8 ) (oracle.com)

Compare List, Set, Map


What are the main differences between List, Set, and Map in Java?

Object ordering
What is the purpose of the Comparable interface in Java ?

How does the Comparator interface differ from Comparable ?

How to combine multiple comparators ?

How to sort a collection in Java?

Reference:

Object Ordering (The Java™ Tutorials > Collections > Interfaces)


(oracle.com) Collections class

What is the Collections class ?

Describe some most used methods of Collections class ?

Compare Collection Inteface and Collections Class ?

Reference:

Collections (Java Platform SE 8 ) (oracle.com)

Exception
Exception in Java
What is an exception in Java ?

What are the advantages of exception ?

How to define an exception ?

Reference:

What Is an Exception? (The Java™ Tutorials > Essential Java Classes > Exceptions) (oracle.com)

Advantages of Exceptions (The Java™ Tutorials > Essential Java Classes >
Exceptions) (oracle.com)

Checked and Unchecked


What are checked exceptions and when are they used ?

What are unchecked exceptions and when are they used ?

What are error and it's difference with exception ?

Reference:

The Catch or Specify Requirement (The Java™ Tutorials > Essential Java Classes >
Exceptions) (oracle.com)

Exception Handling: try-catch, Throw and Throws


How do you use try-catch blocks to handle exceptions in Java?

What is the purpose of the throw keyword in Java?

How does the throws keyword differ from throw?

Reference:

Catching and Handling Exceptions (The Java™ Tutorials > Essential Java Classes >
Exceptions) (oracle.com)
Specifying the Exceptions Thrown by a Method (The Java™ Tutorials > Essential Java
Classes > Exceptions) (oracle.com)

How to Throw Exceptions (The Java™ Tutorials > Essential Java Classes >
Exceptions) (oracle.com)

JDBC
What is JDBC and why is it used in Java?

How do you establish a connection to a database using JDBC?

What are the steps involved in executing a query using JDBC?


Connection, Statement, PreparedStatement
What is the difference between a Statement and a PreparedStatement in JDBC?

How do you create and use a PreparedStatement in Java?

ResultSet, ExecuteUpdate, and ExecuteQuery


How do you use ResultSet to retrieve data from a database in Java?

What is the difference between executeUpdate and executeQuery methods in JDBC?

You might also like