Nihar Ranjan Roy
Data Types
Primitives
(Standard)
Numeric
Integer
byte short int long
Floa
t
float double
Non-
Numeric
char boolean
Non-Primitives
(Derived)
Array Class Interfaces
Unicode16 bits i.e. 65,536 characters
Identifiers are the names given to elements like class , methods,
variables etc.
Rules
1. Variable name must begin with a letter, a doller symbol or an
under Score, which can be followed by a sequence of letters or
digits or, $ or _
2. It must be unique
3. It can be of any length
4. There should not be any space in between
5. Key words cannot be used
6. Java is case sensitive
Decimal(10) ex 23,-34,0, 1234
Octal (8) ex 023,034
Hexa Decimal(16) ex OX23,OX34
Standard Example 2.4double , 3.5FFloat
Scientific Example 2.4E7, 56e5
true or false
‘a’,’B’,’t’,’u0064’Hexa,’141’octal
“nihar Ranjan Roy”
Operator Symbols
Arithmetic
Assignment
Comparison
Unary
Shift
Bitwise
Logical
Conditional
Instance of and (.)
new
+,-,/,*,%
=,+=,-=,/=,*=
<,>,<=,>=,==,!=
++,--
>>,<<,>>>
AND,OR,NOT,XOR(&,|,~,^)
&&,||
Test Cond?Expr1:Expr2;
Obj instanceof class,.
Rose obj=new Rose();
13%5=?
13%-5=?
-13%-5=?
-13% 5=?
Positive number right shift
13>>1
13(1101)2
0000 1101 shift by 1 place
0000 01106
Positive number left shift
13<<1
0000 1101
0001 101026
Trick no/2n
13/21=13/2=6
Trick 2n*no
check 21*13=26
Negative number right shift
-10>>2
-10<<2
100000 1010
-10?
Rule Change 01 and 10 for all bits except the right most
bit that starts with 1
-101111 0110
-10>>21111 1101=-3
-10<<21101 1000=-40
Trick
-10/2n=-10/4=-2.5= -3
-10*2n=10*4=-40
100000 1010
-101111 0110
It does not distinguish between + and –ve numbers
10>>>2=0000 0010=2
-10>>>2
00111111 11111111 11111111 11111111=1073741821
Conclusion it places 0’s at MSB
Write a program in java that finds the sum of
the digits of an integer number till the sum
comes to single digit
Note  D0not use any Loop
Example
12345=1+2+3+4+5=15=1+5=6
float var=100.34;
Int a=(int) var;
Statement Keywords
Decision Making if , if else, switch
Loop for , while, do while
Exception try, catch, finally
Miscellaneous( others) break, continue ,return,
label
Switch If else
It can test only equality It evaluates any type of
Boolean expression
Break is needed Break is not needed
More efficient way of
represent branching
Less efficient way
It is faster Its slower
U cannot use a range of
values easily
U can use range of
values
Causes the flow to exit from the loop
…….
for ( int I =0;i<5;i++)
{
If (i==3)
break;
}
……..
Int i=6;
one:
{
System.out.println(“inside one”);
two:
{
System.out.println(“inside one”);
if (i==3)
break one;
}
}
Test
with in
loop
for (int i=0;i<50;i++)
{
If (i%2==0)
continue;
else
Sum+=I;
}
A frog starts climbing 30 ft well. Each hour frog
climbs 3ft and slips back 2ft. How many hours
does it take to reach top and get out?
[Hint: if Height>30 break;]
[Hint: sum of cubes of individual digits
give same number.
153=13+53+33=1+125+27=153]
Write a java program to find the
Armstrong number from 100 to 1000

02_Data Types in java.pdf

  • 1.
  • 2.
    Data Types Primitives (Standard) Numeric Integer byte shortint long Floa t float double Non- Numeric char boolean Non-Primitives (Derived) Array Class Interfaces
  • 3.
    Unicode16 bits i.e.65,536 characters
  • 5.
    Identifiers are thenames given to elements like class , methods, variables etc. Rules 1. Variable name must begin with a letter, a doller symbol or an under Score, which can be followed by a sequence of letters or digits or, $ or _ 2. It must be unique 3. It can be of any length 4. There should not be any space in between 5. Key words cannot be used 6. Java is case sensitive
  • 6.
    Decimal(10) ex 23,-34,0,1234 Octal (8) ex 023,034 Hexa Decimal(16) ex OX23,OX34 Standard Example 2.4double , 3.5FFloat Scientific Example 2.4E7, 56e5 true or false ‘a’,’B’,’t’,’u0064’Hexa,’141’octal “nihar Ranjan Roy”
  • 7.
    Operator Symbols Arithmetic Assignment Comparison Unary Shift Bitwise Logical Conditional Instance ofand (.) new +,-,/,*,% =,+=,-=,/=,*= <,>,<=,>=,==,!= ++,-- >>,<<,>>> AND,OR,NOT,XOR(&,|,~,^) &&,|| Test Cond?Expr1:Expr2; Obj instanceof class,. Rose obj=new Rose();
  • 8.
  • 9.
    Positive number rightshift 13>>1 13(1101)2 0000 1101 shift by 1 place 0000 01106 Positive number left shift 13<<1 0000 1101 0001 101026 Trick no/2n 13/21=13/2=6 Trick 2n*no check 21*13=26
  • 10.
    Negative number rightshift -10>>2 -10<<2 100000 1010 -10? Rule Change 01 and 10 for all bits except the right most bit that starts with 1 -101111 0110 -10>>21111 1101=-3 -10<<21101 1000=-40 Trick -10/2n=-10/4=-2.5= -3 -10*2n=10*4=-40
  • 11.
    100000 1010 -101111 0110 Itdoes not distinguish between + and –ve numbers 10>>>2=0000 0010=2 -10>>>2 00111111 11111111 11111111 11111111=1073741821 Conclusion it places 0’s at MSB
  • 12.
    Write a programin java that finds the sum of the digits of an integer number till the sum comes to single digit Note  D0not use any Loop Example 12345=1+2+3+4+5=15=1+5=6
  • 13.
  • 15.
    Statement Keywords Decision Makingif , if else, switch Loop for , while, do while Exception try, catch, finally Miscellaneous( others) break, continue ,return, label
  • 16.
    Switch If else Itcan test only equality It evaluates any type of Boolean expression Break is needed Break is not needed More efficient way of represent branching Less efficient way It is faster Its slower U cannot use a range of values easily U can use range of values
  • 17.
    Causes the flowto exit from the loop ……. for ( int I =0;i<5;i++) { If (i==3) break; } …….. Int i=6; one: { System.out.println(“inside one”); two: { System.out.println(“inside one”); if (i==3) break one; } }
  • 18.
    Test with in loop for (inti=0;i<50;i++) { If (i%2==0) continue; else Sum+=I; }
  • 19.
    A frog startsclimbing 30 ft well. Each hour frog climbs 3ft and slips back 2ft. How many hours does it take to reach top and get out? [Hint: if Height>30 break;]
  • 20.
    [Hint: sum ofcubes of individual digits give same number. 153=13+53+33=1+125+27=153] Write a java program to find the Armstrong number from 100 to 1000