Lecture1pptx__2024_08_28_22_02_41
Lecture1pptx__2024_08_28_22_02_41
Introduction to Java
Keywords
Constants
Variables
Data Types
Operators & Expressions
Control Constructs
Introduction to Java
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java Is Multithreaded
Characteristics of Java
Java is inherently object-oriented.
Java Is Simple
Although many object-oriented
Java Is Object-Oriented languages began strictly as procedural
Java Is Distributed languages, Java was designed from the
start to be object-oriented. Object-
Java Is Interpreted oriented programming (OOP) is a
Java Is Robust popular programming approach that is
replacing traditional procedural
Java Is Secure
programming techniques.
Java Is Architecture-Neutral One of the central issues in software
Java Is Portable development is how to reuse code.
Object-oriented programming provides
Java Is Multithreaded great flexibility, modularity, clarity, and
reusability through encapsulation,
inheritance, and polymorphism.
Characteristics of Java
Java Is Simple Distributed computing
Java Is Object-Oriented involves several computers
Java Is Distributed
working together on a network.
Java is designed to make
Java Is Interpreted
distributed computing easy.
Java Is Robust Since networking capability is
Java Is Secure inherently integrated into Java,
Java Is Architecture-Neutral writing network programs is
Java Is Portable like sending and receiving data
Java Is Multithreaded to and from a file.
Characteristics of Java
You need an interpreter to run
Java Is Simple
Java programs. The programs
Java Is Object-Oriented are compiled into the Java
Java Is Distributed Virtual Machine code called
Java Is Interpreted bytecode. The bytecode is
Java Is Robust machine-independent and can
Java Is Secure run on any machine that has a
Java interpreter, which is part
Java Is Architecture-Neutral
of the Java Virtual Machine
Java Is Portable (JVM).
Java Is Multithreaded
Characteristics of Java
Java Is Simple Java compilers can detect many
Java Is Object-Oriented problems that would first show
Java Is Distributed up at execution time in other
Java Is Interpreted languages.
Java has eliminated certain
Java Is Robust
types of error-prone
Java Is Secure
programming constructs found
Java Is Architecture-Neutral in other languages.
Java Is Portable
Java Is Multithreaded
Characteristics of Java
Java Is Simple
Java implements several
Java Is Object-Oriented security mechanisms to
Java Is Distributed protect your system against
Java Is Interpreted harm caused by stray
Java Is Robust programs.
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java Is Multithreaded
Characteristics of Java
Java Is Simple Write once, run anywhere
Java Is Object-Oriented
Java Is Distributed With a Java Virtual Machine
Java Is Interpreted (JVM), you can write one
program that will run on any
Java Is Robust
platform.
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java Is Multithreaded
Characteristics of Java
Java Is Simple Because Java is architecture
Java Is Object-Oriented neutral, Java programs are
Java Is Distributed portable. They can be run
Java Is Interpreted on any platform without
being recompiled.
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java Is Multithreaded
Characteristics of Java
Java Is Simple Multithread programming is
Java Is Object-Oriented smoothly integrated in Java,
Java Is Distributed whereas in other languages you
have to call procedures specific
Java Is Interpreted
to the operating system to
Java Is Robust enable multithreading.
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java Is Multithreaded
Introduction to Java
Java is a object-oriented programming language.
We can develop two types of Java Programs:
1. Stand-alone applications
2. Web Applets
Stand-alone applications are the programs
written in Java to carry out certain tasks on a
stand-alone local computer. Executing a stand-
alone Java program involves two steps.
3. Compiling source code into bytecode using javac
compiler
4. Executing the bytecode program using java
interpreter
Introduction to Java
Applets are small Java programs developed
for Internet applications. An applet located on
a distant computer can be downloaded via
Internet and executed on a local computer
using Java capable browser.
Stand-alone programs can read and write
files and perform certain operations that
applets cannot do. An applet can only run
within a Web browser.
Two ways of using Java
Java
Sourc
e
Code
Java
Compiler
Applet Application Type
JavaType Java
Enabled Interpret
Web er
Browser
Output Output
Simple Java Program
Class SampleOne
{
Public Static Void Main(String args[])
{
System.Out.Println(“Java is better than C+
+”);
}
}
static
the main method belongs to the SampleOne class,
and not a part of any objects of the class
Java Program Structure
Documentation Section Suggested
/**
* These are used by the javadoc utility to create HTML
* documentation files automatically.
*/
Constants
Constants
Constants in Java refer to fixed values that do
not change during the execution of a
program.
Java Constants
Numeric Character
Constants Constants
Primitive Non-Primitive
(Intrinsic) (Derived)
Numeri Non-
Classes Arrays
c Numeric
Interfac
e
Floating Charact
Integer Boolean
-Point er
Operators
Operators
Operators are used in programs to manipulate data
and variables. Java operators can be classified into a
number of related categories as below:
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Increment and Decrement Operators
6. Conditional Operators
7. Bitwise Operators
8. Special Operators
Arithmetic Expressions
An Arithmetic Expression is a combination of
variables, constants, and operators arranged
as per the syntax of the language.
Expressions are evaluated using an
assignment statement of the form:
variable = expression
variable is any valid Java variable name.
Control Constructs
Control Constructs
SELECTION STATEMENT
ITERATION STATEMENT
JUMP STATEMENT
Selection Statement:
It allow to choose the set-of-instructions for
execution depending upon an expression’s truth
value.
Two types :
1. if statement
2. switch statement
Control Constructs
IF Statement:
It tests a particular condition.
Syntax
if(condition checking expression)
{
Statement for true condition;
}
If –else-If statement:
1. It used to tests condition at multiple level.
2. Syntax:
Control Constructs
if(condition expression) Level1
{
statement for true condition;
}
else if(condition expression) Level2
{
statement for true condition of else-if ;
}
else if(condition expression) Level3
{
statement for true condition of else-if ;
}
else
{
statement for false condition of all if;
}
Control Constructs
Nested If Statement:
A nested if is an if that has another if in its if’s body or else’s
body or both.
Syntax:
if(condition expression)
{
if(expression){
Statement1;}
else{ statement2;}
}
else{
if(expression){
Statement1;}
else{ statement2;}
Iteration/Loop Statement
Loop: used for repetition of same task.
Loop consists of three part:
1. Initialization exp: used to began loop , it
executed only once.
2. Test/Condition exp: its truth value decides
whether the loop body will be executed or not.
3. Update exp: It change the value of loop
variable. It executed at the end of loop after the
loop-body is executed.
4. The Body-of -the-loop: contains statement of
loop
Types of Loop
for – Loop
while- Loop
do-while – Loop
For- Loop: It initialize first, then test the condition,
then execute statement from body of loop , and then
execute update expression.
Syntax:
for(Initialization exp; Test exp; Update exp)
{
Body of loop
Statements
}
Nested-for-Loop
Syntax:
for(Initialization exp; Test exp; Update exp)
{
Body of outer for loop
for(Initialization exp; Test exp; Update exp)
{
Body of inner for loop
Statements
}
}
While Loop
It tests the condition , then execute the statement
, and then execute update expression.
Syntax:
while(test exp)
{
Statements
Body of loop
Update expression
}
Do-while Loop
It executes the statements then executes
update expression, and then test the
condition. It executes statements for one time
false condition.
Syntax:
do{
Statements
Body of Loop
Update expression
}while(test expression);
Jump Statement
Jump statements unconditionally transfer
program control within a function. Java has
three Jump statement:
return
break
continue