Java Quick Recap
Java Quick Recap
ject-Oriented
V Secure
Robust
Platform Independent
V Portable
• Developed by Sun Microsystems
V Multithreaded
? Source Code
(java file )
Java
written
program
developer
by
JDK JDK
vs JRE vs JVM
JRE JVM
(Java Development Kit) (Java Runtime Environment) (Java Virtual Machine)
package used to develop JVM and other files that executes Java
EXECUTION FLOW
MOST ASKED INTERVIEW QUESTION
Java Source Code
java
C java file) Q. Why Java is platform independent ?
javac - Compiler converts source code Ans. Java is platform independent because
into bytecode its bytecode (.class file) runs on JVM,
and JVM is available on every platform.
.class - Bytecode (.class file) is created
So, write once (.java), run anywhere.
| JVM JVM
different
executes bytecode on
platforms
IMPORTANT NOTES
* JVM is the heart of Java.
Output
Execution result is * JRE is required to run Java programs.
shown to the user
* JDK is required to develop Java programs.
char grade =
'A'; Il single character name age 20
boolean is JavaFun true; II boolean value
;
II Create Scanner object to read input
Subtraction
Multiplication
mathematical
calculations. . Example :
/ Division
import [Link].
% Modulus (Remainder)
puablic class InputExample {
B. RELATIONAL OPERATORS public static void main(Stringl)args) {
Operator Meaning
Scanner sc = new Scanner ([Link]);
Equal to
Returns [Link]("Enter your age: ");
Not equal to
boolean
Greater than int age = [Link]();
(true/false).
< Less than [Link] ("Enter your name: ");
Greater than or equal
String = [Link]();
name
<= Less than or equal
[Link]("Age: " age);
C. LOGICAL OPERATORS
System. [Link] ("Name: name);
Operator Meaning
Used to
&& Logical AND combine
Logical OR conditions.
Loqical NOT • Common Methods :
x 5 time. Reads
next Boolean() boolean input
x / 5 x*/5
x %=5 x=*%5
3. INPUT FLOW TEACHER NOTES
User enters data
User Input
from
• Always close the Scanner using [Link]();
keyboard
Scanner Scanner class reads •nextLine() is used to read full line including
Variable Data
variables
is stored in
•Be careful with mixing nextInt() and
displays nextline().
Program
Output the result
NOTE : Operators are the building blocks. Input is the gatewy f every program.
Date :_/
CONTROL STATEMENTS
TEACHER NOTE
Definition : Control statements are used to control
• Used to control execution flow.
the flow of execution in a program.
• Helps in decision making
if condition is true
}
else if(marks >= 75) { Execute only
is true
[Link]. println ("C Grade");
Executes this block
else
if all conditions else {
are false System. out. println ("Fail");
case
break;
2: * break is
to } else
and apply for
{
license"); statement.
important
System. out. println ("Tuesday" );
("Wednesday");
[Link].
break;
println
} else {
default: System. out. println ("You cannot vote");
Used when number of Used when number of Similar to while loop but
Definition
iterations is known. iterations is unknown. executes at least once.
Execution Entry controlled loop Entry controlled loop Exit controlled loop
When we know how many When we don't know how When we must execute the
Use When
times loop will run. many times loop will run. code at least once.
2. FLOWCHARTS
FOR LOOP WHILE LOOP DO-WHILE LOOP
Initialization
N
No Loop Body
?
Condition Condition
Update
Yes Yes (inc/dec)
L Yes
3. PRACTICE EXAMPLES
A. PRINT 1 - 10 B. PRINT EVEN NUMBERS (2- 20) C. MULTIPLICATION TABLE (5)
do
num = 5,
{
i = 1;
5 x 10 = 50
TEACHER NOTE
Loops are heavily used in DSA, PRACTICE MORE CODE FASTER
problem solving and real world
THINK LOGIC BUILD MAGIC
applications.
Date :/
ARRAYS
An array is a collection similar type of elements stored in
• VISUAL EXAMPLE
Index : 1 2 3 4
Index always
Values : 10 20 30 40 50 starts from 0
Elements Array
1. DECLARATION 4. SEARCHING
Only declaration.
int key 30;
datatype[] arrayName; Memory not for (int = 0; i < [Link]; it+)
i
int] arr; (arr li]
allocated yet. if key){
System. [Link]("Found at index "* i);
break;
2. INITIALIZATION
I|Linear Search
Memory is }
int []arr = new int [5]; allocated and
int []arr (10, 20, 30, 40, 50); values are 5. SORTING (ASCENDING)
assigned.
for (int i 0; i < arr. length-1; it+){
for (int i = 0; i < arr. length; i++){ Access each arr (i] arr (jJ:
I| Bubble Sort
COMMON PROPERTIES
IMPORTANT NOTES
. Fixed size.
ArrayIndexOutfBoundsException .
STRINGS Strings
IMMUTABLE
are
Method Example
String s1 - "Hello"; (Literal) Description
Multi threaded
Best Use Single threaded [Link](" Developer");
Read-only operations
operations operations ||Thread safe
Date ://
0BJECT ORIENTED MOST
PROGRAMMING IMPORTANT
FOR
0OP is a wy f thinking to design a program using INTERVIEWS
OBJECTS and CLASSES.
Example :
A class is a class Car {
blueprint or template 1. CLASS String color;
int speed ;
for creating objects.
}
Example
An object is an
2. OBJECT Car c1 new Car);
instance fa class . c1. color "Red";
}
another class.
Example
Example
Encapsulation is binding
private int agei
data and methods
5. ENCAPSULATION public void setAge( int age) {
together and restricting this. age age;
direct access. }
Example
{
Interface is a blueprint interface Animal
QUICK RECAP
* Polymorphism provides flexibility. "Think in Classes,
A Object is the real world entity. Abstraction reduces complexity. Create real world
Date :/_I
EXCEPTION HANDLING
Exception Handling is a mechanism to handle runtime errors so that
the normal flow the program can be maintained.
1. BASIC FLOW 2. EXAMPLE
catch
Handles the [Link]. println( "Result: + );
exception. } catch (ArithmeticException e) {
[Link]. println("Cannot divide by zero. ");
Always executes
} finally {
finally whether exception [Link](" This is finally block.");
Occurs or not.
3. THROW vs THROWS
throw throws
Throws exception manually using throw keyword. It is not used inside the method body.
Checked or Unchecked exception can be thrown. Only checked exception can be declared.
Create a constructor.
generic Exception.
Date :_/_/
MULTITHREADING Multithreading
allows concurrentt
execution two
Multithreading in Jaaisa process f executing multiple
or more threads.
threads simultaneously to maximize CPU utilization.
1. THREAD CLASS
class MyThread extends Thread { PROCESS
• [Link] class is used
public void run() {
[Link] ("Thread is running");:
to create and manage a thread.
THREAD
• A thread is created by extending
It has only one method run(). Thread t2 new Thread (new MyRunnable());
[Link]();
3. SYNCHRONIZATION Counter {
class
4. THREAD LIFECYCLE
notify()/
start() sleep()/wait(), timeout
NEW RUNNABLE RUNNING BLOCKED TERMINATED
join() Waits for a thread to finish. V What are the thread states in Java ?
isAlive() Checks if the thread is still running. What is deadlock ? How to avoid it ?
setPriority (n) Sets the priority of the thread (1 to 10). V What is the purpose of sleep() and join() ?
Date _/_/
Java Database
Connectiity JDBC *
JDBC (Java Database Connectivity) is an API used to connect Java
applications with relational databases like MySQL
1. JDBC CONNECTION STEPS 2. JDBC ARCHITECTURE
Loads the database
[Link]().
Establish
JDBC API
connection
Provides
2. Create Connection using DriverManager.
standard
getConnection( ).
JDBC Driver Manager interfaces
and
Create Statement / classes.
3. Execute Query
Prepared Statement
and execute SQL
Driver 1 Driver 2 Driver n
query.
like Set,
3. MySQL SPECIFIC NOTES
5. Close Connection Result
Statement
"jdbe:mysql: //localhost:3306/mydb,
stmt con. create Statement()
"root", "1234");
; DriverManager Manages list database drivers .
ResultSet rs [Link]("SELECT FROM student"); Connection Represents a connection with the database.
while ([Link]()) {
TEACHER NOTES
INTERVIEW TIPS
What JDBC ?
* Always close resources in reverse order.
Explain
is
JDBC
and how
architecture.
it works
Date :_/L
Java 8 is a
major
with
enhancements.
release
powerful
JAVA 8 FEATURES Java
code more
readable
8 made
concise,
and
functional.
interfaces.
1/ Without Lambda
1/ Example : Get squares of even numbers
Runnable r1 new Runnable() {
List <Integer> list Arrays. aslist (1,2, 3,4, 5,6);
public void run()
ri. run();
map(n -> n•n) 1/ square
I| With Lambda
.
collect (Collectors. toList ());
Runnable r2 () -> [Link]. println( "Hello Java");
[Link](); [Link]. printin(result); 1|(4, 16, 36]
3. OPTIONAL CLASS
I/ nothing
* These features improve productivity and code quality
4. FUNCTIONAL INTERFACE
COMMON FUNCTIONAL INTERFACES IN JAVA 8
An interface with exactly one abstract method
Interface Method Description
is called a Functional Interface.
• Used as the target type for lambda expressions. Predicate <T) boolean test(T t) Evaluates a condition
@FunctionalInterface
interface MyInterface {
Function T,R> R apply(T t) Maps an input to output
void show(String msg:
Consumer <T) void accept(T t) Performs an action, no return
public class Test {
public static void main(String[] args) { Supplier < T> T get() Supplies a value
MyInterface m (msg) ->
System. out. println("Message: msg):
m. show("Hello Java 8");
UnaryOperator(T> T apply(T t) Operates on single operand
3 •
•
Real-time messagng
Loqin and user management
between users
Java (Socket Programming)
Multi-threading
5 API
•
• Build RESTful APIs Spring Boot
• MySQL
•
Perform
Test APIs
CRUD
using
operations
Postman . Postman
Tech Used :
AI POWERED JAVA APP
Java t ML
AI • Integrate ML model with Java
• Predict and recommend • Python Model (API)
• Smart automation features Spring Boot
& They improve coding and problem solvng. V Focus on functionality first.
* They teach real world application. V Write clean and maintainable code.
Keep
Keep Growing
Learning,
! ROADMAP Discipline
Success
• Syntax, Variables
Class, Object
Inheritance 2.. OOP 0OPs makes your code
rogee Abstraction
reusable and maintainable.
Driver, Connection
Statement, ResultSet 6. JDBC Connect Java applications
with Databases
• PreparedStatement
CRÚD Operations (MysQL, etc.)
• Auto Configuration
Build production ready
Starters
7. Spring Boot
REST applications faster.
Properties
Pplicationts
ORM Mapping
Table 8. Hibernate Work with DB easily
Entity,
HQL, JPQL using ORM tools.
CRUD with Hibernate
REST Principles
HTTP Methods 9. REST APIs APIs are the backbone
Status Codes
modern aplications.
JSON Handling
Small Services
Eureka, Config Server 10. Microservices Scale your applications
API Gateway like a pro !
Docker, Deployment
*
V Learn V Practice VBuild Revise
Projects
They
build confidence.
improve problem
solving
</>
* They teach real world
pplication.