Академический Документы
Профессиональный Документы
Культура Документы
Operators
&DataTypes
in Java
Java Programs
Example Program
public class MyProg
/* @param args */
main(String[] args)
{ System.out.println("Th
is
with ;
End of class
}
}
Comments
Memory
8 bits = 1byte
Larger measures
kilobyte (KB):
megabyte (MB):
1MB = 210 KB
gigabyte (GB):
1GB = 210 MB
Definitions
Variables
Identifiers
Each word in a
computer program is
an identifier -> 3
/* @param args */
categories:
1) Identifiers that we choose:
Demo,
args
out,
class,
static, void
args)
{
System.out.println("This
is Demo program");
}
}
Naming Identifiers/Variable
Declaration
Data Types
Variable Declaration
Have to declare all variables before using them!
int number;
1) new variable of type int
2) having the name
number
Arithmetic Expressions
Examples
int answer
Division
point
- If both
integer
Example:
= 10 4;
is different,
depending
are integers
division
int answer
(byte,
= 5/2;
on integer/floating
short,
int,
long)=>
(remainders/fractions are
dropped:answer will be 2)
- If one or both
division
Example: double
are floating
answer
point
= 5/2.0;
=> floating
point
Remainder
Example:
operator
(mod
int answer
operation):
= 10%3;
returns
(answer
will
remainder
be 1)
More Examples
1) X=4;
X++;
2) a==b
(checks if a is equal to b)
3) a!=b
(checks if a not equal to b)
4) (a== &&(c==d) (checks if a = b and if c=d)
b)
(what if a=2, b=2, c=3, d=4 ?)
5) (a==b) || (c==d) (checks if a = b or if c=d)
(what if a=2, b=2, c=3, d=4 ?)
6) if(!a)
(checks if a==0)