SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
BASICS
Variables
A variable is something which can hold some
value, or this is like a container for holding some
value; and off course this value is always subject
to change. The name of variable is always
preceded with the name of data type in JAVA.
For example
int speed=0;
Data type Name of variable
Value of variable
Type of variables in JAVA
The Java programming language defines the
following kinds of variables:
• Instance Variables (Non-Static Fields)
• Class Variables (Static Fields)
• Local Variables
• Parameters
Example(Type of Variables)
public class VariableDemo
{
int var1=0; //Each Instance of this class will have
//its own copy of this variable
static int var2=6; //Only one(common) copy of class variable will be
// available with all instances of this class
public void showArea(float r)
{
float pi=3.144f; // Local variable have local scope to that particular
// method or code of block(example for loop;)
System.out.println(“Area of circle is = ”+ pi*r*r);
}
}
Instance variable/Field/ object Variable
Class/static variable
Parameters
Local variable
Operators
Operators are special symbols that perform
specific operations on one, two, or
three operands, and then return a result
Operators Precedence
postfix expr++ expr--
unary ++expr --expr +expr -expr ~ !
multiplicative * / %
additive + -
shift << >> >>>
relational < > <= >= instanceof
equality == !=
bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ? :
assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
Expressions
An expression is a construct made up of
variables, operators, and method invocations,
which are constructed according to the syntax of
the language, that evaluates to a single value.
For example
int empId = 97312;
testArray[1] = 100;
System.out.println("Element 2at index 1: " +
testArray[0]);
Java programming language allows you to
construct compound expressions from various
smaller expressions
Like a*b*c;
However these can be ambiguous
Like a +b /100  Ambiguous, not
recommended
Or like (a+b)/100  Not Ambiguous,
recommended
Expressions must be balanced correctly using
parenthesis
Statements
Statements are roughly equivalent to sentences in
natural languages. A statement forms a complete
unit of execution. The following types of
expressions can be made into a statement by
terminating the expression with a semicolon (;).
• Assignment expressions // speed=107;
• Any use of ++ or -- //a++;
• Method invocations //c= obj.add(15,17);
• Object creation expressions //Cal obj=new Cal();
Blocks
if (condition) { // begin block 1
System.out.println("Condition is true.");
} // end block one
Control Flow Statements
The statements inside your source files are generally
executed from top to bottom, in the order that they
appear. Control flow statements, however, break up the
flow of execution by employing decision making, looping,
and branching, enabling our program
to conditionally execute particular blocks of code.
1. decision-making statements (if-then, if-then-
else, switch),
2. looping statements (for, while, do-while), 3.
3. branching statements (break, continue, return)
supported by the Java programming language.
if
• if(condition)statement;
• The condition is Boolean expression, its
outcome can be only true or false
• Relational operators like <,>,== can be used to
create condition
If-else
if (condition)
{
//do something here
} else
{
//do something else here
}
The switch Statement
Unlike if-then and if-then-else statements,
the switch statement can have a number of
possible execution paths. A switch works with
the byte, short, char, and int primitive data
types. It also works with enumerated types ,
the String class, and a few special classes that
wrap certain primitive
types: Character, Byte, Short, and Integer
Switch example
public class SwitchDemo {
public static void main(String[] args) {
int day = 3;
String day;
switch (month) {
case 1: day= “monday";
break;
case 2: day = “tuesday";
break;
case 3: day = “wednesday";
break;
case 4: day = “thrusday";
break;
case 5: day = “friday";
break;
default: day = “holiday";
break;
}
System.out.println(day);
}
}
For more tutorials on Java visit
programminghunk

More Related Content

What's hot (20)

PPS
Wrapper class
kamal kotecha
 
PPS
Introduction to class in java
kamal kotecha
 
PPTX
Chapter 05 classes and objects
Praveen M Jigajinni
 
PPTX
Applets in java
Wani Zahoor
 
PPTX
Data types in java
HarshitaAshwani
 
PPT
Scanner class
M Vishnuvardhan Reddy
 
PDF
Java variable types
Soba Arjun
 
PPTX
Python Tutorial Part 1
Haitham El-Ghareeb
 
PPTX
Operators in java
AbhishekMondal42
 
PPT
9. Input Output in java
Nilesh Dalvi
 
PPTX
Methods in java
chauhankapil
 
PPTX
Inheritance in java
RahulAnanda1
 
PDF
Arrays in Java
Naz Abdalla
 
PDF
Methods in Java
Jussi Pohjolainen
 
PDF
Java data types, variables and jvm
Madishetty Prathibha
 
PPTX
Tokens in C++
Mahender Boda
 
PPTX
Java Tokens
Madishetty Prathibha
 
PPTX
This keyword in java
Hitesh Kumar
 
PPTX
Python-Inheritance.pptx
Karudaiyar Ganapathy
 
PDF
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
Wrapper class
kamal kotecha
 
Introduction to class in java
kamal kotecha
 
Chapter 05 classes and objects
Praveen M Jigajinni
 
Applets in java
Wani Zahoor
 
Data types in java
HarshitaAshwani
 
Scanner class
M Vishnuvardhan Reddy
 
Java variable types
Soba Arjun
 
Python Tutorial Part 1
Haitham El-Ghareeb
 
Operators in java
AbhishekMondal42
 
9. Input Output in java
Nilesh Dalvi
 
Methods in java
chauhankapil
 
Inheritance in java
RahulAnanda1
 
Arrays in Java
Naz Abdalla
 
Methods in Java
Jussi Pohjolainen
 
Java data types, variables and jvm
Madishetty Prathibha
 
Tokens in C++
Mahender Boda
 
This keyword in java
Hitesh Kumar
 
Python-Inheritance.pptx
Karudaiyar Ganapathy
 
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 

Similar to Java basics and java variables (20)

PPTX
Introduction to Java
Ashita Agrawal
 
PPTX
UNIT 2 programming in java_operators.pptx
jijinamt
 
PDF
Java input Scanner
Huda Alameen
 
PPTX
3. Java Installations ppt for engineering
vyshukodumuri
 
PDF
java notes.pdf
RajkumarHarishchandr1
 
PPTX
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
DevaKumari Vijay
 
PPT
slides03.ppt
Anjali127411
 
PPTX
130706266060138191
Tanzeel Ahmad
 
PDF
9-java language basics part3
Amr Elghadban (AmrAngry)
 
PPT
Chapter 4 flow control structures and arrays
sshhzap
 
PDF
data types.pdf
HarshithaGowda914171
 
PPTX
controlStatement.pptx, CONTROL STATEMENTS IN JAVA
DrNeetuSharma5
 
PPT
Chapter 2&3 (java fundamentals and Control Structures).ppt
henokmetaferia1
 
PPTX
UNIT – 2 Features of java- (Shilpa R).pptx
shilpar780389
 
PPTX
Control structures
Gehad Enayat
 
PPT
Control statements
CutyChhaya
 
DOCX
Materials for teachers and students java-en
Georgeta Manafu
 
PPTX
Learn To Code: Introduction to java
SadhanaParameswaran
 
PPTX
JAVA programming language made easy.pptx
Sunila31
 
PDF
Java Review
pdgeorge
 
Introduction to Java
Ashita Agrawal
 
UNIT 2 programming in java_operators.pptx
jijinamt
 
Java input Scanner
Huda Alameen
 
3. Java Installations ppt for engineering
vyshukodumuri
 
java notes.pdf
RajkumarHarishchandr1
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
DevaKumari Vijay
 
slides03.ppt
Anjali127411
 
130706266060138191
Tanzeel Ahmad
 
9-java language basics part3
Amr Elghadban (AmrAngry)
 
Chapter 4 flow control structures and arrays
sshhzap
 
data types.pdf
HarshithaGowda914171
 
controlStatement.pptx, CONTROL STATEMENTS IN JAVA
DrNeetuSharma5
 
Chapter 2&3 (java fundamentals and Control Structures).ppt
henokmetaferia1
 
UNIT – 2 Features of java- (Shilpa R).pptx
shilpar780389
 
Control structures
Gehad Enayat
 
Control statements
CutyChhaya
 
Materials for teachers and students java-en
Georgeta Manafu
 
Learn To Code: Introduction to java
SadhanaParameswaran
 
JAVA programming language made easy.pptx
Sunila31
 
Java Review
pdgeorge
 
Ad

Recently uploaded (20)

PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
Geographical diversity of India short notes by sandeep swamy
Sandeep Swamy
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Geographical diversity of India short notes by sandeep swamy
Sandeep Swamy
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Ad

Java basics and java variables

  • 2. Variables A variable is something which can hold some value, or this is like a container for holding some value; and off course this value is always subject to change. The name of variable is always preceded with the name of data type in JAVA. For example int speed=0; Data type Name of variable Value of variable
  • 3. Type of variables in JAVA The Java programming language defines the following kinds of variables: • Instance Variables (Non-Static Fields) • Class Variables (Static Fields) • Local Variables • Parameters
  • 4. Example(Type of Variables) public class VariableDemo { int var1=0; //Each Instance of this class will have //its own copy of this variable static int var2=6; //Only one(common) copy of class variable will be // available with all instances of this class public void showArea(float r) { float pi=3.144f; // Local variable have local scope to that particular // method or code of block(example for loop;) System.out.println(“Area of circle is = ”+ pi*r*r); } } Instance variable/Field/ object Variable Class/static variable Parameters Local variable
  • 5. Operators Operators are special symbols that perform specific operations on one, two, or three operands, and then return a result
  • 6. Operators Precedence postfix expr++ expr-- unary ++expr --expr +expr -expr ~ ! multiplicative * / % additive + - shift << >> >>> relational < > <= >= instanceof equality == != bitwise AND & bitwise exclusive OR ^ bitwise inclusive OR | logical AND && logical OR || ternary ? : assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
  • 7. Expressions An expression is a construct made up of variables, operators, and method invocations, which are constructed according to the syntax of the language, that evaluates to a single value. For example int empId = 97312; testArray[1] = 100; System.out.println("Element 2at index 1: " + testArray[0]);
  • 8. Java programming language allows you to construct compound expressions from various smaller expressions Like a*b*c; However these can be ambiguous Like a +b /100  Ambiguous, not recommended Or like (a+b)/100  Not Ambiguous, recommended Expressions must be balanced correctly using parenthesis
  • 9. Statements Statements are roughly equivalent to sentences in natural languages. A statement forms a complete unit of execution. The following types of expressions can be made into a statement by terminating the expression with a semicolon (;). • Assignment expressions // speed=107; • Any use of ++ or -- //a++; • Method invocations //c= obj.add(15,17); • Object creation expressions //Cal obj=new Cal();
  • 10. Blocks if (condition) { // begin block 1 System.out.println("Condition is true."); } // end block one
  • 11. Control Flow Statements The statements inside your source files are generally executed from top to bottom, in the order that they appear. Control flow statements, however, break up the flow of execution by employing decision making, looping, and branching, enabling our program to conditionally execute particular blocks of code. 1. decision-making statements (if-then, if-then- else, switch), 2. looping statements (for, while, do-while), 3. 3. branching statements (break, continue, return) supported by the Java programming language.
  • 12. if • if(condition)statement; • The condition is Boolean expression, its outcome can be only true or false • Relational operators like <,>,== can be used to create condition
  • 13. If-else if (condition) { //do something here } else { //do something else here }
  • 14. The switch Statement Unlike if-then and if-then-else statements, the switch statement can have a number of possible execution paths. A switch works with the byte, short, char, and int primitive data types. It also works with enumerated types , the String class, and a few special classes that wrap certain primitive types: Character, Byte, Short, and Integer
  • 15. Switch example public class SwitchDemo { public static void main(String[] args) { int day = 3; String day; switch (month) { case 1: day= “monday"; break; case 2: day = “tuesday"; break; case 3: day = “wednesday"; break; case 4: day = “thrusday"; break; case 5: day = “friday"; break; default: day = “holiday"; break; } System.out.println(day); } }
  • 16. For more tutorials on Java visit programminghunk