Advanced Programming Java-H-U1
Advanced Programming Java-H-U1
Advanced Programming Java-H-U1
Chapter One
Introduction to Java
✓ no explicit pointer
✓ programs run inside virtual machine
‘close’ to native code sandbox (JVM)
(interpreted language)
abstract declares abstract class do iterates part of the implements implements an private
program interface
boolean True and False values double 64-bit import Avail classes & protected
interfaces to the code
break breaks the current flow of the else alternative options instanceof Tests instantiation public
program
byte 8-bit enum fixed set of constants int 32-bit return
case mark blocks of text extends class is derived from interface declares an interface short
class or interface.
catch catch the exceptions final constant value of var long static
continue continues the current flow of the for to start a for loop null this
program
default specify the default block of code in if tests the conditions package throw
switch statement
Java Data Types & Operators
17
Data types
✓ specify the different sizes and values that can be stored in the variable.
There are two types of data types in Java: primitive and non-primitive.
Primitive data types: The primitive data types include boolean, char, byte, short, int, long, float and double.
Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays.
Operators
✓ Symbols that perform simple computations, like &, |, +, * etc.
Types of operators in Java:
✓ Unary Operator: post incre(expr++, expr--) & pre incre(++expr, --expr, +expr, -expr, ~ ,!)
✓ Arithmetic Operator: *, /, %, +, -
✓ Shift Operator: <<, >>, >>>
✓ Relational Operator: <, >, <=, >=, ==(equal to), !=(not equal to)
✓ Bitwise Operator: &, ^, |
✓ Logical Operator: &&, ||
✓ Ternary Operator: ?, :
✓ Assignment Operator: =, +=, -=, *=, /=, %=, &=, ^=, |=, <<=, >>=, >>>=
Control statements in Java
18
Java compiler executes the code from top to bottom. The statements in the code are executed according to the
order in which they appear. However, Java provides statements that can be used to control the flow of Java
code. Such statements are called control flow statements. It is one of the fundamental features of Java, which
provides a smooth flow of program.
Java provides three types of control flow statements.
1.Decision Making statements
1. if statements → used to evaluate a condition. E.g., if. If-else, if-else-if, if and else-if
2. switch statement → if-else-if statements
2.Loop statements
1. do while loop--checks the condition at the end of the loop after executing the loop statements
2. while loop--iterate over the number of statements multiple times
3. for loop--enables us to initialize the loop variable, check the condition, and increment/decrement in a single line of
code
3.Jump statements--transfer the control of the program to the specific statements.
1. break statement--break the current flow of the program and transfer the control to the next statement outside a
loop or switch statement
2. continue statement--doesn't break the loop, whereas, it skips the specific part of the loop and jumps to the next
iteration of the loop immediately.
Reading assignments
18
Function in Java
Class in Java
Object in Java
Object oriented concepts in Java
Control statements in Java
Array in Java
New features of Java
Exception Handling in Java
Data structure and Algorithm