PPTDay 1
PPTDay 1
WHY Java ?
Class types
Boolean type
Interface types
Numeric type
Array types
char
byte short int long float double
Data Types
• Integral Type
▪ byte 8 bits
▪ short 16 bits
▪ int 32 bits
▪ long 64 bits
• Textual Type
▪ char 16 bits, UNICODE Character
▪ String
Data Types
• Floating Point Type
▪ float 32 bits
▪ double 64 bits
• int n;
• float f1;
• char ch;
• double d;
Variables conti…
• class , interfaces , enum names- 1st letter of 1st word must start with upper case
& then follow camel case notation.
eg : HelloWorld
• data members/methods(functions) -- 1st must start with lower case & then
follow camel case notation
eg : performanceIndex
public double calculateSalary(....) {...}
• private
• default(package private) --no access modifier
• protected
• public
• src & dest - must be compatible, typically dest data type must be able
to store larger magnitude of values than that of src data type.
double myVal = a + b % d – c * d / b;
• Is the same as:
double myVal = (a + (b % d)) – ((c * d) / b);
Relational Operators
== Equal (careful)
!= Not equal
>= Greater than or equal
<= Less than or equal
> Greater than
< Less than
Statements & Blocks
• A simple statement is a command terminated by a
semi-colon:
name = “CDAC”;
if
(expression)
statement; A single statement in the if and a block
else of statements in the else.
{
statements;
}
Conditional Operator
• The operator “ ? : ” is the only operator that takes three
operands, each of which is an expression.
• Syntax:
• while
• for
• do … while
While – Loop
• Syntax:
while (expression) or while (expression)
Statement; {Statements;}
• The loop continues to iterate as long as the value of expression is true (expression
differs from zero).
• The braces { } are used to group declarations and statements together into a
compound statement or block, so they are syntactically equivalent to a single
statement.
for - Loop
• Syntax:
for (expr1 ; expr2 ; expr3)
statement;
or
for (expr1 ; expr2 ; expr3)
{
statements;
}
• Is equivalent to:
expr1;
while (expr2)
{
{statements;}
expr3;
}
do while Loop
• Syntax:
do
{
Statements;
}while (expression);
• The condition expression for looping is evaluated only after the loop body had
executed.
break Statement
• We have seen how to use the break statement within the switch
statement.