0% found this document useful (0 votes)
20 views42 pages

Java

Uploaded by

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

Java

Uploaded by

saranyansmem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

WELCOME

JAVA
INTRODUCTION
• What is programming ?

• Java – high level programming language.

• USES :

1. Used to build variety of applications

2. Platform independent – device(JVM)

3. OOPS

4. Simple, Robust, secure , portable, multi threading, write once


run anywhere
• JDK – JAVA DEVELOPMENT KIT – collection of tools and libraries
1. JVM – JAVA VIRTUAL MACHINE

2. JRE - JAVA RUNTIME ENVIRONMENT

• OOP – Object Oriented Programming – uses objects to design applications and


software programs.

• The four main concepts of Object-Oriented programming are:


Abstraction,Encapsulation,Inheritance,Polymorphism

• Objects –data structures with data fields and methods

• Oops- Complex program to simple one

• JAVA LIBRARIES – build application more quickly and easily


// your First program
1. // Your First Program - // is a comment. Ease understanding of user.

2. Class Helloworld { ---- } - all program should has class definition. Name of the class
should match the filename in java.

3. Public static void main (String[] args) {….}

- main method. Compiler execute from main method. It is mandatory.

4. System.out.println(“Hello, World”) – used to print the statement.


JAVA
JAVA
JVM JRE JDK
(JAVA VIRTUAL MACHINE) (JAVA RUNTIME (JAVA DEVELOPMENT KIT)
ENVIRONMENT)
 Converts Java bytecode into  is a software package that provides  Complete toolkit for Java
machine code an environment in which Java programmers. special translator
 The main tasks are : programs can run. Java code into something the
 communicates between the Java computer can understand.
Loads code
program and the operating system.
Verifies code makes Java programs platform-
Executes code independent, they can run on Windows,
JRE is like a kitchen that has everything
Mac, or any other system with a JVM.
Provides runtime environment needed to cook and serve food (Java
 It also has debuggers to fix errors and
programs)
other tools to help build great Java
programs.
JAVA

Variable - named Data can be stored and


It allow us to store data,
retrieve it, and perform
storage location in a manipulated operations on it throughout the
computer's memory execution of a program.

Example : Toy box holding toys.


Hold different types of variables such as numbers, text or Boolean values
We can change the value of a variable
CHARACTERICTICS OF
VARIABLES
Modification:
Variables in Java can be
Name:
Each variable – name ; Serves as identifier. changed (modified) after they
Rules: are created.
start with a letter or underscore, cannot
contain spaces, etc.. You can update the information
stored in the variable during
your program's execution.

Data Type: Memory Location:


Determines what kind of data Variables are associated with
they can store (e.g., integer, specific memory locations in the
floating-point number, string, computer's RAM (Random Access
Memory).
etc.). This allows programs to access and
This ensures that the variable is modify the stored data during
used correctly and efficiently. execution.
CHARACTERICTICS OF
VARIABLES
RULES FOR VARIABLE
DECLARATION
•Data Type: Every variable needs a data type
(e.g., int, double, String)
•Meaningful Name: Descriptive name that reflects the variable's purpose
(e.g., age, fullName, isActive).
•Valid Characters: Names can use letters (uppercase/lowercase), numbers (0-9), and
underscore (_). The first character cannot be a number.
•No Keywords: Avoid reserved keywords (like int, if, for) as variable names.
•Case-Sensitive: age and Age are different variables.
•Scope: Where you declare a variable determines its accessibility (local to a method or
throughout the class).
•Optional Initialization: You can declare a variable without an initial value, or assign a value
during declaration.
JAVA LITERALS
 Literals are used to represent fixed values.

 They can be used directly in the code.


INTEGER LITERALS
Integer Literals
• Binary : It is2)a numeric value without any fractional or exponential part.
(base
• Decimal (base 10)
• Octal (base 8)
• Hexadecimal (base 16)
4 types:

EXAMPLES :

int decimal = 123; // decimal literal

int octal = 0123; // octal literal (83 in decimal)

int hex = 0xABCD; // hexadecimal literal (43981 in decimal)

int binary = 0b101010; // binary literal (42 in decimal)


LITERALS
 Represent numbers with fractional parts or exponents.
 Specified in decimal or hexadecimal formats
 Keyword Float
CHARACTER LITERALS

• KEYWORD : CHAR Ex :
char ch = ‘A’;
STRING LITERALS

• KEYWORD : String
Ex : String s = “Apple”;
BOOLEAN LITERALS

Boolean literals represent the two possible values of the boolean


type: true and false.

• KEYWORD : String
Ex : String s = “Apple”;
BOOLEAN LITERALS
DATA TYPES :
Boolean literals
• Data types define represent the twothat
the kind of information possible values
can be stored in aof the boolean
variable.
type: true and false.
• They act like little boxes with labels, where each box can only hold a specific type of

item.

1. •Primitive
KEYWORDdatatype:
String
Ex : String s = “Apple”;
2. Non- Primitive datatype
BOOLEAN LITERALS
Primitive Data Types: These are basic building blocks provided by Java

Boolean
itself. literals represent the two possible values of the boolean
type:
They true
storeand false.
simple values like numbers, characters, or true/false. (e.g., int,
double, char, boolean)

• KEYWORD
•Non-Primitive : String
Data Types: These are more complex data structures
Exprogrammers.
created by : String s = “Apple”;
They allow you to organize larger amounts of data or create custom
objects. (e.g., String, Array, Class)
BOOLEAN LITERALS

Boolean literals represent the two possible values of the boolean


type: true and false.

• KEYWORD : String
Ex : String s = “Apple”;
BOOLEAN LITERALS

Boolean literals represent the two possible values of the boolean


type: true and false.

• KEYWORD : String
Ex : String s = “Apple”;
BOOLEAN LITERALS

Boolean literals represent


OPERATORS : the two possible values of the boolean
type: true and false.
Operators in Java are the symbols used for performing specific

operations in Java.

OperatorsKEYWORD
make tasks: like
String
addition, multiplication, etc which look
Ex : String s = “Apple”;
easy although the implementation of these tasks is quite complex.
BOOLEAN LITERALS

Boolean literals represent the two possible values of the boolean


type: true and false.

• KEYWORD : String
Ex : String s = “Apple”;
BOOLEAN LITERALS

Boolean literals represent the two possible values of the boolean


type: true and false.

• KEYWORD : String
Ex : String s = “Apple”;
BOOLEAN
ASSIGNMENT LITERALS
OPERATORS

Boolean literals represent the two possible values of the boolean


type: true and false.

• KEYWORD : String
Ex : String s = “Apple”;
BOOLEAN LITERALS

Boolean literals represent the two possible values of the boolean


type: true and false.

• KEYWORD : String
Ex : String s = “Apple”;
BOOLEAN LITERALS

Check for relations between two operands, including equality,


Boolean
greaterliterals represent
than, less the two possible values of the boolean
than, etc.
type:
Theytrue anda false.
return boolean result after the comparison

• KEYWORD : String
Ex : String s = “Apple”;
BOOLEAN LITERALS

Boolean literals represent the two possible values of the boolean


type: true and false.

• KEYWORD : String
Ex : String s = “Apple”;
BOOLEAN LITERALS
Logical operators are used to perform logical “AND”, “OR” and “NOT”
operations
Boolean literals represent the two possible values of the boolean
AND Operator ( && ) – if( a && b ) [if true execute else don’t]
type: true and false.
OR Operator ( || ) – if( a || b) [if one of them is true to execute else don’t]
NOT Operator ( ! ) – !(a<b) [returns false if a is smaller than b]

• KEYWORD : String
Ex : String s = “Apple”;
BOOLEAN LITERALS
UNARY OPERATOR
Unary operators are the types that need only one operand to perform any
Boolean literals represent the
operation like increment, decrement
two possible values of the boolean
type: true and false.

• KEYWORD : String
Ex : String s = “Apple”;
BOOLEAN LITERALS
Bitwise operators are used to performing the manipulation of individual
bits of a number
Boolean literals represent the two possible values of the boolean
type: true and false.

• KEYWORD : String
Ex : String s = “Apple”;
BOOLEAN LITERALS
CONDITION STATEMENTS
Conditional statements in Java are like the decision-makers of your
Boolean
programliterals represent the two possible values of the boolean
type: true and
In simpler false.
terms: “If this happens, do that. Otherwise, do
something else.”

•if statement: Executes a block if the condition is true.


• KEYWORD : String
•if-else statement: Executes one block if true, another if false.
Ex : String s = “Apple”;
•else if ladder: Tests multiple conditions sequentially.
•switch statement: Selects code to run based on a specific value.
BOOLEAN LITERALS

Boolean literals represent the two possible values of the boolean


type: true and false.

• KEYWORD : String
Ex : String s = “Apple”;
BOOLEAN LITERALS
SIMPLE IF
public class PassFail
Boolean literals represent the two possible values of the boolean
{ true and false.
type:
public static void main(String[] args) {
int marks = 75;
• KEYWORD
if (marks >= 50) : String
Ex : String s = “Apple”;
{ System.out.println("You have passed the exam!");
}
}}
BOOLEAN LITERALS
IF - ELSE
public class EvenOddChecker {
Boolean
publicliterals represent
static void the
main(String[] two
args) { possible values of the boolean
type: int
true and=false.
number 7;
if (number % 2 == 0)
{

• KEYWORD : String
System.out.println(number + " is even.");
} elseEx : String s = “Apple”;+ " is odd.");
{ System.out.println(number
}
}
}
IF – ELSE IF
BOOLEAN LITERALS
public class WeatherChecker {
public static void main(String[] args)
Boolean
{ literals represent the two possible values of the boolean
type:inttrue and false.
temperature = 25;
if (temperature < 20)
{ System.out.println("It's cold outside!");
} • KEYWORD : String
else ifEx : String s>==20“Apple”;
(temperature && temperature < 30)
{
System.out.println("It's pleasant weather."); }
else { System.out.println("It's hot outside!");
BOOLEAN
NESTED CONDITIONALS LITERALS
Decisions Within Decisions
public class Main {
public static void main(String[] args) {
int age = 12;
Boolean literals
int graderepresent
= 6; the two possible values of the boolean
type: trueifand
(age >false.
10) {
if (grade > 5) {
System.out.println("You are eligible for the school activity!");
}
else {
System.out.println("You
• KEYWORD : need to be in grade 6 or higher.");
String
}}
Exelse: String
{ s = “Apple”;
System.out.println("You need to be older than 10.");
}}}
BOOLEAN
SWITCH STATEMENT LITERALS
It allows you to choose between multiple options based on the value of a variable.

Boolean
Asking literals
a questionrepresent
with several the twoanswers,
possible possible values ofonthe
and depending the boolean
answer, you
do different things.
type: true and false.
•switch: This starts the switch statement and takes a variable to compare.

•case: Each case checks if the variable matches a specific value.


• KEYWORD
•break: : String
This ends a case. Without it, the program will continue to the next case.
Ex : String s = “Apple”;
•default: This runs if none of the cases match.
public class Main {
BOOLEAN LITERALS
public static void main(String[] args) {
int day = 3; // Let's say 1 = Monday, 2 = Tuesday, ..., 7 =
Sunday switch (day)
{
case 1:
Boolean literals
System.out.println("It's
break;
represent
Monday!"); the two possible values of the boolean
type:
casetrue
2: and false.
System.out.println("It's Tuesday!");
break;
case 3:
System.out.println("It's Wednesday!");
break;
case 4:
• KEYWORD : String
Ex : StringThursday!");
System.out.println("It's s = “Apple”;
break;
case 5:
System.out.println("It's Friday!");
break;
case 6: System.out.println("It's Saturday!"); break; case
7: System.out.println("It's Sunday!"); break; default:

You might also like