Title: JAVA PROGRAMMING
1JAVA PROGRAMMING
2CONSTANT
Constant is input data for machine get to
calculate following our instructions
- Integer constant
- Real constant
- Boolean constant
- Character constant
- String constant
3Integer Constants
- Integer -(2311) to 231-1
- Decimal
- Oct
- Hex
- Long Integer -(2631) to 231-1
Example -897, 356, 0
Example 0700, 0356, 00
Example 0x89A, 0x356, 0x0
Example 50000000000L,23145l,-13L
4Integer Constants
//IntegerLiteral.java //Represent integer
Decimal, Octagonal and Hexagonal public class
IntegerLiteral public static void
main(String args) System.out.println(12)
//Show Decimal constant System.out.println(01
2) //Show Octagonal constant
System.out.println(0x12)//Show Hexagonal
constant
12 10 18
5Integer Constants
//LongConstant.java //Represent Normal Integer
and Long Integer Public class LongConstant
public static void main (String args)
System.out.println(12345678901234)
System.out.println(12345678901234L)
1942892530 12345678901234
6Real Constants
- Float -1.4 x 1045 and 3.4 x 1038
- Double -4.9 x 10-324 and 1.7 x 10308
Suffix F or f
Example 10.2F, 3.14f, 2.35E5F, -3.14e45F
Suffix D or d
Example 10.2D, -1.89d, 2.35E5D, -1.4e309D
7Boolean Constant
Note all character in word is small.
8Character Constants
- All character represent in Unicode 16 bits
- represent between single quote
- Represent special character
- Represent in unicode
a A z Z 0 9 ß
\t \b \n \f \r \ \ \\
9Escape sequence
//CtrlChar.java Public class CtrlChar public
static void main(String args)
System.out.println(backspace lt\bgt)
System.out.println(new line lt\ngt)
System.out.println(return lt\rgt)
System.out.println(formfeed lt\fgt)
System.out.println(tab lt\tgt)
System.out.println(backslash lt\\gt)
System.out.println(single quote lt\gt)
System.out.println(double quote lt\gt)
System.out.println(null lt\0gt)
10String Constants
- It is sequence of characters
- Represent between (double quote)
11Variables
12Identifiers
- Not allow
- Keywords
- Blank space
- Allow follow symbol
- Upper Case (A..Z)
- Lower Case (a..z)
- Number (0..9)
- Other symbol dollar-sign _underscore
13Keywords
abstract, boolean, break, byte, case, catch,
char, class, const, continue, default, do,
double, else, extends, false,final, finally,
float, for, goto, if, implements, import,
instanceof, int, interface, long, native, new,
null, package, private, protected, public,
return, short, static, super, switch,
synchronized, this, throw, throw, transient,
true, try, void, volatile, while
14Type variables
ltTypegt ltidentifiergtltvaluegt,ltidentifiergtltval
uegt
Example int x float a,b double half0.5
15Type wrapper classes
- Each primitive data type has a corresponding
class in package java.lang
public class IntegerConstants public static
void main(String args) System.out.println(
Byte.MAX_VALUE) System.out.println(Byte.MIN_V
ALUE) System.out.println(Short.MAX_VALUE)
System.out.println(Short.MIN_VALUE)
System.out.println(Integer.MAX_VALUE)
System.out.println(Integer.MIN_VALUE)
System.out.println(Long.MAX_VALUE)
System.out.println(Long.MIN_VALUE)
16Operators
- Assignment Operators
- Arithmatic Operators (IntegerFloat)
- Arithmatic Assignment Operators
- Increment and Decrement Operators
- Bitwise Operators
- Ralational Operators
- Logical Operators
17Arithmatic Operators (IntegerFloat)
18Arithmatic Assignment Operators
19Increment and Decrement Operators
- Increment Operator is
- Decrement Operator is
- x and x have different in meaning
int x 10 int y y x System.out.println(x)
System.out.println(y)
int x 10 int y y x System.out.println(x)
System.out.println(y)
11 11
11 10
20Overflow and Underflow
public class FloatRange public static void
main(String args) float pMax
Float.MAX_VALUE float pMin
Float.MIN_VALUE System.out.println(pMin
to pMax) System.out.println(Overflow
pMax10) System.out.println(Underflow
pMin/10)
21Bitwise Operators
22Ralational Operators
- Result is either true or false
23Logical Operators
int i 0 boolean b
24Condition Operator
Conditional Operator (ltconditiongt) ? ltexpression
1gt ltexpression 2gt
- If condition is true do expression 1
- If condition is false do expression 2
Example System.out.println(x0?01)
25Statement
- Simple Statement
- Assignment
- Condition Statement
- If
- Switch
- Loop Statement
- While
- for
26Assignment Statement
ltvariablegt ltexpressiongt
Example X ( a a 4.0 b ) / 2.0
27Condition Statement
if (ltboolean expressiongt) ltstatementsgt else
ltstatementsgt
If (ltexpressiongt) ltstatement1gt ltstatement2gt
If (ltexpressiongt) ltstatement1gt else
ltstatement2gt ltstatement3gt
28Condition Statement
Switch (ltinteger expressiongt) case ltvaluegt
ltstatementsgt case ltvaluegt ltstatementsgt .
. . . . . . . . . . . . . default
ltstatementsgt
29Loop Statement
while (ltboolean expressiongt) ltstatementsgt
public class LoopWhileFac public static void
main (String args) int n
Integer.parseInt(args0) int i 1, f 1
while (i lt n) f i
System.out.println(n!f)
30Loop Statement
do (lt statements gt) while lt boolean
expression gt
public class LoopDoFac public static void
main (String args) int n
Integer.parseInt(args0) int i 1, f 1
do f i while (i lt n)
System.out.println(n!f)
31Loop Statement
for (ltinitial expgtltcondition expgtltupdate expgt)
(lt statements gt)
public class LoopForFac public static void
main (String args) int n
Integer.parseInt(args0) int i 1, f 1
for (i 1 f 1 i lt n i) f
i System.out.println(n!f)