0% found this document useful (0 votes)
6 views47 pages

Java Full Stack

The document provides a comprehensive overview of Java, including its definition, installation process, and basic programming structure. It explains Java's application types, web application architecture, and the differences between high-level, intermediate, and low-level code. Additionally, it covers the flow of a web application and the roles of frontend, backend, and database components.
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)
6 views47 pages

Java Full Stack

The document provides a comprehensive overview of Java, including its definition, installation process, and basic programming structure. It explains Java's application types, web application architecture, and the differences between high-level, intermediate, and low-level code. Additionally, it covers the flow of a web application and the roles of frontend, backend, and database components.
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‬

‭Step 1: What is Java?‬

‭●‬ J ‭ ava is a‬‭high-level, object-oriented programming‬‭language‬‭developed by‬‭Sun‬


‭Microsystems‬‭in 1995 (now owned by Oracle).‬
‭●‬ ‭It is used to build‬‭desktop, web, mobile, and enterprise‬‭applications‬‭.‬

‭Step 2: Java Installation‬

‭●‬ ‭To write and run Java programs, you need:‬


‭○‬ ‭JDK‬‭– Java Development Kit (contains compiler, tools)‬
‭○‬ ‭JRE‬‭– Java Runtime Environment (contains JVM to run‬‭programs)‬
‭○‬ ‭IDE (Optional)‬‭– Tools like‬‭Eclipse‬‭,‬‭NetBeans‬‭, or‬‭IntelliJ‬‭to help write code‬

‭Step 3: Write Java Code.‬

‭●‬ ‭A basic Java program looks like this:‬

public class HelloWorld {‬


public static void main(String[] args) {‬


[Link]("Hello, Java!");‬

}‬

}‬

‭Step 4: Save the File‬

‭‬ S
● ‭ ave the code in a file named‬‭[Link]‬
‭●‬ ‭The file name must match the class name (HelloWorld)‬

‭Step 5: Compile the Code‬

‭●‬ ‭Use the Java compiler from the terminal or command prompt:‬

‭javac [Link]‬

‭·‬ ‭This creates a‬‭[Link]‬‭file (bytecode)‬

‭Step 6: Run the Program‬

‭●‬ ‭Run the compiled file using JVM:‬

‭java HelloWorld‬

‭Output:‬

‭Hello, Java!‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭1‬
‭JAVA FULL STACK‬
‭Step 7: Java Program Structure‬

‭‬ C
● ‭ lass‬‭: Java code is organized in classes.‬
‭●‬ ‭main() method‬‭: Entry point of any Java program.‬
‭●‬ ‭[Link]()‬‭: Used to print output to console.‬

‭Step‬‭8: Java Data Types‬

‭Examples:‬

‭·‬ int number = 10;‬


‭·‬ double price = 99.99;‬


‭·‬ String name = "Suresh";‬


‭·‬ boolean isJavaFun = true;‬


Step 9: Control Statements‬



‭‬ ‭
● if, else, switch‬
‭●‬ ‭
for, while, do-while‬‭
loops‬

if (number > 5) {‬

[Link]("Number is big!");‬

}‬

Step 10: Object-Oriented Features‬



‭‬ ‭
● Java uses‬‭
classes and objects‬
.‬

‭●‬ ‭
You define‬‭
methods, variables, constructors‬‭
in a class.‬

class Car {‬

String model;‬

void start() {‬

[Link]("Car started");‬

}‬

}‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭2‬
‭JAVA FULL STACK‬
‭Types of application:‬

‭1. Standalone Application (Desktop Application)‬

‭●‬ ‭Runs‬‭independently on a single machine‬

‭●‬ ‭Does‬‭not require‬‭a network or internet connection‬‭(usually)‬

‭●‬ ‭Installed manually on the system‬

‭Examples:‬

‭●‬ ‭MS Word‬

‭●‬ ‭Calculator‬

‭●‬ ‭VLC Media Player‬

‭2. Web-Based Application‬

‭●‬ ‭Runs‬‭on a web server‬

‭●‬ ‭Accessed through a‬‭web browser‬

‭●‬ ‭Requires‬‭internet connection‬

‭●‬ ‭User doesn't need to install it‬

‭Examples:‬

‭●‬ ‭Gmail‬

‭●‬ ‭YouTube‬

‭●‬ ‭Online Shopping Sites (Amazon, Flipkart)‬

‭Web Application Architecture (Simple Explanation)‬

‭ eb application architecture‬‭defines the‬‭structure‬‭of how different components of a web‬


W
‭app communicate with each other — from the user's browser to the backend server and‬
‭database.‬

‭Basic Web Application Architecture Includes:‬


‭<Gunapati Suresh />‬
‭<JSpiders BTM Layout />‬
‭3‬
‭JAVA FULL STACK‬
‭1. Client-Side (Frontend)‬

‭●‬ ‭What the user sees and interacts with‬

‭●‬ ‭Runs in the web browser‬

‭●‬ ‭Built using:‬

‭○‬ ‭HTML, CSS‬

‭○‬ ‭JavaScript (React, Angular, [Link])‬

‭2. Server-Side (Backend)‬

‭●‬ ‭Handles business logic and data processing‬

‭●‬ ‭Responds to client requests‬

‭●‬ ‭Built using:‬

‭○‬ ‭Java (Servlets, JSP, Spring Boot)‬

‭○‬ ‭Python (Django, Flask)‬

‭○‬ ‭PHP, [Link], etc.‬

‭3. Database‬

‭●‬ ‭Stores the application's data‬

‭●‬ ‭Connected to the backend‬

‭●‬ ‭Types:‬

‭○‬ ‭SQL: MySQL, PostgreSQL‬

‭○‬ ‭NoSQL: MongoDB‬

‭4. Web Server‬

‭●‬ ‭Handles incoming client requests (HTTP/HTTPS)‬

‭●‬ ‭Sends data to and from the backend‬

‭●‬ ‭Examples: Apache, Nginx, Tomcat‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭4‬
‭JAVA FULL STACK‬
‭5. Application Server‬

‭●‬ ‭Hosts the backend logic and services‬

‭●‬ ‭Often combined with the web server (like in Tomcat for Java)‬

‭Flow of a Web Application:‬

User (Browser)‬

↓‬

Frontend (HTML, JS)‬


↓ HTTP Request‬

Web Server (Apache/Tomcat)‬


↓‬

Backend (Java, PHP, etc.)‬


↓‬

Database (MySQL, MongoDB)‬


↓‬

Backend → Web Server → Client (Response)‬


‭Example:‬‭Java-Based Web App Architecture‬

‭●‬ ‭Frontend‬‭: HTML + CSS + JS‬

‭●‬ ‭Backend‬‭: Java (Servlets, JSP, or Spring Boot)‬

‭●‬ ‭Database‬‭: MySQL‬

‭●‬ ‭Server‬‭: Apache Tomcat‬

‭Web application consition three types :‬

‭1) Frontend (Client-side)‬

‭●‬ ‭What the‬‭user sees‬‭and interacts with‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭5‬
‭JAVA FULL STACK‬
‭●‬ ‭Runs in the‬‭web browser‬

‭●‬ ‭Built using:‬

‭○‬ ‭HTML‬‭– Structure‬

‭○‬ ‭CSS‬‭– Styling‬

‭○‬ ‭JavaScript‬‭– Interactivity‬

‭○‬ ‭Frameworks: React, Angular, [Link]‬

‭ xample:‬
E
‭Buttons, forms, navigation menus, website layout‬

‭2) Backend (Server-side)‬

‭●‬ ‭Handles‬‭logic‬‭,‬‭processing‬‭, and‬‭data communication‬

‭●‬ ‭Runs on a‬‭web server‬

‭●‬ ‭Built using languages like:‬

‭○‬ ‭Java‬‭(Spring Boot, Servlets, JSP)‬

‭○‬ ‭Python‬‭(Django, Flask)‬

‭○‬ ‭PHP‬‭,‬‭[Link]‬‭,‬‭.NET‬

‭Responsibilities:‬

‭●‬ ‭Process requests from frontend‬

‭●‬ ‭Connect to database‬

‭●‬ ‭Send responses back to frontend‬

‭3) Database‬

‭●‬ ‭Stores‬‭persistent data‬‭used by the web app‬

‭●‬ ‭Backend communicates with it using queries‬

‭Types:‬

‭●‬ ‭SQL Databases‬‭: MySQL, PostgreSQL, Oracle‬

‭●‬ ‭NoSQL Databases‬‭: MongoDB, Firebase‬


‭<Gunapati Suresh />‬
‭<JSpiders BTM Layout />‬
‭6‬
‭JAVA FULL STACK‬
‭Stores:‬

‭●‬ ‭User info‬

‭●‬ ‭Login details‬

‭●‬ ‭Orders, messages, etc.‬

‭Simple Diagram (Text Format):‬

Frontend (HTML/CSS/JS)‬

↓‬

Sends request‬

↓‬

Backend (Java, Python, etc.)‬


↓‬

Talks to Database (MySQL, MongoDB)‬


↓‬

Sends data back‬


↓‬

Frontend displays result to user‬


‭Type of codes:‬
‭1.‬ ‭If a set of instructions is human-readable, is it called high-level code.‬

‭Answer:‬

I‭f a set of instructions (code) is understandable by humans, it is called high-level code or‬
‭high-level programming language.‬

‭What is High-Level Code?‬

‭●‬ ‭Written in human-readable format‬

‭●‬ ‭Easier to learn and write‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭7‬
‭JAVA FULL STACK‬
‭‬ U
● ‭ ses English-like syntax and keywords‬
‭●‬ ‭Must be compiled or interpreted to run on a computer‬

‭Examples:‬

[Link]("Hello, World!");
‭ // Java‬

print("Hello, World!")
‭ // Python‬

‭ .If a set of instructions is in binary, it is called Low-Level Code or‬


2
‭Machine Code.‬

‭What is Low-Level Code?‬

‭●‬ ‭Written in binary (0s and 1s)‬

‭●‬ ‭Directly understood by the computer's CPU‬

‭●‬ ‭Very fast and efficient for machines‬

‭●‬ ‭Hard for humans to read or write‬

‭●‬ ‭Closest form to hardware‬

‭Example:‬
10110000 01100001‬

‭(This might instruct the CPU to load a value into a register)‬

‭Types of Low-Level Code:‬

‭1.‬ ‭Machine Code‬


‭○‬ ‭Pure binary instructions‬
‭○‬ ‭Directly executed by CPU‬

‭2.‬ ‭Assembly Language‬


MOV‬
‭○‬ ‭Slightly readable (uses mnemonics like‬‭ ADD‬
‭,‬‭ ‭)‬
‭○‬ ‭Needs to be translated to machine code using an assembler‬

‭ .If a set of instructions is partially human-readable and partially‬


3
‭machine-readable, is it called intermediate-level code?"‬
‭<Gunapati Suresh />‬
‭<JSpiders BTM Layout />‬
‭8‬
‭JAVA FULL STACK‬
‭Corrected Understanding:‬

‭ es, a set of instructions that is between high-level and low-level code is often‬
Y
‭called intermediate code or intermediate-level code.‬

‭What is Intermediate-Level Code?‬

‭ ‬ I‭t is not fully human-readable like high-level code‬



‭●‬ ‭It is not fully machine code either‬
‭●‬ ‭It is partially readable and designed for execution by a virtual‬
‭machine (VM)‬

‭Examples of Intermediate-Level Code:‬

‭1.‬ ‭Bytecode (Java)‬


.java‬‭files‬
‭○‬ ‭Produced after compiling‬‭

‭○‬ ‭Executed by the Java Virtual Machine (JVM)‬

[Link]‬
‭ ‬ ‭Example file:‬‭

‭2.‬ ‭MSIL / CIL (.NET)‬
‭○‬ ‭Microsoft Intermediate Language‬

‭○‬ U ‭ sed in C#, [Link] – runs on the .NET CLR (Common‬


‭Language Runtime)‬
‭3.‬ ‭LLVM IR‬
‭○‬ ‭Intermediate Representation used in compilers like‬
‭Clang/LLVM‬

‭Summary Table:‬

‭Code Type‬ ‭Readable by‬ ‭Example‬

‭ igh-Level‬
H ‭Humans‬ ‭Java, Python‬
‭Code‬

I‭ntermediate‬ ‭ irtual‬
V ‭ ava‬
J
‭Code‬ ‭Machines‬ ‭Bytecode‬

‭ ow-Level‬
L ‭ PU‬
C ‭ ssembly,‬
A
‭Code‬ ‭(Machines)‬ ‭Binary‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭9‬
‭JAVA FULL STACK‬
‭4.‬ ‭Is high-level code also binary code?‬

‭➤‬‭No, high-level code is not binary code.‬

‭Here's the correct explanation:‬

‭High-Level Code:‬

‭●‬ ‭Written in human-readable language (like Java, Python, C++)‬

‭●‬ ‭Looks like English instructions‬

‭●‬ ‭NOT binary‬

‭●‬ M
‭ ust be translated into binary (machine code) using a compiler or‬
‭interpreter‬

‭Example (Java):‬

[Link]("Hello, World!");‬

‭Binary Code (Machine Code):‬

‭●‬ ‭Low-level code‬

‭●‬ ‭Written in 0s and 1s‬

‭●‬ ‭Understood directly by the CPU‬

‭●‬ ‭Looks like:‬

10110000 01100001‬

‭How it works:‬
High-Level Code (Java, Python)‬

↓‬

Compiler / Interpreter‬

↓‬

Intermediate Code (Bytecode, etc.)‬

↓‬

Machine Code (Binary)‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭10‬
‭JAVA FULL STACK‬
↓‬

CPU Executes‬

‭Final Point:‬

🔸
‭ High-level code is not binary,‬
🔸
‭ But it gets converted into binary so the machine can run it.‬

‭5‬ ‭.Is intermediate-level code also binary code?‬


‭ ‬‭Partially Yes — it's a type of low-level, non-human-readable‬
‭code, but not raw binary machine code.‬

‭Example:‬‭Java Bytecode‬

.java‬‭source code by the Java compiler‬‭(‭


‭●‬ ‭Generated from‬‭ j
‬ avac‬
‭)‬

.class‬‭files‬
‭●‬ ‭Stored in‬‭

‭●‬ ‭Executed by the‬‭JVM (Java Virtual Machine)‬‭— not the‬‭CPU directly‬

‭●‬ ‭Appears in binary-like format, but it’s‬‭platform-independent‬

/‭/ High-level code‬


‭[Link]("Hello");‬

‭Compiled:‬

// Intermediate code (Bytecode)‬



0: getstatic‬

3: ldc‬

6: invokevirtual‬

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‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭11‬
‭JAVA FULL STACK‬

Steps in Java Program Execution:‬


1. Write Source Code‬


Code is written in a‬‭


‭ .java‬‭
file using a high-level‬
language.‬

public class Hello {‬


public static void main(String[] args) {‬


[Link]("Hello, World!");‬

}‬

}‬

2. Compile the Code‬


‭●‬ ‭
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!‬

Java Execution Flow:‬


Source Code (.java)‬


↓ javac‬

Bytecode (.class)‬

↓ JVM‬

Machine Code → Output‬


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:‬

A program is a set of instructions that performs a‬



caution task.‬

Syntax:‬

Rules & rugiutation to be followed when writing‬



program.‬

Basic Syntax:‬
‭ for writing a java program consists of‬‭
‭ two‬
part‬

❖‬‭Class‬

‭<Gunapati Suresh />‬
‭<JSpiders BTM Layout />‬
‭14‬
‭JAVA FULL STACK‬
❖‬‭Main Method‬

Class it’is most basic functionental unit of writing‬



java program‬

Main Method:‬

Enter point for execution inside a java program‬


Class ClassName{‬

Public static void main(String[] args){‬


[Link](“Welcom to java”);‬

}‬

}‬

➔‬‭If is a predefined statement syntax in java‬



‭●‬ ‭
The programer can make use of there statement to‬
display content on the output seres.‬

‭●‬ ‭
String type values can be enclassed in””.‬
‭●‬ ‭
Character values student be enclosed in ||.‬
‭●‬ ‭
Number are should be enclosed in drittiely.‬

Program:‬

class Program{‬

Public static void main(String[] args){‬


[Link](“Jspiders BTM”);‬

[Link](143);‬

[Link](3.45);‬

[Link](‘J’);‬

[Link](true);‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭15‬
‭JAVA FULL STACK‬
[Link](flase);‬

}‬

}‬

Output:‬

Jspiders BTM‬

143‬

3.45‬

J‬

true‬

False‬

❖‬‭Write a java program to display the following‬



details.‬

Class Suresh{‬

Public static void main(String[] args){‬


[Link](“[Link]”);‬

[Link](“2021-2025”);‬

[Link](‘7.2’);‬

[Link](‘M’);‬

[Link](true);‬

}‬

}‬

Practical Execution:-‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭16‬
‭JAVA FULL STACK‬
1.‬‭
‭ Open Notepad++.‬
‭●‬ ‭
Select Language‬
‭●‬ ‭
Type the program‬
2.‬‭
‭ Save the program.‬
➔‬‭
‭ File Name (classname)‬
➔‬‭
‭ File extension (.java)‬
➔‬‭
‭ Location‬

[Link] CMD.‬

➔‬‭
‭ Javac [Link]‬
➔‬‭
‭ Java classname‬

Java program Lifecycle:-‬


‭➔‬ ‭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.‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭17‬
‭JAVA FULL STACK‬
‭●‬ I‭f mistakes are not found it will generate “class” file with‬
‭Bycode.‬
‭●‬ ‭The bycode present in the”Class” file is executed by the‬
‭JVM with the help of it’s sub-system inside the JRE to‬
‭provide output.‬
‭●‬ ‭Programmer perform basic output analysis.‬

‭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‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭18‬
‭JAVA FULL STACK‬
‭Order of Execution:-‬
‭➔‬ ‭The default order of execution in the java program in tep to bottom and‬
‭left to right.‬

‭ 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.‬

‭Keywords (53 total):-‬

‭ 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‬

‭Additional reserved literals (sometimes counted separately, making53+)‬‭:‬

‭True, false, null‬

‭Note:-‬ ‭Goto and const keywords are not used directly‬‭in java programming.‬

‭ atatypes and variables:-‬


D
‭Datatypes and variables will help the programmer to store values inside java‬
‭program.‬

‭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.‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭20‬
‭JAVA FULL STACK‬
‭Primitive:-‬


‭ ‬ ‭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‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭21‬
‭JAVA FULL STACK‬
‭METHODS:-‬

‭Defination‬‭:-‬


‭ ‬A ‭ method is a named block of code that is reusable in nature.‬
‭➔‬ ‭Method are alos known as functions.‬

‭Syntax:-‬

‭For creating a method consists of tow ports.‬

‭ .‬ M
1 ‭ ethod Declaration‬
‭2.‬ ‭Method Defination‬

‭<access-modifier><modifier>retuntype methodname(<arguments>)‬

‭<> If’s not mandatory,It’s optional‬

‭{‬

‭➔‬ ‭Method Defination‬

‭}‬


‭ ‬ ‭ 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{‬

‭static void play()‬

‭{‬

‭[Link]("Executing Play().....");‬

‭}‬

‭public static void main(String[] args)‬

‭{‬

‭[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{‬

‭public static void main(String[] args)‬

‭{‬

‭[Link]("Program Starts");‬

‭help();‬

‭help();‬

‭help();‬

‭[Link]("Progerm End");‬

‭}‬

‭static void help()‬

‭{‬

‭[Link]("Exacution help().....");‬

‭}‬

‭}‬

‭OUTPUT:-‬

‭Program Starts‬

‭Exacution help().....‬

‭Exacution help().....‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭23‬
‭JAVA FULL STACK‬
‭Exacution help().....‬

‭Progerm End‬

‭Programs:3‬

‭class Demo3{‬

‭static void read()‬

‭{‬

‭[Link]("Executing read()....");‬

‭}‬

‭static void write()‬

‭{‬

‭[Link]("Executing write()....");‬

‭}‬

‭static void edit()‬

‭{‬

‭[Link]("Executing edit().....");‬

‭}‬

‭public static void main(String[] args)‬

‭{‬

‭write();‬

‭edit();‬

‭read();‬

‭}‬

‭}‬

‭OUTPUT:-‬

‭Executing write()....‬

‭Executing edit().....‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭24‬
‭JAVA FULL STACK‬
‭Executing read()....‬

‭Programs:4‬

‭class Demo4{‬

‭static void send()‬

‭{‬

‭int a=10;‬

‭[Link]("Value : "+a);‬

‭if (a%2==0){‬

‭[Link]("Even Number");‬

‭}‬

‭}‬

‭public static void main(String[] args)‬

‭{‬

‭send();‬

‭}‬

‭}‬

‭OUTPUT:-‬

‭Value : 10‬

‭Even Number‬

‭Programs:5‬

‭class Demo5{‬

‭static void send()‬

‭{‬

‭[Link]("Text Starts");‬

‭[Link]("Text End");‬

‭}‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭25‬
‭JAVA FULL STACK‬
‭static void disp()‬

‭{‬

‭[Link]("Disp Starts");‬

‭send();‬

‭[Link]("Disp Ends");‬

‭}‬

‭public static void main(String[] args)‬

‭{‬

‭[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‬

‭CALLING METHOD‬ ‭CALLED METHOD‬

‭Program:1‬

‭class Demo1{‬

‭static void test(double arg)‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭26‬
‭JAVA FULL STACK‬
‭{‬

‭[Link]("Value : "+arg);‬

‭}‬

‭public static void main(String[] args)‬

‭{‬

‭test(4.5);‬

‭test(6.7);‬

‭test(7.5);‬

‭}‬

‭}‬

‭OUTPUT:-‬

‭Value : 4.5‬

‭Value : 6.7‬

‭Value : 7.5‬

‭Program:2‬

‭class Demo2{‬

‭static void addition(int a,int b)‬

‭{‬

‭int sum=a+b;‬

‭[Link](a+" + "+b+" = "+sum);‬

‭}‬

‭public static void main(String[] args)‬

‭{‬

‭addition(12,13);‬

‭}‬

‭}‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭27‬
‭JAVA FULL STACK‬
‭OUTPUT:-‬‭12 + 13 = 25‬


‭ ‬ ‭ 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.‬

‭CALLING METHOD‬ ‭CALLED 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{‬

‭static int test()‬

‭{‬

‭return 10;‬

‭}‬

‭public static void main(String[] args)‬

‭{‬

‭int val=test();‬

‭[Link]("Returned value : "+val);‬

‭[Link]("Returned value : "+test());‬

‭}‬

‭}‬

‭OUTPUT:-‬

‭Returned value : 10‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭28‬
‭JAVA FULL STACK‬
‭Program:2‬

‭class Demo2{‬

‭static double play()‬

‭{‬

‭return 2.3;‬

‭}‬

‭public static void main(String[] args)‬

‭{‬

‭double d=play();‬

‭[Link]("Returned value : "+d);‬

‭[Link]("Returned value : "+play());‬

‭}‬

‭}‬

‭OUTPUT:-‬

‭Returned value : 2.3‬

‭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‬

‭2).‬ ‭public class Pattern4 {‬


‭static boolean verify(int arg) {‬
‭if (arg % 2 == 0) {‬
‭return true;‬
‭} else {‬
‭return false;‬
‭}‬
‭}‬

‭public static void main(String[] args) {‬


‭boolean val = verify(10);‬
‭[Link]("Return value : " + val);‬
‭[Link]("Return value : " + verify(15));‬
‭}‬
‭<Gunapati Suresh />‬
‭<JSpiders BTM Layout />‬
‭30‬
‭JAVA FULL STACK‬
‭}‬

‭ 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 need‬‭to 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.‬

‭public class Pattern4 {‬


‭static void play() {‬
‭[Link]("Executing play()...");‬
‭disp();‬
‭}‬
‭<Gunapati Suresh />‬
‭<JSpiders BTM Layout />‬
‭31‬
‭JAVA FULL STACK‬
‭static void disp() {‬
‭[Link]("Executing disp()....");‬
‭test(); // Call test instead of play to avoid recursion‬
‭}‬
‭static void test() {‬
‭[Link]("Executing test()....");‬
‭}‬
‭public static void main(String[] args) {‬
‭play(); // Start with play()‬
‭}‬
‭}‬
‭ utput:-‬
O
‭Executing play()...‬
‭Executing disp()....‬
‭Executing test()....‬


‭ ‬ ‭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.‬

‭public class Pattern5 {‬


‭static void display(int a) {‬
‭[Link](a);‬
‭if (a < 5) {‬ ‭// No semicolon here‬
‭a++;‬
‭display(a);‬ ‭// Recursion until a ==‬‭5‬
‭}‬
‭}‬
‭public static void main(String[] args) {‬
‭display(1); // Start from 1‬
‭}‬
‭}‬
‭Output:-‬
‭1‬
‭2‬
‭3‬
‭4‬
‭5‬

‭public class Pattern6 {‬


‭static void text() {‬
‭[Link]("Executing text()");‬
‭}‬
‭<Gunapati Suresh />‬
‭<JSpiders BTM Layout />‬
‭32‬
‭JAVA FULL STACK‬
‭static void disp(int a) {‬
‭[Link]("Executing disp() with value: " + a);‬
‭}‬
‭static int play() {‬
‭return 10;‬
‭}‬
‭static boolean help(int x) {‬‭// fixed spelling‬
‭return x > 0;‬‭// example condition‬
‭}‬
‭public static void main(String[] args) {‬
‭text();‬
‭disp(5);‬
‭[Link]("play() returned: " + play());‬
‭[Link]("help(3) returned: " + help(3));‬
‭}‬
}‭ ‬
‭Output:-‬
‭Executing text()‬
‭Executing disp() with value: 5‬
‭play() returned: 10‬
‭help(3) returned: true‬

‭Identifiers:-‬


‭ ‬‭Any name that is given by the programmer is called as identifiers.‬
‭➔‬‭As a programmer it’is our responsibility to provide.‬

‭Rules for identifiers:-‬‭name should always beige with‬‭alphabets.‬



‭ ‬‭Numbers can be used in identifiers but not as the first character.‬
‭➔‬‭“$” and”_” can be used bursitis not recomenuded.‬
‭➔‬‭Keyword connot be used by identifiers.‬
‭➔‬‭Identifiers cannot has blank space” “‬

‭Industry standend namming counuction:-‬

‭➔‬‭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:-‬

‭Scanner is predefined program pregent in the java program.‬


‭●‬ ‭The programmer can make use of scanner to ruled user input‬
‭Step used to scanner:-‬

‭ ‬‭Import scanner from java util package.‬
‭➔‬‭Create an object/Instance of scanner.‬
‭➔‬‭Read value by calling the method of scanner.‬

‭Data type‬ ‭Method‬


‭ yte‬
B ‭ ext Byte()‬
N
‭Short‬ ‭Next Short()‬
‭Int‬ ‭Next Int()‬
‭Long‬ ‭Next Long()‬
‭Float‬ ‭Next Float()‬
‭Double‬ ‭Next Double()‬
‭Char‬ ‭NA‬
‭Boolean‬ ‭Next Boolean‬
‭String‬ ‭Next () or Next time‬
‭Note:-‬‭There is not direct method or was to read chartype‬‭value.‬

‭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 homogenoas‬‭values.‬
‭ 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 by‬‭providing the‬
‭datatype and size of the array.‬
‭Syntax:-‬
‭Datatype[] variblename = new datatype [int arr];‬
‭Example:-‬
I‭nt[] 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

‭int[] arr = new int[7];‬

‭double[] value = new double[5];‬

c‭ har[] vowel = new char[6];‬


‭Char [] vowel = {‘a’,’e’,’i’,’o’,’u’};‬

‭ ouble[] value = new double[4];‬


D
‭Double[] value = {0.2,0.3,0.4,0.5};‬
‭●‬ ‭When ever we create an array dimension approach if will initially‬
‭contain default value.‬
‭Note:-‬‭Byte,short,long,int—--->0‬
‭float,double—--->00‬
‭char—------->100000‬
‭boolean—--->flase‬
‭other—------->null‬
‭Array Ength:-‬
‭➔‬‭Every array in java has pre defined property length called‬
‭length which can be used by the programmer to dilermine‬
‭size or capacity of an array.‬
‭1.‬ ‭Int[] arr=new int[5];‬
‭[Link]([Link]);---->5‬
‭2.‬ ‭Int[] iArr={14,10,15,17,16,18,19};‬
‭[Link]([Link]);---->7‬
‭3.‬ ‭Int[] dArr=new double[10];‬
‭[Link]([Link]);---->10‬
‭4.‬ ‭Char[] ch={‘j’,’a’,’v’,’a’};‬
‭[Link]([Link]);---->4‬
‭Note:-‬ ‭Array indexout of bond exception.‬
‭➔‬‭If the programmer try to acapt the walid exception if will case‬
‭AIooBE‬

‭class Array{‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭36‬
‭JAVA FULL STACK‬
‭public static void main(String[] args){‬
‭int[] arr= {13,12,17,14,15};‬
‭[Link]("Before Sorting");‬
‭for(int i=0;i<[Link];i++) {‬
‭[Link](arr[i]);‬
‭}‬
‭for(int i=0;i<[Link];i++)‬
‭{‬
‭for(int j=i+1;j<[Link];j++)‬
‭{‬
‭if(arr[i]>arr[j])‬
‭{‬
‭int t=arr[i];‬
‭arr[i]=arr[j];‬
‭arr[j]=t;‬
‭}‬
‭}‬
‭}‬
‭[Link]("After Sorting");‬
‭for(int i=0;i<[Link];i++) {‬
‭[Link](arr[i]);‬
‭}‬
‭}‬
‭}‬
‭Output:-‬
‭Before Sorting‬
‭13‬
‭12‬
‭17‬
‭14‬
‭15‬
‭After Sorting‬
‭12‬
‭13‬
‭14‬
‭15‬
‭17‬

‭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 —--------------->‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭38‬
‭JAVA FULL STACK‬
‭}‬ j‭[Link]‬ ‭[Link] java Deepika‬
‭ [Link]‬
H
‭Trick-2‬
‭➔‬ ‭It’is possible to create, save and compile a java program without main‬
‭[Link] ever we cannot execute without main method.‬
‭Trick-3‬
‭➔‬ ‭It’is possible to declare multiple class inside a single source fine.‬
‭➔‬ ‭In these scenario programmer responsibility to provide a meaningful file‬
‭name.‬
‭➔‬ ‭The compiler will generate as separate. Class file for each and erery class fill.‬

‭ 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.‬

‭STATIC AND NON-STATIC MEMBERS:-‬


‭➔‬‭Any variable or method which is declared directly in class body is‬
‭known as members.‬
‭Static members:-‬
‭➔‬‭Static members are declared with static keyword.‬
‭➔‬‭Static members can be access from out side class using class‬
‭name.‬

‭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]();‬
‭}‬
‭}‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭40‬
‭JAVA FULL STACK‬
‭ utput:-‬
O
‭100‬
‭8.9‬
‭Exeuting play().....‬
‭Exeuting disp().....‬

‭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 {‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭41‬
‭JAVA FULL STACK‬
i‭nt a = 50;‬
‭char b = 'J';‬
‭void disp() {‬
‭[Link]("Executing disp().....");‬
‭}‬
‭void help() {‬
‭[Link]("Executing help().....");‬
‭}‬
}‭ ‬
‭public class Mainclass2 {‬
‭public static void main(String[] args) {‬
‭Delta ex = new Delta(); // use Delta, not Example‬
‭[Link](ex.a);‬
‭[Link](ex.b);‬
‭[Link]();‬
‭[Link]();‬
‭}‬
‭}‬
‭Output:-‬
‭50‬
‭J‬
‭Executing disp().....‬
‭Executing help().....‬

‭ ).‬‭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()....‬

‭➔‬ ‭Can we access Non-static members using class name?‬


‭●‬ ‭No java syntax does not allow.‬
‭➔‬ ‭Can we access static members using object?‬
‭<Gunapati Suresh />‬
‭<JSpiders BTM Layout />‬
‭42‬
‭JAVA FULL STACK‬
‭ ‬ ‭Yes but it is not recommended as it leads to unnecessary dependency.‬

‭➔‬ ‭How to create and access static members?‬
‭●‬ ‭We can create with static keyword and access using class name.‬
‭➔‬ ‭How to create and access Non-static members?‬
‭●‬ ‭We can create directly without static keyword and access by creating object.‬
‭➔‬ ‭What are data members/member variables?‬
‭●‬ ‭Variables which are declared directly inside the class body are called as data‬
‭members/member variables.‬
‭●‬ ‭They can be declared with or without static keyword.‬
‭➔‬ ‭What are member function?‬
‭●‬ ‭Methods which are declared directly inside the class body are called as‬
‭member function.‬
‭●‬ ‭They can be declared with or without static keyword.‬
‭Class and object:-‬

‭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‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭43‬
‭JAVA FULL STACK‬
‭Suresh is writing the cgpa is 8.0‬

‭ ).‬‭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.‬

‭<Gunapati Suresh />‬


‭<JSpiders BTM Layout />‬
‭47‬

You might also like