Java March 2023
Java March 2023
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
History->
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{
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
Datatypes in Java->
1. byte
2. short
3. int
4. long
5. float
6. double
7. char
8. boolean
Core 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{
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
4. Class- Outer class never static, Inner class will be declared as static
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.
Native method stacks :For every thread, separate native stack is created.
It stores native method information.
.java -> Java Compiler[javac] -> .class -> Java Interpreter-> Output
2 types-
1. UpCasting- lower to higher
Ex. int to double
Core Java
Static Concept->
-------------------------------------------------------
Final Concept->
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
}
1. for
for(init; cond; ++/--)
2. while
while(cond){
stmnt;
}
3. do..while()
do{
stmnt;
}while(cond);
--------------------------------------------------------------------------
4 Pillars->
4 Pillars-
8. With in class will implements n no. With in class will extends only one class
of interfaces by "," seperated at a time
4 Pillars-
-----------------------------------------------------------------------------------
--
4 Pillars-
-----------------------------------------------------------------------------------
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
4 Pillars-
---------------------------------------------------------------------------------
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
5 block->
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
Exception Handling->
2 types of Exception
1] Checked[Compile Time]Ex- IOException, SQLException
5 blocks-
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->
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
2. Set- Uniqueness
A] HashSet
- Does not maintain order
- Allows one null element
B] TreeSet
- Follows order
- Not allows null element
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
-----------------------------------------------------------------------------------
--------
File Handling in Java->
3. Read File-
Ex- Use Scanner and give input as file reference
4. Delete File-
Ex- file.delete();
-----------------------------------------------------------------------------------
---------------
2 way-
1. extends Thread class
2. implements Runnable interface
Thread LifeCycle
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
2 Ways-
1. by extends Thread class
2. by implements Runnable interface
Thread Lifecycle-
InterThread Communication
wait(), notify and notifyAll()
wait();
notify() | notifyAll()
---------------------------------
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
-----------------------------------------------------------------------------------
-----
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();
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
Oops->
4 Pillars->
1. Abstraction- Hiding internal details and showing functionality
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->
2 types of Exception
1. Checked Exception[Compile Time]-
Ex- IOException, SQLException
5 block-
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
----------------------------------------------------------
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
What is SCP?
Write a program to do Reverse a String