Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
12 views84 pages

Java Training-1

This is my java training notes

Uploaded by

aditti4005
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)
12 views84 pages

Java Training-1

This is my java training notes

Uploaded by

aditti4005
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
You are on page 1/ 84

J A VA

PRESENTATION
By:-
Sanket, Rakhi, Aashi, Aditya
DAY - 1
I N T R O D U C T I O N T O JAVA
01. What is Java 04. Difference Between
Ja va And C

02. Features Of Java 05. Difference


Between Java
And C++

03. History Of Java 06. Code


• It is a programming language
• It has development environment such as
jdk 22, jdk 24
• It is application where application are of
three types -
WHAT IS
• 1.Core java(J2SE stands for J2 standard
JAVA? edition)
• 2.Advance java(J2EE stands for J2
enterprise
edition)
• 3.J2ME(J2 mobile edition)
Features Of Java
01 03
Simple & Platform Independent
Object-Oriented & Portable
Easy to learn and follows Runs anywhere and can be
object-oriented principles. easily transferred

02 04
Interpretable, Scalable
Secure & Efficient
& Robust
JVM-based, supports growth, Provides strong security with
and ensures reliability. good performance.
HISTORY OF
In 1995, Oak was
renamed as java
In 1991, java was and father of java In 2005, J2ME was

JAVA
introduced as Oak was James Gosling introduced

1993 1999

1991 1995 2005

In 1993, CUI was In 1999, J2EE was


converted into GUI introduced
Difference Between Java And C

• Java was developed by • C was developed by Dennis


James Gosling in 1995. M. Ritchie between 1969
and 1973
• Java is Object Oriented
Language. • C is a Procedural
Programming Language.
• Java is an Interpreted
language that is in Java, the • C is a compiled language
code is first transformed that is it converts the code
into bytecode and that into machine language so
bytecode is then executed that it could be understood
by the JVM (Java Virtual by the machine or system.
Machine).
Difference Between Java And C++

• Platform-independent, Java • Platform dependent should


bytecode works on any be compiled for different
operating system. platforms.

• Java is both a Compiled • C++ is a Compiled


and Interpreted Language. Language.

• Java supports only calls by • C++ both supports call by


value. value and call by reference.
Write a program to
print Hello World

First
Java
program
DAY - 2
B AS I C , VA RI AB LE S &
C O N T R O L ST AT EMEN TS
01. if Statement 04. Program(while-loop)

02. Program(Simple-if) 05. for-loop

03. while-loop 06. Program(for-


loop)
Program using
Simple IF
Statement
Calculator
using Simple
IF Statement
While Loop Syntax:
Program
Using While
Loop To Print
Alphabets
Program
to Sum
Numbers
Using While
Loop
Program to
Print Square
From 10 to 1
Program to
Print Natural
Number With
While Loop
For Loop Syntax:

for (initialization expr; test


expr; update expr)
{
// body of the loop
// statements we want to
execute
}
Program:

Print
the
Pattern
Program:

Print
the
Pattern
Program:

Print
the
Pattern
D AY - 3
I N T R O D U C T I O N TO JAVA G U I DE V E LO P ME N T IN N E T B E A N S

01. Creating Calculator 03. Drop-down Selection


with Message Dialog

02. Multiple Image Navigator


Using Buttons
1. C R E A T I N G A C A L C U L A T O R

Creating Design calculator using Jframes having jlabel, jbutton, jTextArea and
various swing controls
STEPS

▪ We type two numbers in the given text fields.

▪ We choose the operation we want (Add,


Subtract, Multiply, Divide).

▪ When we click the button, the program reads


both numbers.

▪ It does the calculation based on the operation


we selected.

▪ The answer is shown inside the text area on


the window.
Logic Behind the design Of Calculator
2: D R O P - D O W N S E L E C T I O N W I T H MESSAGE D I A L O G
STEPS
1. Thewindowopenswithasmaldropdown
menu.

2. Inthatmenu,youcanchooseeitheradminor
user.

3. If youpickadmin,itshowsamessagesaying
“WelcomeAdmin.”

4. If youpickuser,itshowsamessagesaying
“WelcomeUser.”

5. If youleaveitonselect,nothinghappens.
LOGIC BEHIND DIALOG BOX
. Multiple Image Navigator Using
uttons
STEPS
We keep a counter i to know which image is
01 showing; clicking OK moves to the next image,
and Previous goes back.

We check the counter using a switch


02 statement to change the image in jLabel1

We show the images (1.jpg, 2.jpg, 3.jpg)


03 one by one as we navigate through them.
Logic Behind the Use of “Ok” and “previous” Button for multiple
images
DAY – 4
I N T R O D U C T I O N T O OOP
01. Cla ss 04. Constructor

02. Method 05. Constructor


with parameter

03. Method with 06. Static


parameter
• A class in Java is a template with the help of which we
create real-world entities known as objects that share
common characteristics and properties.
• Class Declaration in java:-
access_modifier class<class_name> {
data member;
method;
What is constructor;
nested class;
Class? interface;
}
• Class names usually start with a capital letter.
• Classes provide reusability → one class can be used to
create many objects.
• We can create a class inside another class
• The name of the public class must match the file name.
A method is a block of code inside a class
01 that performs a specific task..
What Is Method??

Methods improve code reusability —


02 you write once and call it multiple times.

Java supports method overloading and


03 overriding, which are key concepts of
polymorphism in OOP..
“Java Program to
Demonstrate
Class, Object, and
Method”
“Java Program to
Demonstrate
Method With
Parameter”
“Java Program
to Demonstrate
Constructor”
(Default)
“Java Program to
Demonstrate
Constructor with
parameter”
“Java Program
to Demonstrate
static method”
DAY - 5
O OP S ( I N HER IT E N CE )
01. What is Inheritence 04. Hierarchical
Inheritence

02. Single-Level
Inheritence
05. Interface(Basics)

03. Multi-Level 06. Multiple


Inheritence Inheritence
• Inheritance is when one class (child/subclass)
can use properties and methods of another
class (parent/superclass).
• Achieved using the extends keyword.
• Improves code reusability.
What is
• Classes provide reusability → one class
Inheritence? can be used to create many objects.
• It Supports method overriding (same
method redefined in child class).
• It Demonstrates “is-a” relationship (e.g.,
Dog is a Animal).
Single-Level Inheritence

• Involves only one parent class and one child class.

• Implemented using the extends keyword.

• Provides code reusability (child can use parent’s methods/variables).

• Supports method overriding (child can redefine parent’s method).

• Shows an “is-a” relationship (e.g., Dog is an Animal).


“Single-Level
Inheritence”
Multi-Level Inheritence

• It’s like a family chain → a parent, a child, and then a grandchild.

• We use the extends keyword again and again to link the classes.

• The last class (grandchild) can use features from both parent and child, which saves coding
effort.

• Each class in the chain can change or update methods from the class above it.

• It shows a step-by-step “is-a” relationship → Example: Puppy is a Dog, and Dog is an Animal.
“Multi-Level
Inheritence”
Hierarchical Inheritence

• It means one parent class has many child classes.

• All child classes use the extends keyword to inherit from the same parent.

• Each child class gets the features of the parent, but they can also have their own features.

• Child classes can redefine (override) the parent’s methods if needed.

• It shows an “is-a” relationship in different directions → Example: Dog is an Animal, Cat is an


Animal, but Dog is not a Cat.
“Hierarchical
Inheritence”
• An interface is like a set of rules that a class
must follow.

• A class uses implements to follow (use) an


interface.

• One class can follow many interfaces at the


What is same time .This is how Java allows multiple
Interface? inheritance (because one class can’t directly
inherit from more than one class).

• All the methods inside an interface are like


empty instructions (just names, no body) that
the class must fill in.
“Interface
(Basic)”
Multiple Inheritence

• Multiple inheritance means a class can take features from more than one parent.

• In Java, this is not possible with classes (to avoid confusion), but it is possible with interfaces.

• A class can use the implements keyword to follow many interfaces at the same time.

• If two interfaces have the same method, the child class must define it clearly (to remove
confusion).

• It shows an “is-a” relationship from many parents → Example: A Smartphone is a Camera and
is a Phone at the same time.
“Multiple
Inheritence”
DAY - 6
OOPS( P O L Y MO R P HI SM)
01. What is Polymorphism 04. Dynamic
Polymorphism

02. Types of 05. Array(1-D) Basic


Polymorphism

03. Static Polymorphism


• Polymorphism means one thing behaving in
many ways.
• In Java, it is mainly of two types: Compile-time
(method overloading) and Runtime (method
overriding).
• Method Overloading → Same method name but
What is different parameters in the same class.
Polymorphism? • Method Overriding → Same method name, same
parameters, but defined differently in child class.
• Example: A Shape class can have a draw()
method, and child classes like Circle and Square
can draw differently.
Types Of Polymorphism
Static Polymorphism Dynamic Polymorphism
• It happens when we have multiple • It happens when a child class has the
methods with the same name but same method as the parent class but
different parameters in the same class. with a different implementation.

• The method call is decided during • The method call is decided during
compilation by the compiler. runtime by the JVM.

• It is also called Method Overloading. • It is also called Method Overriding.

• The return type can be the same or • It is mainly used when we want
different, but the parameters must be different behaviors for the same
different (number or type). method in parent and child classes.

• It makes the code clean, simple, and • It supports dynamic behavior and
reusable. makes the program more flexible.
Static Polymorphism
i) Number of Parameters

• When two or more methods have the same name but take a different number of
inputs (parameters).

• Java decides which method to run while compiling the program, not at runtime.

• The method is chosen based on how many values you pass when calling it.

• This is done using method overloading.

• It makes the code simpler and easier to read.


“Static
Polymorphism

(Number of
parameters)”
Static Polymorphism
ii) Type of Parameters

• When two or more methods have the same name but take different types of inputs
(parameters).

• Java decides which method to run while compiling the program.

• The method is chosen based on the data type of the values you pass when calling it.

• This is also achieved using method overloading.

• It makes the code flexible and easier to maintain.


“Static
Polymorphism

(Types of
parameters)”
Static Polymorphism
ii) Sequence of Parameters

• When two or more methods have the same name but take the same number of
inputs arranged in a different order.

• Java decides which method to run while compiling the program, not at runtime.

• The method is chosen based on the sequence of values you pass when calling it.

• This is done using method overloading.

• It makes the code flexible and easy to understand.


“Static
Polymorphism

(Sequence of
parameters)”
Dynamic Polymorphism
• When a child class has the same method as its parent class, but with a different
implementation.

• Java decides which method to run at runtime, not while compiling.

• This is achieved using method overriding.

• It allows the program to choose the correct method based on the object being used.

• It makes the code more flexible and supports runtime decision-making.


“Dynamic
Polymorphism”
“Dynamic
Polymorphism
(superoverriding)”
“Dynamic
Polymorphism”
Array(1-D)
• A 1D array is a linear collection of elements (data stored in a straight line).

• It can store multiple values of the same data type (e.g., all integers, all strings).

• Each value in the array is stored at a specific index (starts from 0).

• Accessing elements is done using the index number (e.g., arr[0] gives the first
value).

• It saves memory and makes the code cleaner and easier to manage.
“Array(1-D)
Basic Syntax”
DAY 7 –
Collection Frameworks
Array List
Implementation
Code
Hash Set
Implementation
Code
Tree Set
Implementation
Code
Priority Queue
Implementation
Code
DAY - 6
INTRODUCTION OF COLLECTIONS
01. List 04. Queue

02. Set 05. Stack

03. Map
• Stores elements in an ordered sequence.

• Duplicates are allowed in a List.

• Size is dynamic, unlike arrays.

What is List • Elements are accessed using an index


starting from 0.

• List is an interface implemented by classes


like ArrayList, LinkedList, and Vector

• Can store objects of any type, but not


primitive types directly.
“ArrayList
Implementation”
• Stores unique elements — duplicates are
not allowed.

• Does not maintain insertion order (except


LinkedHashSet).

What is Set • Can store objects of any type, but not


primitive types directly.

• TreeSet stores elements in sorted order,


while HashSet does not.

• Best suited when you need unique values


without duplicates.
“Hashset
Implementation”
“Treeset
Implementation”
• Stores data in key-value pairs — each key is
unique, but values can be duplicate.

• Map is an interface implemented by classes


like HashMap, etc.

What is Map • If you try to insert a duplicate key, the old


value gets replaced with the new one.

• Can store objects of any type for both keys


and values.

• Best when you need fast access to values


using a unique key.
“HashMap
Implementation”
• Queue is an interface in Java used to store
elements in order.

• It follows the FIFO rule (First In, First Out) —


the element added first is removed first.

• Common implementations are LinkedList,


What is Queue PriorityQueue, and ArrayDeque.

• add() / offer() methods are used to insert


elements, and remove() / poll() methods
are used to delete elements.

• PriorityQueue sorts elements based on


priority instead of insertion order.
“PriorityQueue
Implementation”
“ArrayDeque
Implementation”
• PriorityQueue sorts elements based on
priority instead of insertion order. Stack is a
class in Java used to store elements in
order.

• It follows the LIFO rule (Last In, First Out) —


the element added last is removed first.
What is Stack
• Common methods: push() to add, pop() to
remove, and peek() to see the top element.
• It is part of the java.util package.

• Useful for solving problems like undo


operations, expression evaluation, and
backtracking.
“Stack
Implementation”

You might also like