SlideShare a Scribd company logo
Java Interview Q & A
By Krishnan
What is Java?
Java is a general-purpose, class-based, object-oriented programming language designed
for having lesser implementation dependencies.
Features of Java:
JDK VS JRE VS JVM
Access Modifier
In Java, there 4 types of the access specifiers.
 public: accessible in all class in your application.
 protected: accessible within the package in which it is defined and in
its subclass(es)(including subclasses declared outside the package)
 private: accessible only within the class in which it is defined.
 default (declared/defined without using any modifier): accessible within same
class and package within which its class is defined.
Data Types
Java has two categories of data:
 Primitive Data Type: such as boolean, char, int, short, byte, long, float, and double
 Non-Primitive Data Type or Object Data type: such as String, Array, etc.
OOPS CONCEPTS
Class :
Collection of objects is called class. It is a logical entity.
Object : Any entity that has state and behavior is known as an object. For example, a
chair, pen, table, keyboard, bike, etc. It can be physical or logical.
Inheritance :
When one object acquires all the properties and behaviors of a parent object, it is
known as inheritance. It provides code reusability. It is used to achieve runtime
polymorphism.
Polymorphism:
If one task is performed in different ways, it is known as polymorphism. For
example: to convince the customer differently, to draw something, for example,
shape, triangle, rectangle, etc.
In Java, we use method overloading and method overriding to achieve polymorphism.
Abstraction :
Hiding internal details and showing functionality is known as abstraction. For
example phone call, we don't know the internal processing.
Encapsulation :
Binding (or wrapping) code and data together into a single unit are known as
encapsulation. For example, a capsule, it is wrapped with different medicines.
What is String in Java?
Generally, String is a sequence of characters. But in Java, string is an object that
represents a sequence of characters. The java.lang.String class is used to create a
string object.
How to create a string object?
There are two ways to create String object:
1.By string literal
2.By new keyword
Why String objects are immutable?
Java uses the concept of String literal. Suppose there are 5 reference variables, all
refer to one object "abc". If one reference variable changes the value of the object, it
will be affected by all the reference variables. That is why String objects are
immutable in Java
Exception Handling
Types of Java Exceptions
1)Checked Exception
2)UnChecked Exception
3)Errror
1) Checked Exception
The classes that directly inherit the Throwable class except
RuntimeException and Error are known as checked exceptions. For
example, IOException, SQLException, etc. Checked exceptions are
checked at compile-time.
2) Unchecked Exception
The classes that inherit the RuntimeException are known as unchecked
exceptions. For example, ArithmeticException, NullPointerException,
ArrayIndexOutOfBoundsException, etc. Unchecked exceptions are not
checked at compile-time, but they are checked at runtime.
3) Error
Error is irrecoverable. Some example of errors are
Throw Vs Throws
The throw and throws are the concepts of exception handling in Java where the throw
keyword throws the exception explicitly from a method or a block of code, whereas the
throws keyword is used in the signature of the method.
Final VS Finally Vs Finalize
Collections
A Java Collection is a predefined architecture capable of storing a group of elements
and behaving like a single unit such as an object or a group.
It’s for all the data manipulation jobs such as storing data, searching, sorting,
insertion, deletion, and updating of data
Comparable Vs Comparator
Java provides two interfaces to sort objects using data members of the class:
1.Comparable
2.Comparator
Multithreading
Multithreading is a Java feature that allows concurrent execution of two or more parts
of a program for maximum utilization of CPU. Each part of such program is called a
thread. So, threads are light-weight processes within a process.
Threads can be created by using two mechanisms :
1.Extending the Thread class
2.Implementing the Runnable Interface
Life Cycle and States of Thread
A thread in Java at any point of time
exists in any one of the following states.
A thread lies only in one of the shown
states at any instant:
1.New
2.Runnable
3.Blocked
4.Waiting
5.Timed Waiting
6.Terminated
Synchronization
Synchronization in java is the capability to control the access of multiple threads to
any shared resource. In the Multithreading concept, multiple threads try to access the
shared resources at a time to produce inconsistent results. The synchronization is
necessary for reliable communication between threads.
Why use Synchronization
Synchronization helps in preventing thread interference.
Synchronization helps to prevent concurrency problems.
Design Patterns in Java
A design patterns are well-proved solution for solving the specific problem/task.
Problem Given :
Suppose you want to create a class for which only a single instance (or object) should
be created and that single object can be used by all other classes.
Solution:
Singleton design pattern is the best solution of above specific problem. So, every
design pattern has some specification or set of rules for solving the problems.
Java_Interview Qns
Java 8 Features :
Default Methods
Before Java 8, interfaces could have only abstract methods. The implementation of
these methods has to be provided in a separate class. So, if a new method is to be
added in an interface, then its implementation code has to be provided in the class
implementing the same interface. To overcome this issue, Java 8 has introduced the
concept of default methods which allow the interfaces to have methods with
implementation without affecting the classes that implement the interface.
Functional Interface :
A functional interface is an interface that contains only one abstract method. They can
have only one functionality to exhibit. From Java 8 onwards, lambda expressions can
be used to represent the instance of a functional interface. A functional interface can
have any number of default methods. Runnable, ActionListener, Comparable are
some of the examples of functional interfaces.
Lambda Expression :
The Lambda expression is used to provide the implementation of an interface which
has functional interface. It saves a lot of code. In case of lambda expression, we don't
need to define the method again for providing the implementation.
Streams :
The Stream API is used to process collections of objects. A stream is a sequence of
objects that supports various methods which can be pipelined to produce the desired
result.
Features of Stream :
 Stream does not store elements. It simply conveys elements from a source such as
a data structure, an array, or an I/O channel, through a pipeline of computational
operations.
 Stream is functional in nature. Operations performed on a stream does not modify
it's source. For example, filtering a Stream obtained from a collection produces a
new Stream without the filtered elements, rather than removing elements from the
source collection.
 Stream is lazy and evaluates code only when required.
 The elements of a stream are only visited once during the life of a stream. Like an
Iterator, a new stream must be generated to revisit the same elements of the
source.
Java_Interview Qns

More Related Content

PPTX
A brief tour of modern Java
DOCX
Jist of Java
DOCX
JAVA CONCEPTS AND PRACTICES
PDF
Core_Java_Interview.pdf
PDF
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
DOCX
Viva file
PDF
20 most important java programming interview questions
PPT
Intro Java Rev010
A brief tour of modern Java
Jist of Java
JAVA CONCEPTS AND PRACTICES
Core_Java_Interview.pdf
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
Viva file
20 most important java programming interview questions
Intro Java Rev010

Similar to Java_Interview Qns (20)

DOCX
Core java questions
PPT
Core java by a introduction sandesh sharma
PDF
Java Faqs useful for freshers and experienced
PDF
Top 100 Java Interview Questions with Detailed Answers
PPTX
Intro to java 8
PPTX
Beginning Java for .NET developers
PDF
core java
PDF
Top 371 java fa qs useful for freshers and experienced
PDF
__ Java Technical round questions .pdf soo
PPTX
Suga java training_with_footer
PPTX
Java-Development-A-Comprehensive-Guide.pptx
PPTX
JAVA AND OOPS CONCEPTS.pptx helpful for engineering
PPTX
Java8: what's new and what's hot
PPTX
Object Oriented Programming unit 1 content for students
PPTX
Java For Automation
PPTX
ppt_on_java.pptx
PDF
Introduction to JAVA
DOC
Java interview questions
PDF
Java programming material for beginners by Nithin, VVCE, Mysuru
Core java questions
Core java by a introduction sandesh sharma
Java Faqs useful for freshers and experienced
Top 100 Java Interview Questions with Detailed Answers
Intro to java 8
Beginning Java for .NET developers
core java
Top 371 java fa qs useful for freshers and experienced
__ Java Technical round questions .pdf soo
Suga java training_with_footer
Java-Development-A-Comprehensive-Guide.pptx
JAVA AND OOPS CONCEPTS.pptx helpful for engineering
Java8: what's new and what's hot
Object Oriented Programming unit 1 content for students
Java For Automation
ppt_on_java.pptx
Introduction to JAVA
Java interview questions
Java programming material for beginners by Nithin, VVCE, Mysuru
Ad

Recently uploaded (20)

PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Nekopoi APK 2025 free lastest update
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Digital Strategies for Manufacturing Companies
How to Choose the Right IT Partner for Your Business in Malaysia
PTS Company Brochure 2025 (1).pdf.......
Design an Analysis of Algorithms II-SECS-1021-03
How Creative Agencies Leverage Project Management Software.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
ManageIQ - Sprint 268 Review - Slide Deck
How to Migrate SBCGlobal Email to Yahoo Easily
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Odoo POS Development Services by CandidRoot Solutions
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Nekopoi APK 2025 free lastest update
ISO 45001 Occupational Health and Safety Management System
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
2025 Textile ERP Trends: SAP, Odoo & Oracle
Softaken Excel to vCard Converter Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Digital Strategies for Manufacturing Companies
Ad

Java_Interview Qns

  • 1. Java Interview Q & A By Krishnan
  • 2. What is Java? Java is a general-purpose, class-based, object-oriented programming language designed for having lesser implementation dependencies.
  • 4. JDK VS JRE VS JVM
  • 5. Access Modifier In Java, there 4 types of the access specifiers.  public: accessible in all class in your application.  protected: accessible within the package in which it is defined and in its subclass(es)(including subclasses declared outside the package)  private: accessible only within the class in which it is defined.  default (declared/defined without using any modifier): accessible within same class and package within which its class is defined. Data Types Java has two categories of data:  Primitive Data Type: such as boolean, char, int, short, byte, long, float, and double  Non-Primitive Data Type or Object Data type: such as String, Array, etc.
  • 7. Class : Collection of objects is called class. It is a logical entity. Object : Any entity that has state and behavior is known as an object. For example, a chair, pen, table, keyboard, bike, etc. It can be physical or logical. Inheritance : When one object acquires all the properties and behaviors of a parent object, it is known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.
  • 8. Polymorphism: If one task is performed in different ways, it is known as polymorphism. For example: to convince the customer differently, to draw something, for example, shape, triangle, rectangle, etc. In Java, we use method overloading and method overriding to achieve polymorphism. Abstraction : Hiding internal details and showing functionality is known as abstraction. For example phone call, we don't know the internal processing.
  • 9. Encapsulation : Binding (or wrapping) code and data together into a single unit are known as encapsulation. For example, a capsule, it is wrapped with different medicines. What is String in Java? Generally, String is a sequence of characters. But in Java, string is an object that represents a sequence of characters. The java.lang.String class is used to create a string object.
  • 10. How to create a string object? There are two ways to create String object: 1.By string literal 2.By new keyword Why String objects are immutable? Java uses the concept of String literal. Suppose there are 5 reference variables, all refer to one object "abc". If one reference variable changes the value of the object, it will be affected by all the reference variables. That is why String objects are immutable in Java
  • 11. Exception Handling Types of Java Exceptions 1)Checked Exception 2)UnChecked Exception 3)Errror
  • 12. 1) Checked Exception The classes that directly inherit the Throwable class except RuntimeException and Error are known as checked exceptions. For example, IOException, SQLException, etc. Checked exceptions are checked at compile-time. 2) Unchecked Exception The classes that inherit the RuntimeException are known as unchecked exceptions. For example, ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException, etc. Unchecked exceptions are not checked at compile-time, but they are checked at runtime. 3) Error Error is irrecoverable. Some example of errors are
  • 13. Throw Vs Throws The throw and throws are the concepts of exception handling in Java where the throw keyword throws the exception explicitly from a method or a block of code, whereas the throws keyword is used in the signature of the method.
  • 14. Final VS Finally Vs Finalize
  • 15. Collections A Java Collection is a predefined architecture capable of storing a group of elements and behaving like a single unit such as an object or a group. It’s for all the data manipulation jobs such as storing data, searching, sorting, insertion, deletion, and updating of data
  • 16. Comparable Vs Comparator Java provides two interfaces to sort objects using data members of the class: 1.Comparable 2.Comparator
  • 17. Multithreading Multithreading is a Java feature that allows concurrent execution of two or more parts of a program for maximum utilization of CPU. Each part of such program is called a thread. So, threads are light-weight processes within a process. Threads can be created by using two mechanisms : 1.Extending the Thread class 2.Implementing the Runnable Interface
  • 18. Life Cycle and States of Thread A thread in Java at any point of time exists in any one of the following states. A thread lies only in one of the shown states at any instant: 1.New 2.Runnable 3.Blocked 4.Waiting 5.Timed Waiting 6.Terminated
  • 19. Synchronization Synchronization in java is the capability to control the access of multiple threads to any shared resource. In the Multithreading concept, multiple threads try to access the shared resources at a time to produce inconsistent results. The synchronization is necessary for reliable communication between threads. Why use Synchronization Synchronization helps in preventing thread interference. Synchronization helps to prevent concurrency problems.
  • 20. Design Patterns in Java A design patterns are well-proved solution for solving the specific problem/task. Problem Given : Suppose you want to create a class for which only a single instance (or object) should be created and that single object can be used by all other classes. Solution: Singleton design pattern is the best solution of above specific problem. So, every design pattern has some specification or set of rules for solving the problems.
  • 23. Default Methods Before Java 8, interfaces could have only abstract methods. The implementation of these methods has to be provided in a separate class. So, if a new method is to be added in an interface, then its implementation code has to be provided in the class implementing the same interface. To overcome this issue, Java 8 has introduced the concept of default methods which allow the interfaces to have methods with implementation without affecting the classes that implement the interface. Functional Interface : A functional interface is an interface that contains only one abstract method. They can have only one functionality to exhibit. From Java 8 onwards, lambda expressions can be used to represent the instance of a functional interface. A functional interface can have any number of default methods. Runnable, ActionListener, Comparable are some of the examples of functional interfaces.
  • 24. Lambda Expression : The Lambda expression is used to provide the implementation of an interface which has functional interface. It saves a lot of code. In case of lambda expression, we don't need to define the method again for providing the implementation. Streams : The Stream API is used to process collections of objects. A stream is a sequence of objects that supports various methods which can be pipelined to produce the desired result.
  • 25. Features of Stream :  Stream does not store elements. It simply conveys elements from a source such as a data structure, an array, or an I/O channel, through a pipeline of computational operations.  Stream is functional in nature. Operations performed on a stream does not modify it's source. For example, filtering a Stream obtained from a collection produces a new Stream without the filtered elements, rather than removing elements from the source collection.  Stream is lazy and evaluates code only when required.  The elements of a stream are only visited once during the life of a stream. Like an Iterator, a new stream must be generated to revisit the same elements of the source.