0% found this document useful (0 votes)
33 views18 pages

Java March 2023

Java is a high-level object-oriented programming language created in 1991 by James Gosling at Sun Microsystems. It was initially called Oak but was renamed to Java in 1995. Key features of Java include being platform independent, secure, supporting object-oriented programming, being simple, allowing for multithreading, and being robust, dynamic, and distributed.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
33 views18 pages

Java March 2023

Java is a high-level object-oriented programming language created in 1991 by James Gosling at Sun Microsystems. It was initially called Oak but was renamed to Java in 1995. Key features of Java include being platform independent, secure, supporting object-oriented programming, being simple, allowing for multithreading, and being robust, dynamic, and distributed.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 18

Java-> Java is a High Level Object Oriented Programming Language

in 1991 by James Gosling in Sun Microsystem

initial name "Oak" renamed in 1995 as "Java"

Features->
1. Platform Idependent[WORA]
2. Secure
3. Oops
4. Simple
5. Multithreading
6. Robust
7. Dynamic
8. Distributed

Core Java->
Java- It is a High Level Object Oriented Programming Language

Finance, Retail, Telecom, Healthcare, etc

History->

in 1991 by James Gosling in Sun Microsystem

initial name is "Oak" renamed in 1995 as "Java"

Features->
1. Platform Indepedent[WORA]
2. Oops
3. Simple
4. Secure
5. Multithreading
6. Robust
7. Dynamic
8. Distributed

---------------------------------------
Class- It is predefined template. It is a collection of objects,
variables and methods
Ex. class Customer{

Object- Instance of a class


Ex- Customer customer = new Customer();

Variables- Storage
3 types->
1. Instance Variable- Declared with class level
2. Static Variable- Declared with class level but must be static
3. Local Variable- Declared inside method/block

Ex. int empId=121;


double empSalary=65000.96;

Datatypes in Java->
1. byte
2. short
3. int
4. long
5. float
6. double
7. char
8. boolean

Method- perform some task


void showData(){

Core Java->

Java-> It is a High Level Object Oriented Programming Language

in 1991 by James Gosling in Sun Microsystem

"Oak" renamed in 1995 as "Java"

Features->
1. Platform Independent[WORA]
2. Simple
3. Oops
4. Secure
5. Multithreading
6. Robust
7. Dynamic
8. Distributed

---------------------------------
Class- Its predefined template |
It is collection of objects, variables and methods
Ex- class Employee{

Object- Instance of a class


Ex- Employee e1 = new Employee();

Method- perform some task


Ex- void showData(){
}

Variables- Storage
3 types-
1. Instance Variable- Declared with class level
2. Static Variable- Declared with class level but must be static
3. Local Variable- Inside method/block

Datatypes->
1. byte
2. short
3. int
4. long
5. float
6. double
7. char
8. boolean

-----------------------------------
Debug Java Application
f6- next line
f5- inside method
f8- next breakpoint

Static Concept-
1. Variable- Declared with class level but must be static

2. Method- Not need to create object to call static method inside main
- Static allows to overload, but cant allows override

3. Block- It will execute before main method


- It will help us for pre-initilization

4. Class- Outer class never static, Inner class will be declared as static

JVM- Java Virtual Machine


The compiler compiles the Java file into a .class file,
then that .class file is input into the JVM, which loads
and executes the class file.

JVM Memory
Method area: All class level information like class name,
immediate parent class name, methods and variables information etc. are stored,
including static variables. There is only one method area per JVM, and it is a
shared resource.

Heap area : Objects is stored in heap area. There is also one Heap Area per JVM.
It is also a shared resource.

Stack area :For every thread, JVM create one run-time stack which is stored here.
Every block of this stack is called activation record/stack frame which store
methods.
All local variables of that method are store d in their corresponding frame. After
a thread
terminate, it’s run-time stack will be destroyed by JVM. It is not a shared
resource.

PC Registers :Store address of current execution instruction of a thread. Obviously


each
thread has separate PC Registers.

Native method stacks :For every thread, separate native stack is created.
It stores native method information.

.java -> Java Compiler[javac] -> .class -> Java Interpreter-> Output

Just-In-Time Compiler(JIT) : It is used to increase efficiency of interpreter.


It compiles the entire bytecode and changes it to native code so whenever
interpreter see repeated method calls,JIT provide direct native code for that part
so
re-interpretation is not required,thus efficiency is improved.
JDK- Java Development Kit
JRE- Java Runtime Environment
JAR- Java Archieve
WAR- Web Archeve

TypeCasting-> Convert one type into another type

2 types-
1. UpCasting- lower to higher
Ex. int to double

2. DownCasting- Higher to lower


Ex. double to int

AutoBoxing- convert primitive type into wrapper class


Ex- int to Integer

UnBoxing- Convert wrapper class into primitive type


Ex- Integer to int

JVM- Java Virtual Machine

Welcome.java-> javac-> Welcome.class-> java-> Output.

Access Modifiers- Scope of visibility


4 types-

1. private- Scope with in class.

2. default- Scope with in package.

3. protected- Scope with in package outside package but within subclass.

4. public- Access everywhere.

Core Java

Static Concept->

1. Variable- Declared with class level & must be static

2. Method- Not need to create object to call inside main


- Static allows to overload the method
- Static cant allows to override the method

3. Block- It will execute before main method


- It is used for pre-initialization

4. Class- Outer class never static, inner class will


be declared as static

-------------------------------------------------------

Final Concept->

1. Variable- Cant reinitialize


2. Method- Cant Override

3. Class- Cant extends

IQ- How to create custom immutable class in Java?


=> 1. Declared class with final
2. All variables are must be private
3. Dont use setter, And use constructor

Core Java
Control Statement->

1. if
if(cond)
{

}
2. if...else
3. Nested if..else
4. switch case

Control Statement->
1. if

if(cond)

2. if...else

if(cond){

}else{

3. Nested if...else

if(cond){

}else if(cond){

}else if(cond){

}else{

4. Switch case
switch(ch){

case 1: stmnt;
break;

case 2: stmnt;
break;

.
.
.
default: stmntl
break
}

Control Flow[Loop in Java]

1. for
for(init; cond; ++/--)

2. while

while(cond){
stmnt;
}

3. do..while()

do{
stmnt;
}while(cond);

--------------------------------------------------------------------------

Oops-> Object Oriented Programming

4 Pillars->

1. Abstraction- Hiding internal details and showing functionality

2. Encapsulation- The wrapping up of a data into a single unit

3. Polymorphism- The ability to take more than one form


A] Compile Time[Method Overload]
B] Run Time[Method Override]

4. Inheritance- One class can acquire the properties of another class


1. Single
2. Multilevel
3. Hierarchical
4. Multiple
5. Hybrid

Oops- Object Oriented Programming

4 Pillars-

1. Abstraction- Hiding internal details and showing functionality

2. Encapsulation- The warapping up of a data into a single unit

3. Polymorphism- The ability to take more than one form


A] Compile Time[Method Overload]
1. Same method name and different parameters
2. Method overload possible with in single class
3. Static allows to overload the method
4. Final allows to overload the method

B] Run Time[Method Override]


1. Same method name and same parameters
2. Method override never possible with in single class, must need to use
inheritance concept
3. Static cant allows to override
4. Final cant allows to override

4. Inheritance- One class can acquire the properties of another class


1. Single
2. Multilevel
3. Hierarchical
4. Multiple
5. Hybrid

Interface Abstract class


1. All methods are abstract till jdk 7 It supports abstract and non-abstract
methods
but from jdk 8 interface supports
2 non-abstract methods- static &
default

2. All methods are public Methods are may/not be public/final/static

3. All variables are public/final/static Variables are may/not be


public/final/static

4. No Constructor Allows Constructor

5. Cant instantiate Cant instantiate

6. I-I-> extends I-C-> implements | C-C-> extends

7. Keywords- interface abstract

8. With in class will implements n no. With in class will extends only one class
of interfaces by "," seperated at a time

Oops-> Object Oriented Programming

4 Pillars-

1. Abstraction- Hiding internal details and showing functionality

2. Encapsulation- The wrapping up of a data into a single unit

3. Polymorphism- The ability to take more than one form


A] Compile Time[Method Overload]
1. Same method name and different parameters
2. It possible with in single class
3. Static allows to overload method
4. Final allows to overload method
B] Run Time[Method Override]
1. Same method name and same parameters
2. Its not possible with in single class, must need to use Inheritance
3. Static cant allows to override method
4. Final cant allows to override method

4. Inheritance- One class can acquire the properties of another class


1. Single
2. Multilevel
3. Hierarchical
4. Multiple
5. Hybrid

-----------------------------------------------------------------------------------
--

Oops-> Object Oriented Programming

4 Pillars-

1. Abstraction- Hiding internal details and showing functionality

2. Encapsulation- The wrapping up of a data into a single unit

3. Polymorphism- The ability to take more than one form


A] Compile Time[Method Overload]
1. Same method name and different parameters
2. It possible with in single class
3. Static allows to overload method
4. Final allows to overload method

B] Run Time[Method Override]


1. Same method name and same parameters
2. Its not possible with in single class, must need to use Inheritance
3. Static cant allows to override method
4. Final cant allows to override method

4. Inheritance- One class can acquire the properties of another class


1. Single
2. Multilevel
3. Hierarchical
4. Multiple
5. Hybrid

-----------------------------------------------------------------------------------

Constructor-
1. Constructor itself initialize at the time of object creation
2. Constructor name same name as a class name
3. Constructor does not have any return type
4. Constructor overload possible in Java
5. Constructor override never possible in Java

2 types of Constructor->
1. Default Constructor- No Parameters
2. Parameterized Constructor- Passing some parameters
Constructor-
1. Constructor itself initialize at the time of object creation
2. Constructor name same name as a class name
3. Constructor does not have any return type
4. Constructor overload possible in Java
5. Constructor override never possible in Java

2 types of Constructor->
1. Default Constructor- No Parameters
2. Parameterized Constructor- Passing some parameters

Oops-> Object Oriented Programming

4 Pillars-

1. Abstraction- Hiding internal details and showing functionality

2. Encapsulation- The wrapping up of a data into a single unit

3. Polymorphism- The ability to take more than one form


A] Compile Time[Method Overload]
1. Same method name and different parameters
2. It possible with in single class
3. Static allows to overload method
4. Final allows to overload method

B] Run Time[Method Override]


1. Same method name and same parameters
2. Its not possible with in single class, must need to use Inheritance
3. Static cant allows to override method
4. Final cant allows to override method

4. Inheritance- One class can acquire the properties of another class


1. Single
2. Multilevel
3. Hierarchical
4. Multiple
5. Hybrid

---------------------------------------------------------------------------------

Constructor-
1. Constructor itself initialize at the time of object creation
2. Constructor name same name as a class name
3. Constructor does not have any return type
4. Constructor overload possible in Java
5. Constructor override never possible in Java

2 types of Constructor->
1. Default Constructor- No Parameters
2. Parameterized Constructor- Passing some parameters

---------------------------------------------------------------------------------
Exception Handling->
Exception- It is an abnormal condition which is interrupt
normal flow of program

2 types->
1. Checked[Compile Time]Ex- IOException, SQLException

2. UnChecked[Run Time]Ex- NullPointerException, ArithmeticException

5 block->

1. try- Will add exceptional code in try block

2. catch- It is used to catch the exception

3. throw-
1. It is a User defined Exception
2. Will declare throw inside method
3. In throw will handle only one Exception at a time
4. It called explicitly

4. throws
1. It is a System generated Exception
2. Will declare thorws at the time of method declaration
3. In throws will handle multiple Exception at a time by "," seperated
4. It called implicitly

5. finally- Always execute


System.exit(0);- In this scenario finally block does not execute

Exception Handling->

Exception- It is an abnormal condition which is interrupt normal flow of program

2 types of Exception
1] Checked[Compile Time]Ex- IOException, SQLException

2] Unchecked[Run Time]Ex- NullPointerException, ArithmeticException

5 blocks-

try- Will add Exceptional code in try block

catch- It is used to catch the Exception

throw-
1. It is a User Defined Exception
2. Will declare throw inside method
3. In throw will handle only one Exception at a time
4. It called explicitly

throws-
1. It is a System generated Exception
2. Will declare throws at the time of method declaration
3. In throws will handle multiple Exception at a time by "," seperated
4. It called implicitly
finally- It always execute
System.exit(0) then finally block does not execute
Realtime usage- close Database connection, close Hibernate Session

What is try-with-resources
-> From Java 7 we are able to use try without catch & finally
Realtime usage- 1. Avoid resource leakage
2. It will take care of Close object automatically

-----------------------------------------------------------------------------------
------
String- It is a collection of character
Ex- Fintech
- Immutable

StringBuffer
- Mutable
- Thread Synchronized
- Thread Safety

StringBuilder
- Mutable
- Not Thread Synchronized
- Not Thread Safety
comes in JDK 1.5

IQ-
1. Diff .equals() & ==
2. Diff. String, StringBuffer & StringBuilder
3. What is SCP
4. Write a Java Program for Reverse String
5. Write a Java Program to find repeated character with number of occurences

-----------------------------------------------------------------------------------
-------
Collection Framework->

Collection- It is a group of objects

1. List- allows duplication of data


- Follows Insertion order
A] ArrayList- DDL[Read]
B] LinkedList- DML[Insert/Update/Delete]

2. Set- uniqueness
A] HashSet- Does not maintain order
It allows one null element
B] TreeSet- Follows order
Does not allows null element

3. Map- K, V pair | In Map key must be unique and value allows duplicate
A] HashMap- Does not maintain order
- It allows one null key, and allows multiple null values
B] TreeMap- Follows order
- No null key but it allows multiple null values
IQ-
1. Diff ArrayList & LinkedList
2. When ConcurrentModificationException come?
3. Explain FailFast & FailSafe iterator
4. Explain Internal working of HashMap?
->
HashMap-> Map-> K, V
1 Bucket-> 16 Block
Principle- Hashing
Structure- LinkedList

equals()
hashcode()- integer value
collision

5. Write a Java program for HashMap/TreeMap & iterate elements using for each
6. Diff. Comparable & Comparator
-> .lang .util
compareTo() compare() & equals()
It is used for single It is used for multiple sequence sort
sequence sort

-----------------------------------------------------------------------------------
-----------
Collection- It is a group of object

1. List- Allows duplication of data


A] ArrayList- DDL[Read]
B] LinkedList- DML[Insert|Update|Delete]

2. Set- Uniqueness
A] HashSet
- Does not maintain order
- Allows one null element

B] TreeSet
- Follows order
- Not allows null element

3. Map- K, V pair | Key must be unique and values allows duplicate


A] HashMap-
- Does not maintain order
- Allows one null key and multiple null values

B] TreeMap
- Follows order
- No null key but it allows multiple null values

IQ-
1. Diff ArrayList & LinkedList
2. When ConcurrentModificationException come?
3. Explain Fail Fast & Fail Safe iterator
4. Write a Java Program for HashMap and iterate elements using for each
5. How HashMap internally works?
Bucket- 0 to 15=> 16 Block
Principle- Hashing Principle
Structure- LinkedList

equals(), hashcode, collision

6. Diff Comparable & Comparator


.lang .util
compareTo() compare(), equals()
It is used for single sequence sort It is used for multiple sequence sort

-----------------------------------------------------------------------------------
--------
File Handling in Java->

1. Create File- createNewFile()

2. Write File- FileWriter | write()


Once write file we must need to close it
ex- fileWriter.close();

3. Read File-
Ex- Use Scanner and give input as file reference

4. Delete File-
Ex- file.delete();

-----------------------------------------------------------------------------------
---------------

Thread-> It is a Lightweight part of process

2 way-
1. extends Thread class
2. implements Runnable interface

Thread LifeCycle

New-> Ready-> Execution-> Terminate


|| ||
|| || [I/O | Interrupt]
|| ||
------- waiting

MultiThreading- 2 or more Thread simultaneously comes into


execution

Thread Synchronization- 2 or more Thread simultaneously


comes into execution but only one Thread execute at a
time.

IQ-
1. What is Thread Synchronization?
2. How many way's to Create Thread in Java?
3. Is it possible to start same Thread twice?
-> No. java.lang.IllegalThreadStateException
4. What is InterThread Communication
5. What are the Priorities in Thread?
6. Diff. wait() & sleep() methods
7. Explain methods in Thread

Thread-> It is a Lightweight part of process

2 Ways-
1. by extends Thread class
2. by implements Runnable interface

Thread Lifecycle-

New-> Ready -> Running-> -> Terminate


|| ||
|| || [I/O | Interrupt]
|| ||
----- waiting

Multithreading- 2 or more Thread simultaneously comes


into execution

Thread Synchronization- 2 or more Thread simultaneously


comes into execution, but only one Thread execute at a time

InterThread Communication
wait(), notify and notifyAll()

Account Balance- 10000/-


Going to withdraw money- 15000/-
"Insufficient Fund"

wait();

Going to deposit money- 25000/-


Money deposited successfully

notify() | notifyAll()

withdraw amount successfully

---------------------------------

Priorities in Thread

3 types-
1. MIN- 1
2. NORM- 5
3. MAX- 10

------------------------------
Methods in Thread

IQ-
1. What is MultiThreading?
2. What is Thread Synchronization?
3. Diff wait() & sleep()
4. Explain Thread Lifecycle
5. Is it possible to start same Thread twice?
6. What is InterThread Communication?
-> wait(), notify(), notifyall()
7. What are the priorities in Thread
8. What are the methods in Thread

-----------------------------------------------------------------------------------
-----

Core Java Revision->

IQ- Diff. final, finally & finalize

final- Keyword
1. Variable- Cant reinitialize
2. Method- Cant override
3. Class- Cant extends

finally- Block
It always execute
try- System.exit(0)- In this scenario finally does not execute
Real time use- DB connection close, Hibernate session close, etc

finalize()- Method
It will help us to achieve garbage collection in Java
referred object as null
System.gc();

How to create Custom Immutable class in Java?


-> 1. Declared class with final
2. All variables are private
3. Dont use Setter, use constructor

What is enum?
- It help us to declared constant in Java
- Enum by default as public/final/static
- Enum alwyas declared as Capital Letters
- Enum is very Lightweight as compared to String
- Enum we are able to iterate by using for each
- Enum we are able to handle with in condition
- Enum it will good Performance

Whar are the Marker Interface in Java?


Marker Interface- Empty Interface | No Methods
3 Marker Interface-
1. Serializable[.io]- Convert object into byte stream
2. Cloneable[.lang]- Clone the object
3. Remote[.rmi]- Socket Programming | Network Programming

transient variable- Avoid Serialization


Core Java Revision->

Oops->
4 Pillars->
1. Abstraction- Hiding internal details and showing functionality

2. Encapsulation- The wrapping up of a data into a single unit

3. Polymorphism- The ability to take more than one form


A] Compile Time[Method Overload]
1. Same method name and diff parameters
2. Method overload possible with in single class
3. Static allows to overload the method
4. Final allows to overload the method

B] Run Time[Method Override]


1. Same method name and same parameters
2. Method override never possible with in single class,
must need to use inheritance
3. Static cant allows to override the method
4. Final cant allows to override the method

4. Inheritance- One class can acquire the properties of another class


1. Single
2. Multilevel
3. Hierarchical
------------------------------------------------------
Interface Abstract class
1. All methods are abstract till JDK 7 It supports abstract & non-abstract
methods
But from JDK 8 interface supports 2
non-abstract methods- static & default

2. All methods are public Methods are may/not be public/final/static

3. All variables are public/final/static Variables are may/not be


public/final/static

4. No Constructor Allows Constructor

5. Cant Instantiate Cant Instantiate

6. Keyword- interface abstract

7. I-I-> extends I-C-> implements | C-C-> extends

8. With in class will implements With in class will extends only one class
n no. of interfaces by ","
seperated

-----------------------------------------------------------------------

Constructor->
2 types->
1. Default Constructor
2. Parameterized Constructor

Notes-
1. Constructor itself initialize at the time of object creation
2. Constaructor name same name as a class name
3. Constructor does not have any return type
4. Constructor overload possible in Java
5. Constructor override never possible in Java

Exception Handling->

Exception- It is an abnormal condition which is interrupt normal flow of program

2 types of Exception
1. Checked Exception[Compile Time]-
Ex- IOException, SQLException

2. Unchecked Exception[Run Time]-


Ex- NullPointerException, ArithmeticException

5 block-

try- Will add exceptional code in try block

catch- It is used to catch the Exception

throw-
1. It is a User Defined Exception
2. Will declare throw inside method
3. In throw will handle only one Exception at a time
4. It called explicitly

throws-
1. It is a System generated Exception
2. Will declare throws at the time of method declaration
3. In throws will handle multiple Exception by "," separated
4. It called implicitly

finally- Always execute


try-> System.exit(0);
Real Time- DB Connection Close, Hibernate Session Close

----------------------------------------------------------
String- It is a collection of character
- Immutable

StringBuffer
- Mutable
- Thread Safe
- THread Synchronized

StringBuilder
- Mutable
- Not Thread Safe
- Not Thread Synchronized
comes in JDK 1.5

Diff. .equals() & ==

What is SCP?
Write a program to do Reverse a String

Write a program to find repeated character with number of occurence

You might also like