JAVA PROGRAMMING - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

JAVA PROGRAMMING

Description:

Constant is input data for machine get to calculate following our instructions ... Arithmatic Operators (Integer&Float) Arithmatic Assignment Operators ... – PowerPoint PPT presentation

Number of Views:93
Avg rating:3.0/5.0
Slides: 32
Provided by: kratcha
Category:

less

Transcript and Presenter's Notes

Title: JAVA PROGRAMMING


1
JAVA PROGRAMMING
  • PART II

2
CONSTANT
Constant is input data for machine get to
calculate following our instructions
  • Integer constant
  • Real constant
  • Boolean constant
  • Character constant
  • String constant

3
Integer 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
4
Integer 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
5
Integer 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
6
Real 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
7
Boolean Constant
  • 2 value
  • true
  • false

Note all character in word is small.
8
Character 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 \ \ \\
9
Escape 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)
10
String Constants
  • It is sequence of characters
  • Represent between (double quote)

11
Variables
12
Identifiers
  • Not allow
  • Keywords
  • Blank space
  • Allow follow symbol
  • Upper Case (A..Z)
  • Lower Case (a..z)
  • Number (0..9)
  • Other symbol dollar-sign _underscore

13
Keywords
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
14
Type variables
  • Declaration form

ltTypegt ltidentifiergtltvaluegt,ltidentifiergtltval
uegt
Example int x float a,b double half0.5
15
Type 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)
16
Operators
  • Assignment Operators
  • Arithmatic Operators (IntegerFloat)
  • Arithmatic Assignment Operators
  • Increment and Decrement Operators
  • Bitwise Operators
  • Ralational Operators
  • Logical Operators

17
Arithmatic Operators (IntegerFloat)
18
Arithmatic Assignment Operators
19
Increment 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
20
Overflow 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)
21
Bitwise Operators
22
Ralational Operators
  • Result is either true or false

23
Logical Operators
int i 0 boolean b
24
Condition 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)
25
Statement
  • Simple Statement
  • Assignment
  • Condition Statement
  • If
  • Switch
  • Loop Statement
  • While
  • for

26
Assignment Statement
  • Assignment expression

ltvariablegt ltexpressiongt
Example X ( a a 4.0 b ) / 2.0
27
Condition Statement
  • If Statement formula

if (ltboolean expressiongt) ltstatementsgt else
ltstatementsgt
If (ltexpressiongt) ltstatement1gt ltstatement2gt
If (ltexpressiongt) ltstatement1gt else
ltstatement2gt ltstatement3gt
28
Condition Statement
  • Switch Statement formula

Switch (ltinteger expressiongt) case ltvaluegt
ltstatementsgt case ltvaluegt ltstatementsgt .
. . . . . . . . . . . . . default
ltstatementsgt
29
Loop Statement
  • While statement formula

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)
30
Loop Statement
  • Do statement formula

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)
31
Loop Statement
  • for statement formula

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)
Write a Comment
User Comments (0)
About PowerShow.com