Java
Java
What is Java?
boolean(true or false)-a boolean is not a number and cannot be converted to a number or any other type.
char(characters)-represents text characters or unicode characters.
byte-represents short numbers from -128 – 127 only.
short-ranges from -32768 - 32767
int(integer)-numbers without fractional parts. Negative values are allowed ranges from -2,147,483,648 -
2,147,483,647.
long-enhance version of integer. Ranges from 9,223,372,036,854,775,808 - 9,223,372,036,854,775,807.
float(floating point or fraction)- numbers with decimal points.
double-mostly used than the float data type, since these numbers have twice the precision of the float type.
Normal Form Compressed Form
sum = sum + 1 sum+=2
p=p–1 p -=1
r = r /4 r /=4
j=j*b j*=b
n = n% 2 n%=2
n=n+1 n++
a=a–1 a—
Relational Operator
&& Conditional-AND
|| Conditional-OR
Conditional Statements
If statement
If else
If else if
switch
If statement
If the boolean expression evaluates to true then the block of code inside the if statement will be executed. If not
the first set of code after the end of the if statement(after the closing curly brace) will be executed.
37
Programming Logic
What is Computer?
• Is an electronic device that accepts input, processes data, store data and produces output.
Program
• A computer program is a collection of instructions that performs a specific task when executed by a computer.
• A computer requires programs to function, and typically executes the program's instructions in a central
processing unit.
Programming
• Programming is the process of translating a problem’s solution into instructions that a computer can process.
– Planning
– Analysis
– Design
– Implementation
– Maintenance
Planning
Analysis
• Identifying solutions
Design
Implementation
Algorithm
• Example
Instruction in a shampoo
• Pseudocode: The steps of the algorithm are written in English in a shorthand form which represents the flow of
control through the algorithm.
Flowchart Symbols
Terminator Block
Flow lines
Input/Output Block
Programming Structure
1. Sequential Structure
2. Conditional Structure
3. Looping Structure
Conditional
• If
• If else
• If else if