0% found this document useful (0 votes)
3 views34 pages

Java Full Stack Cours

JAVA
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views34 pages

Java Full Stack Cours

JAVA
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JAVA FULL STACK

COURSE
Source Code (.java)
Written by the developer.

Java is a high-level, object-oriented programming


language designed with the principle of platform Compilation (javac)
independence. The Java compiler converts .java
files into .class files (bytecode).
Java code is compiled into bytecode, not machine
code
Bytecode is platform-independent Bytecode (.class)
JVM executes the bytecode on any system Platform-independent intermediate
representation. (bytecode).
This enables “Write Once, Run Anywhere” portability

Execution (JVM)
JVM (Java Virtual Machine)
The Java Virtual Machine (JVM) is a core
component of the Java Runtime Environment
(JRE) that allows Java programs to run on any
platform without modification.
JVM enables platform independence by
executing bytecode instead of machine code, isolating from OS differences
Handles class loading & memory management (heap, stack, etc.)
Manages runtime memory automatically (heap, stack, metaspace), reducing developer burden
and preventing errors
Provides a secure sandbox environment, preventing direct access to system resources
JRE (Java Runtime Environment)

Java Runtime Environment (JRE) is an open-


access software distribution that includes a
Java class library, specific tools, and a separate
JVM.

JRE provides the environment required to run Java applications


Includes JVM, core class libraries (Java API), and supporting runtime files
JRE is sufficient for running Java applications but not for developing them
JDK (Java Development Kit)
Java Development Kit (JDK) is a cross-
platform software development kit that
provides tools and libraries needed to build
Java-based applications and applets.
Components of JDK
It works together with the JVM (Java
JRE (which includes JVM)
Virtual Machine) and JRE (Java Runtime
Development tools such as:
Environment) as part of the core Java
javac (compiler)
setup.
java (launcher)
JDK is required during development,
jdb (debugger)
whereas only JRE is required for
jar (archiver)
execution.
Variables and Datatypes Operators
Variables are containers to store data, and Operators are used to perform operations
Data Types define what kind of data can be on variables/data
stored.
Syntax dataType variableName = value; Components of Operators
int age = 20; Arithmetic(int a = 10 + 5; // +, -, *, /, %)
Primitive Datatype Relational(if(a > 5) // >, <, ==, !=)
store actual value (int, double, char, Logical(if(a > 5 && b < 10) // &&, ||, !)
boolean) Bitwise(int x = 5 & 3;)
Non-Primitive Datatype
store reference (String, Arrays, Objects)
import [Link];
Input/Output (I/O)
Input/Output (I/O) is used to take data
public class Main {
from user and display output to user.
Syntax (Scanner) public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
import [Link];
Scanner sc = new Scanner([Link]);
[Link]("Enter name: ");
next() vs nextLine()
String name = [Link]();
next()
Reads only one word
nextLine()
[Link]("Hello " + name);
Reads full line (including spaces) }
}
Control statements
Control statements are used to control the flow of program execution based
on conditions or repetition.

IF / ELSE-IF / NESTED IF
EXAMPLE:
if(condition){
// code if([Link]("admin")){
} else if(condition){ if([Link]("1234")){
// code [Link]("Login Success");
} else { } else {
// code [Link]("Wrong Password");
} }
}
Loops Loops are used to repeat a block of code multiple times

NESTED FOR LOOP EXAMPLE:


FOR LOOP
for(initialization; condition; A nested for loop is a loop
inside another loop. for(int i = 1; i <= 3; i++){
increment){
// code for(int j = 1; j <= 3; j++){
} [Link](j + " ");
for(initialization1; condition1; increment1){
}
Start → Condition → Increment [Link]();
for(initialization2; condition2; increment2)
}
{
// inner loop code
}
// outer loop code
}
Loops Loops are used to repeat a block of code multiple times

WHILE LOOP
EXAMPLE:
A while loop is used to execute a block of code repeatedly
as long as a condition is true. int i = 1;

while(condition){ while(i <= 5){


[Link](i);
// code
i++;
} }
Loops Loops are used to repeat a block of code multiple times

DO-WHILE LOOP
EXAMPLE:
A do-while loop is used to execute a block of code at least
once, and then repeat it as long as the condition is true. int choice;

do{ do{
// code [Link]("1. Add\n2.
} while(condition); Exit");
choice = [Link]();
} while(choice != 2);
Arrays
An array is a fixed-size, contiguous
memory data structure used to store
elements of the same data type.
int[] arr = {10, 20, 30, 40}; Multi-Dimensional Array
Single-Dimensional Array Array of arrays (matrix-like structure)
int[][] matrix = {
Stores elements in a linear format (one row) {1, 2, 3},
int[] arr = new int[5]; {4, 5, 6}
Memory Representation: };
Index: 0 1 2 3 4 Memory Representation:
Value: [10][20][30][40][50] matrix → reference → row1 → [1,2,3]
row2 → [4,5,6]
Strings
A sequence of characters represented
using String class.
String name = "Harini";
Immutability: Once a String object is
created, its value cannot be changed

String Pool
A special memory area inside heap where duplicate
strings are avoided

String a = "Java";
String b = new String("Java");
String vs StringBuilder vs StringBuffer

String StringBuilder StringBuffer


String s = "Hello"; StringBuilder sb = new StringBuilder("Hello"); StringBuffer sb = new StringBuffer("Hello");
s = s + " World"; [Link](" World"); [Link](" World");
[Link](sb); [Link](sb);
class Student {
// Variables (State)
String name;
Class in Java int age;
A class is a blueprint or template used to // Method (Behavior)
create objects. void display() {
[Link]("Name: " + name);
Syntax class ClassName { [Link]("Age: " + age);
// variables (fields) }
}
public class Main {
// methods public static void main(String[] args) {
} // Object Creation
Student s1 = new Student();
Object in Java // Assign values
[Link] = "Harini";
An object is an instance of a class. [Link] = 20;

Syntax ClassName obj = new ClassName(); // Method call


[Link]();
}
}
class User {
private String password; // hidden

OOPS IN JAVA public void setPassword(String password){


if([Link]() >= 6){
Encapsulation [Link] = password;
Encapsulation is the process of wrapping } else {
data (variables) and methods into a single [Link]("Password too short");
}
unit (class) and restricting direct access to }
the data. public String getPassword(){
return "********"; // hide actual password
Data inside a class is hidden from outside }
}
access public class Main {
It can only be accessed using methods public static void main(String[] args) {
User u = new User();
(getters and setters)
[Link]("123456");
[Link]([Link]());
}
}
class Employee {
String name;

OOPS IN JAVA void work(){


[Link]("Working...");
Inheritance }
}
Inheritance is a concept where one class
class Manager extends Employee {
(child) acquires properties and methods of void manage(){
another class (parent). [Link]("Managing team");
}
class Parent { }

// properties & methods public class Main {


} public static void main(String[] args) {
Manager m = new Manager();
class Child extends Parent {
// additional features [Link] = "Harini";
[Link](); // inherited
} [Link](); // own method
}
}
OOPS IN JAVA
Polymorphism
Polymorphism means “one method,
multiple forms” — the same method
behaves differently based on context.
Types of Polymorphism
class Calculator {
Compile-Time (Method Overloading)
int add(int a, int b){
Method Overloading is a type of polymorphism return a + b;
}
where multiple methods have the same name
int add(int a, int b, int c){
but different parameters, and the method call is return a + b + c;
resolved at compile time. }
}
OOPS IN JAVA
Polymorphism
Polymorphism means “one method,
multiple forms” — the same method
behaves differently based on context.
Types of Polymorphism
class Parent {
Runtime (Method Overriding) void show(){
[Link]("Parent method");
Method Overriding is a type of polymorphism
}
where a child class provides a specific }
class Child extends Parent {
implementation of a method already defined in @Override
the parent class, and the method call is resolved void show(){
[Link]("Child method");
at runtime. }
}
abstract class Vehicle {

OOPS IN JAVA abstract void start(); // abstract method

Abstraction void fuel() { // concrete method


Abstraction is the process of hiding implementation [Link]("Vehicle needs fuel");
}
details and showing only the essential features to the user. }
class Car extends Vehicle {
Abstract Class
@Override
An abstract class is a class that cannot be instantiated (cannot
void start() {
create object) and is used to provide a base structure for other [Link]("Car starts with key");
classes. }
abstract class ClassName { }
abstract void methodName(); // abstract
public class Main {
method public static void main(String[] args) {
void normalMethod(){ Car c = new Car();
// concrete method [Link]();
} [Link]();
}
}
}
interface Vehicle {
OOPS IN JAVA
Interface void start(); // abstract method
}
An interface is a completely abstract blueprint
used to define what a class should do, not how class Car implements Vehicle {
it does it.
@Override
It contains:
public void start() {
Abstract methods (by default) [Link]("Car starts with key");
Constants (public static final) }
interface Animal { }
// abstract method (by default public &
public class Main {
abstract)
public static void main(String[] args) {
void sound();
Car c = new Car();
// constant (public static final) [Link]();
int age = 5; }
} }
finally
EXCEPTION HANDLING try {
Exception Handling is a mechanism to handle int a = 10 / 2;
runtime errors so that the program does not } catch (Exception e) {
[Link]("Error");
crash and continues execution normally.
} finally {
Try /catch
[Link]("Always runs");
public class Test { }
public static void main(String[] args) {
throw
try {
throw new ArithmeticException("Custom Error");
int a = 10 / 0; // risky code
} catch (ArithmeticException e) { throws
[Link]("Cannot divide by zero");
void readFile() throws IOException {
}
}
}
}
COLLECTIONS FRAMEWORK
import [Link].*;
The Collections Framework is a set of classes
and interfaces used to store, manage, and
public class Test {
manipulate groups of data efficiently.
public static void main(String[] args) {
LIST
List<String> list = new ArrayList<>();
A List is an ordered collection in Java that
maintains the insertion order of elements. [Link]("Apple");
[Link]("Banana");
Allows duplicate elements
[Link]("Apple"); // Duplicate allowed
Supports index-based access

[Link](list);
}
}
COLLECTIONS FRAMEWORK
All core interfaces and classes of the Collections import [Link].*;
Framework are available in the [Link] package,
enabling easy access to standardized data structures public class Test {
in Java. public static void main(String[] args) {
SET Set<Integer> set = new HashSet<>();
A Set is a collection that stores unique elements
[Link](10);
only, meaning it does not allow duplicates.
[Link](20);
Stores unique elements only [Link](10); // Duplicate ignored
Does not allow duplicates
Does not guarantee order (except some [Link](set);
implementations) }
}
COLLECTIONS FRAMEWORK import [Link].*;
The Collections class provides useful utility
methods such as sorting, reversing, and shuffling,
public class Test {
which help in performing common operations
public static void main(String[] args) {
easily on collections.
Queue<Integer> q = new LinkedList<>();
QUEUE
A Queue is a collection designed to process [Link](1);
elements in a FIFO (First In First Out) manner. [Link](2);
Elements are added at the end and removed [Link](3);
from the beginning.
[Link]([Link]()); // Removes 1
}
}
COLLECTIONS FRAMEWORK import [Link].*;
The Collections class provides useful utility
methods such as sorting, reversing, and shuffling, public class Test {
which help in performing common operations public static void main(String[] args) {
easily on collections. Map<Integer, String> map = new
MAP (KEY-VALUE PAIR) HashMap<>();
A Map is a data structure that stores elements
[Link](1, "Apple");
in key-value pairs, where each key is unique
[Link](2, "Banana");
and maps to a specific value. It allows efficient
retrieval of data based on keys.
[Link]([Link](1));
}
}
import [Link].*;
public class Test {
LINKED LIST public static void main(String[] args) {
A LinkedList is a linear data structure where LinkedList<String> list = new
LinkedList<>();
elements are stored as nodes, and each node
[Link]("Apple");
contains: [Link]("Banana");
Data [Link]("Mango"); // adds at
Reference (link) to the next node beginning
[Link]("Orange"); // adds at end
In Java, LinkedList is a class that implements [Link](list);
both the List and Queue interfaces. [Link]();
[Link]();

[Link](list);
}
}
import [Link].*;

HASHMAP public class Test {


A HashMap is a data structure that stores public static void main(String[] args) {

elements in key-value pairs, where each HashMap<Integer, String> map = new


HashMap<>();
key is unique and maps to a specific value.

It is part of the Map interface and is widely [Link](1, "Apple");


[Link](2, "Banana");
used for fast data retrieval. [Link](1, "Mango"); // replaces value

[Link](map);
[Link]([Link](1));
}
}
import [Link].*;
HASHSET
A HashSet is a collection that stores unique public class Test {
public static void main(String[] args) {
elements only, and does not allow
HashSet<Integer> set = new HashSet<>();
duplicates.
[Link](10);
It is part of the Set interface and internally
[Link](20);
uses a HashMap. [Link](10); // ignored

[Link](set);
}
}
import [Link].*;
ARRAYLIST
An ArrayList is a resizable (dynamic) array public class Test {
public static void main(String[] args) {
implementation in Java that is part of the
ArrayList<String> list = new ArrayList<>
List interface. ();
It is used to store elements in an ordered [Link]("Apple");
manner and allows duplicate values. [Link]("Banana");
[Link]("Apple"); // duplicate allowed
List provides only method definitions, [Link](list);
whereas ArrayList provides the actual [Link]([Link](1)); // access
element
implementation of those methods.
[Link]("Banana");
[Link](list);
}
}

You might also like