SlideShare a Scribd company logo
1 of 26
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 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

Similar to Java_Interview Qns

Top 20 Core Java Interview Questions & Answers for Selenium Automation Testin...
Top 20 Core Java Interview Questions & Answers for Selenium Automation Testin...Top 20 Core Java Interview Questions & Answers for Selenium Automation Testin...
Top 20 Core Java Interview Questions & Answers for Selenium Automation Testin...
AnanthReddy38
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
nofakeNews
 
Object Oriented Programming All Unit Notes
Object Oriented Programming All Unit NotesObject Oriented Programming All Unit Notes
Object Oriented Programming All Unit Notes
BalamuruganV28
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
AnkurSingh340457
 
Object-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdfObject-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdf
Bharath Choudhary
 
Introduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologiesIntroduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologies
TabassumMaktum
 

Similar to Java_Interview Qns (20)

20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
 
Top 20 Core Java Interview Questions & Answers for Selenium Automation Testin...
Top 20 Core Java Interview Questions & Answers for Selenium Automation Testin...Top 20 Core Java Interview Questions & Answers for Selenium Automation Testin...
Top 20 Core Java Interview Questions & Answers for Selenium Automation Testin...
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
 
Suga java training_with_footer
Suga java training_with_footerSuga java training_with_footer
Suga java training_with_footer
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
 
Object Oriented Programming All Unit Notes
Object Oriented Programming All Unit NotesObject Oriented Programming All Unit Notes
Object Oriented Programming All Unit Notes
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 
javaopps concepts
javaopps conceptsjavaopps concepts
javaopps concepts
 
Java OOPs Concepts.docx
Java OOPs Concepts.docxJava OOPs Concepts.docx
Java OOPs Concepts.docx
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
 
Object-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdfObject-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdf
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Introduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologiesIntroduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologies
 
Qb it1301
Qb   it1301Qb   it1301
Qb it1301
 
Basics java programing
Basics java programingBasics java programing
Basics java programing
 
Java notes
Java notesJava notes
Java notes
 
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
 
Java basic concept
Java basic conceptJava basic concept
Java basic concept
 

Recently uploaded

Recently uploaded (20)

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 

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.
  • 21.
  • 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.