Java Full Stack
Java Full Stack
[Link]("Hello, Java!");
}
}
S
● ave the code in a file named[Link]
● The file name must match the class name (HelloWorld)
● Use the Java compiler from the terminal or command prompt:
javac [Link]
java HelloWorld
Output:
Hello, Java!
C
● lass: Java code is organized in classes.
● main() method: Entry point of any Java program.
● [Link](): Used to print output to console.
Examples:
if (number > 5) {
[Link]("Number is big!");
}
class Car {
String model;
void start() {
[Link]("Car started");
}
}
Examples:
● Calculator
Examples:
● Gmail
● YouTube
3. Database
● Types:
● Often combined with the web server (like in Tomcat for Java)
User (Browser)
↓
↓ HTTP Request
↓
↓
↓
xample:
E
Buttons, forms, navigation menus, website layout
○ PHP,[Link],.NET
Responsibilities:
3) Database
Types:
Frontend (HTML/CSS/JS)
↓
Sends request
↓
↓
↓
↓
Type of codes:
1. If a set of instructions is human-readable, is it called high-level code.
Answer:
If a set of instructions (code) is understandable by humans, it is called high-level code or
high-level programming language.
Examples:
[Link]("Hello, World!");
// Java
print("Hello, World!")
// Python
Example:
10110000 01100001
es, a set of instructions that is between high-level and low-level code is often
Y
called intermediate code or intermediate-level code.
[Link]
Example file:
○
2. MSIL / CIL (.NET)
○ Microsoft Intermediate Language
Summary Table:
igh-Level
H Humans Java, Python
Code
Intermediate irtual
V ava
J
Code Machines Bytecode
ow-Level
L PU
C ssembly,
A
Code (Machines) Binary
High-Level Code:
● M
ust be translated into binary (machine code) using a compiler or
interpreter
Example (Java):
[Link]("Hello, World!");
10110000 01100001
How it works:
High-Level Code (Java, Python)
↓
Compiler / Interpreter
↓
Intermediate Code (Bytecode, etc.)
↓
Machine Code (Binary)
Final Point:
🔸
High-level code is not binary,
🔸
But it gets converted into binary so the machine can run it.
➤
Partially Yes — it's a type of low-level, non-human-readable
code, but not raw binary machine code.
Example:Java Bytecode
.classfiles
● Stored in
Compiled:
Answer:
Intermediate code
is not raw binary machine code
,
but it
can be in a binary format
(like bytecode) that
is understood by a
virtual machine
, not directly by
the CPU.
Note:
Execution of a Java Program
[Link]("Hello, World!");
}
}
●
Use the
Java Compiler (
javac
)
to compile the
.java
file.
javac [Link]
●
This creates a file called
[Link]
containing
bytecode
.
3. Bytecode is Generated
●
The
.class
file contains
intermediate code (bytecode)
●
Bytecode is
platform-independent
4. Execution by JVM
●
Use the
Java Virtual Machine (JVM)
to run the bytecode.
java Hello
●
The
JVM interprets or JIT-compiles
the bytecode into
machine code
specific to the system.
<Gunapati Suresh />
<JSpiders BTM Layout />
12
JAVA FULL STACK
Output:
Hello, World!
↓ javac
Bytecode (.class)
↓ JVM
Summary Points:
●
Java code is
compiled
into
bytecode
●
Bytecode is
executed by the JVM
, not directly by the
CPU
●
Java is
platform-independent
because of the JVM
MODULE:1
Language funcation
●
Intaduction
●
Keywords
●
Datatypes & variables
●
Operatores
●
Contral Statement
●
Methods
●
Identifiers
●
Scanner
●
Arrays
●
Strings
Module:2
Object oriented programing
●
Introduction
<Gunapati Suresh />
<JSpiders BTM Layout />
13
JAVA FULL STACK
●
Static & Non-static memters
●
Class & object
●
Memory management
●
Constructors
●
Inheritance
●
Constritance
●
Type casting
●
Method OVerloding
●
Polymorphism
●
Atstraction
●
Encapsutution
●
Enum & Imer Class
●
Has-A Relationship
Module:3
Core Java litraries.
●
Introduction
●
Class object
●
Exception handling
●
Class string
●
String Buffer & string Builder
●
Wrapper class
●
File handing
●
Threads
●
Collction framework
Program Languages:
Syntax:
Basic Syntax:
for writing a java program consists of
two
part
❖Class
<Gunapati Suresh />
<JSpiders BTM Layout />
14
JAVA FULL STACK
❖Main Method
Main Method:
Class ClassName{
[Link](“Welcom to java”);
}
}
Program:
class Program{
[Link](“Jspiders BTM”);
[Link](143);
[Link](3.45);
[Link](‘J’);
[Link](true);
}
}
Output:
Jspiders BTM
143
3.45
J
true
False
Class Suresh{
[Link](“[Link]”);
[Link](“2021-2025”);
[Link](‘7.2’);
[Link](‘M’);
[Link](true);
}
}
Practical Execution:-
[Link] CMD.
➔
Javac [Link]
➔
Java classname
➔ The programmer creates the source code and saves it in the
computer by providing a filename and “Java” file extension.
➔ The “Java” file is given to javac,it will check the program for
mistakes.
● If mistakes are found it will display error messages.
Javac:-
➔ It is the name of out java compiler.
➔ The compiler will take source code present in “Java” file as an input and
checks for compile time error.
➔ If compiler finds the error it will display appropriate error message.
➔ If no error is found if will generate”Class” file with byte code.
➔ The”Class” file generated by the compiler will always has same name
as the classname.
Bytecode:-
➔ It is the intermittent level code in java language.
➔ The byte code is generated by the compiler and is present inside
“Class” file.
➔ The byte code is not num an readable.
➔ The JVM make use of byte code for execution is also known as java.
JVM:-Java virtual machine.
➔ It is the execution engine of java programming language.
➔ The JVM execution the byte code to provide o/p.
➔ The JVM will control all the actiutes in the Runtime.
➔ It is a virtual [Link] does not hava a physical existence.
JRE:-Java Runtime Environment
➔ JVM internaly makes use of/subsystem during program execution.
❖ Loder
❖ Memory manger
❖ Linkers
❖ Verifier
❖ Event handlers
➔ All these tools combined together is known as jre.
➔ All activities in the jre is conterlled by the jvm.
The “+” operator:-
➔ In java we can use the ”+” to perform the following two operation.
● Addition
● Coneateration
0+10—-->20
1
“10”+”10”---->”1010”
“10”+10—-->”1010”
10+”10”------->”1010”
“A”+10—---->”A10”
‘A’+10—------>75
Note:-
In java erery character value is internally represented as a numbers
clerired from UNI CODE system.
‘A’ ‘Z’
| |
65 90
‘a’ ‘z’
| |
97 122
‘0’ ‘9’
| |
48 57
Comments:-
➔ Comments are used by the programmer description or explanation
about the java programs.
➔ In java the programmer writ comments in they are two types.
● Single line comment
● Multiple Linecomment
➔ Comments do not have any impact on program exeaction.
➔ The main goal of comment is to males the programmer easy to read
and understend.
Program:-
/*
Aim: To demonstrate the use of comments
Author: Gunapati Suresh
Unit: JSpiders-btm
Batch: Java afternoon 12
*/
<Gunapati Suresh />
<JSpiders BTM Layout />
19
JAVA FULL STACK
lass Demo
C
{
//Entery point for execution in side java program
Public static void main(String[] argos)
{
[Link](“Hello,World”);
}
}
Keywords:-
➔ Key words are in build works that have speciacnasy as a programmer
we can use keyword but we.
➔ In java keywords are always completely in lower.
➔ General keywords appear in a shade of blue collars.
➔ As per java version 1.8 the have a total of 53 keywords.
bstract, assert, boolean, break, byte, case, catch, char, class, const
A
(reserved, not used),continue, default, do, double,else, enum, extends,
final, finally, float, for, goto(reserved, not used),if, implements, import,
Instanceof, int, interface, long, native, new, package, private, protected,
public, return, short, static, strictfp, super, switch, synchronized, this,
Throw, throws, transient, try, void, volatile, while
Note:- Goto and const keywords are not used directlyin java programming.
Data Types:-
atatypes are programming help to determine what type of value can be stored
D
inside a variable.
➔ In java data type are classified two types is primitive.
❖ Primitive.
❖ Primitive data type.
❖ Non primitive data type.
➢
Primitive are predefined data types.
➢ Primitives are used to declare variable.
➢ Java provides a total of 8 primitive
Primitive:-
Byte—--->1-Byte
Short —--->2-Byte
Int—------->4-Byte
Long—--->8-Byte
Float—--->4-Byte
Double—-->8-Byte
Char—------>2-Byte
Boolean—--->1-Bit
Defination:-
➔
A method is a named block of code that is reusable in nature.
➔ Method are alos known as functions.
Syntax:-
. M
1 ethod Declaration
2. Method Defination
<access-modifier><modifier>retuntype methodname(<arguments>)
{
}
➔
method should always be declared directly in the class body.
A
➔ In java gets executed only when it as called.
➔ One a method is created it can be called n-number of times.
➔ In a class on our depending on our requirement,we can develop n number of
methods.
➔
Methods will make the program modular making it easy to read maintain and modify.
Programs:1
class Demo{
{
[Link]("Executing Play().....");
}
{
[Link]("Progerm Starts");
play();//Method Call
<Gunapati Suresh />
<JSpiders BTM Layout />
22
JAVA FULL STACK
[Link]("Progerm End");
}
}
OUTPUT:-
Progerm Starts
Executing Play().....
Progerm End
Programs:2
class Demo2{
{
[Link]("Program Starts");
help();
help();
help();
[Link]("Progerm End");
}
{
[Link]("Exacution help().....");
}
}
OUTPUT:-
Program Starts
Exacution help().....
Exacution help().....
Progerm End
Programs:3
class Demo3{
{
[Link]("Executing read()....");
}
{
[Link]("Executing write()....");
}
{
[Link]("Executing edit().....");
}
{
write();
edit();
read();
}
}
OUTPUT:-
Executing write()....
Executing edit().....
Programs:4
class Demo4{
{
int a=10;
[Link]("Value : "+a);
if (a%2==0){
[Link]("Even Number");
}
}
{
send();
}
}
OUTPUT:-
Value : 10
Even Number
Programs:5
class Demo5{
{
[Link]("Text Starts");
[Link]("Text End");
}
{
[Link]("Disp Starts");
send();
[Link]("Disp Ends");
}
{
[Link]("Main Starts");
disp();
[Link]("Main Ends");
}
}
OUTPUT:-
Main Starts
Disp Starts
Text Starts
Text End
Disp Ends
Main Ends
PASSING VALUES:-
● It’is of conupt of sending values from calling method to called method
Program:1
class Demo1{
[Link]("Value : "+arg);
}
{
test(4.5);
test(6.7);
test(7.5);
}
}
OUTPUT:-
Value : 4.5
Value : 6.7
Value : 7.5
Program:2
class Demo2{
{
int sum=a+b;
}
{
addition(12,13);
}
}
❖
ormal arguments are variables are created in the method declaration.
F
❖ Actual arguments are the values provided when calling the method.
❖ Passing values is how we can provide input for a method.
❖ Iff necessary the programmer pass multiple values by declaring multiple argument.
❖ When passing multiple values arguments should be separated with comma.
RETURNING VALUS:-
➔ It’is a concept the sending a value from called method back to calling method.
➔ To return a value the programmer has to following three step.
1. Declare return type based on value to be returned.
2. Return a compatible value using “Return” keyword.
3. Capture the returned value inside calling method.
Program:1
class Demo1{
{
return 10;
}
{
int val=test();
}
}
OUTPUT:-
class Demo2{
{
return 2.3;
}
{
double d=play();
}
}
OUTPUT:-
Program:3
class Demo3 {
static boolean help() {
return true;
}
static char disp() {
return 'J';
}
public static void main(String[] args) {
char ch = disp();
[Link]("Returned value : " + ch);
[Link]("Returned value : " + help());
}
}
UTPUT:-
O
Returned value : J
Returned value : true
<Gunapati Suresh />
<JSpiders BTM Layout />
29
JAVA FULL STACK
Verify()
➔ The verify () Method should task a integer argument.
➔ Check if given argument is even or odd.
➔ If even return true to the called if odd return false to the called.
Program:-
public class Pattern4 {
static int square(int n)
{
int sq=n*n;
return sq;
}
public static void main(String[] args)
{
for(int a=1;a<=5;a++)
{
[Link](a+"square : "+square(a));
}
}
}
Output:-
1square : 1
2square : 4
3square : 9
4square : 16
5square : 25
utput:-
O
Return value : true
Return value : false
Recussion in methods:
➔ A method are methods is set to be recursion in the following to
senarow.
➔
In this cenariow that called method males call back to It’s calling
method.
Program:
public class Pattern4 {
static void text() {
[Link]("Executing text()...");
disp();
}
static void disp() {
[Link]("Executing disp()....");
test();// This method is missing; we needto define it
}
static void test() {
[Link]("Executing test()....");
}
public static void main(String[] args) {
text();
}
}
Output:-
Executing text()...
Executing disp()....
Executing test()....
Cenariow-2
➔ The cenariow executing method makes a call to it self.
➔
If recursion under control it will cases stake overflow error.
➔
If programmer using recursion the programmer responsible to make
sure runcation happed to a controlled manner.
Identifiers:-
➔
Any name that is given by the programmer is called as identifiers.
➔As a programmer it’is our responsibility to provide.
➔In case of class names first letter of every word should be in
capital letter (Upper case).
Eg:- lass Karthik
C
Class Demo
Class Suresh
<Gunapati Suresh />
<JSpiders BTM Layout />
33
JAVA FULL STACK
➔
Method names and variable name.
➔In case method names and variable names the first word
complicity small letters (Lower case) and sub equations word are
the first letter will be in capital letters (Upper case).
Eg:- int age;
Double profilename
Class teacher
Scanner:-
import [Link];
class Program {
public static void main(String[] args) {
Scanner scn = new Scanner([Link]);
[Link]("Enter the value");
int val = [Link]();
[Link]("Value: " + val);
[Link]();// closes the scanner
}
}
<Gunapati Suresh />
<JSpiders BTM Layout />
34
JAVA FULL STACK
utput:-
O
Enter the value
42
Value: 42
Arrays:-
Definition:-An array is a finite set of homogenoasvalues.
inite:-Array are fixed in size
F
Set:-Array contain a group of value
Homogenoas:-Array contain values group of values
➔In java the programmer can create arrays two ways
● Using dimensions
● Using array intialzations
Using dimensions:-
Point:-In these approach will create an array byproviding the
datatype and size of the array.
Syntax:-
Datatype[] variblename = new datatype [int arr];
Example:-
Int[] arr1 = new int [10];
Double[] arr2= new double [5];
Char[] arr3= new char [7];
Using array intialzations:-
➔In these approach array created by providing the datatype and
actual value.
Syntax:-
Datatype[] variblename {value1,value2,value3…..value11};
Example:-
Int[] value = {7,5,18,27,4,8};
Double[] cgpa ={8.9,7.8,8.8,8.9,8.7};
Char[] vowel = {‘a’,’e’,’i’,’o’,’u’};
➔When ever we create an array the JVM allocates contiguous block
of memory based on the datatype and size of the array.
➔The block of memory internally divided of segments of equal size.
➔Each segment an array can be access using index values.
<Gunapati Suresh />
<JSpiders BTM Layout />
35
JAVA FULL STACK
➢
Sub point 1:-Index values always begins with ‘0’.
➢Sub point 2:-Index values always ends at [Link]-1.
g:- Int[] arr = new int[5];
E
class Array{
Important Questions:-
. Why java is considered as platform independent?
1
2. What is JDK?
3. What is JVM?
<Gunapati Suresh />
<JSpiders BTM Layout />
37
JAVA FULL STACK
. What is JRE?
4
5. What is JAVAC?
6. What is Bytecode?
7. What are Keywords?
8. What are Datatypes?
9. What are Primitives?
10. What are Variables?
11. What is Re-Initialization? How to prevent Re-Initialization?
12. How to create constant values in java?
13. What are operaters?
14. Difference between = and == operator?
15. Difference between post and pre operator?
16. What is Operator Overloading?
17. Can we write else statement in a java program directly?
18. After IF how many else can be written?
19. After IF how many else-if can be written?
20. What is the use of default in switch statement?
21. What is the use of break in switch statement?
22. Difference between for loop and while loop?
23. Difference between while loop and do-while loop?
24. What are Methods?
25. Explain Passing Values?
26. Explain Returning Values?
27. What is Recursion in Methods?
28. What are Identifiers?
29. What is Scanner and How to use?
30. What are Arrays?
odule-2
M
Trick-1
➔ It’is possible for the filename class name to the different but if is at
recommended.
➔ If the file and class name are different we should compile using the file name
execute using class name.
➔ [Link] file generated by the compiler will always hava the same name as
the class name.
lass karthik
C
{ —-----------------------> Box —--------------->
ox
B ox
B ox
B
[Link]
A [Link]
B [Link]
Trick-4
➔ If a class is a declare as a public it is mandatary the file name to be same as
class name.
lass Demo
C ublic class Demo
p
{ {
} }
[Link]
D [Link]
D
It is allowed—--->[Link] If is—------->[Link]
Bout not recommended—------>[Link] not required—-->[Link]
C.T.E
ote:-
N
In a signal source file only one class can be declare as public.
Program:-
emo
D
X: int static
Test(): void static
<Gunapati Suresh />
<JSpiders BTM Layout />
39
JAVA FULL STACK
class Naveen {
static int x = 100;
static void test() {
[Link]("Exeuting test().....");
}
}
public class Maniclass3 {
public static void main(String[] args) {
[Link](Naveen.x);
[Link]();
}
}
Output:-
100
Exeuting test().....
ample
S
a: int static
b: double static
play() : void static
disp(): void static
class Naveen {
static int a = 100;
static double b=8.9;
static void play(){
[Link]("Exeuting play().....");
}
static void disp()
{
[Link]("Exeuting disp().....");
}
}
public class Maniclass3 {
public static void main(String[] args) {
[Link](Naveen.a);
[Link](Naveen.b);
[Link]();
[Link]();
}
}
Non-Static Members:-
➔ Any member that is using static keyword is called as a non-static member.
Note:-
● Non static member can be access by creating a object.
Program:-
tility
U
P: int static
Q: int
test(): void static
play(): void
class Utility {
static int p = 10;
int q = 20;
static void test() {
[Link]("Exeuting test().....");
}
void play() {
[Link]("Exeuting play().....");
}
}
public class Mainclass4 {
public static void main(String[] args) {
Utility ref = new Utility();
[Link](Utility.p);
[Link](ref.q);
[Link]();
[Link]();
}
}
Output:-
10
20
Exeuting test().....
Exeuting play().....
2).class Delta {
).class Delta
3
{
int x=143;
void test()
{
[Link]("Executing test()....");
}
}
public class Mainclass1
{
public static void main(String[] args)
{
[Link](new Delta().x);
new Delta().test();
}
}
Output:-
143
Executing test()....
1).class Student{
String name;
double cgpa;
void study(){
[Link](name+" is studying");
}
void write(){
[Link](name+" is writing the cgpa is "+cgpa);
}
}
public class Mainclass5{
public static void main(String[] args)
{
Student s1=new Student();
[Link]="Karthik";
[Link]=7.5;
[Link]();
[Link]();
[Link]("------------------------------------");
Student s2=new Student();
[Link]="Suresh";
[Link]=8.0;
[Link]();
[Link]();
}
}
utput:-
O
Karthik is studying
Karthik is writing the cgpa is 7.5
------------------------------------
Suresh is studying
).class Emplotee
2
{
int eid;
double ctc;
void work(){
[Link](eid+" is working the ctc is "+ctc);
}
}
public class Mainclass6
{
public static void main(String[] args)
{
Emplotee e1=new Emplotee();
[Link]=100;
[Link]=4.5;
[Link]();
[Link]("-------------------------------------");
Emplotee e2=new Emplotee();
[Link]=101;
[Link]=4.6;
[Link]();
[Link]("-------------------------------------");
Emplotee e3=new Emplotee();
[Link]=103;
[Link]=4.7;
[Link]();
}
}
Output:-
100 is working the ctc is 4.5
-------------------------------------
101 is working the ctc is 4.6
-------------------------------------
103 is working the ctc is 4.7
3).class Player {
String name;
int number;
void play() {
[Link](name + " is the player with number " + number);
}
<Gunapati Suresh />
<JSpiders BTM Layout />
44
JAVA FULL STACK
}
public class Mainclass7 {
public static void main(String[] args) {
Player p1 = new Player();
[Link] = "Rohit";
[Link] = 23;
[Link]();
[Link]("--------------------------------");
Player p2 = new Player();
[Link] = "Virat";
[Link] = 18;
[Link]();
[Link]("--------------------------------");
Player p3 = new Player();
[Link] = "Dhoni";
[Link] = 7;
[Link]();
}
}
Output:-
Rohit is the player with number 23
--------------------------------
Virat is the player with number 18
--------------------------------
Dhoni is the player with number 7
4).class Mobile{
String model;
double price;
void call(){
[Link]("Calling in "+model);
}
void message(){
[Link]("Message in "+model+" its price is "+price+" lakhs");
}
}
public class Mainclass8{
public static void main(String[] args)
{
Mobile m1=new Mobile();
[Link]="poco";
[Link]=150000;
[Link]();
<Gunapati Suresh />
<JSpiders BTM Layout />
45
JAVA FULL STACK
[Link]();
m
[Link]("----------------------");
Mobile m2=new Mobile();
[Link]="I phone 15";
[Link]=100000;
[Link]();
[Link]();
[Link]("----------------------");
}
}
Output:-
Calling in poco
Message in poco its price is 150000.0 lakhs
----------------------
Calling in I phone 15
Message in I phone 15 its price is 100000.0 lakhs
----------------------
5).class Bike {
int cc;
double milage;
void drive() {
[Link]("Driving Bike with cc " + cc + " Milage " + milage);
}
}
public class Mainclass9 {
public static void main(String[] args) {
Bike ktm = new Bike();
[Link] = 390;
[Link] = 14.0;
[Link]();
[Link]("-------------------------------");
Bike re = new Bike();
[Link] = 150;
[Link] = 40.0;
[Link]();
[Link]("-------------------------------");
Bike sp = new Bike();
[Link] = 125;
[Link] = 55.0;
[Link]();
[Link]("-------------------------------");
}
<Gunapati Suresh />
<JSpiders BTM Layout />
46
JAVA FULL STACK
}
Output:-
Driving Bike with cc 390 Milage 14.0
-------------------------------
Driving Bike with cc 150 Milage 14.0
-------------------------------
Driving Bike with cc 125 Milage 14.0
-------------------------------
6).class Bottle {
String cap;
double water;
void showDetails() {
[Link]("Bottle with " + cap + " cap has " + water + " liters of water.");
}
}
public class Mainclass10 {
public static void main(String[] args) {
Bottle b1 = new Bottle();
[Link] = "Red";
[Link] = 1.5;
[Link]();
[Link]("--------------------------------");
Bottle b2 = new Bottle();
[Link] = "Blue";
[Link] = 2.0;
[Link]();
[Link]("--------------------------------");
Bottle b3 = new Bottle();
[Link] = "Green";
[Link] = 0.75;
[Link]();
}
}
Output:-
Bottle with Red cap has 1.5 liters of water.
--------------------------------
Bottle with Blue cap has 2.0 liters of water.
--------------------------------
Bottle with Green cap has 0.75 liters of water.