Java Revision Tour

13
  visit @ http://www.infotechcomputer.in  INFOTECH Computer Education, Kishangarh (Raj)  9829171122 Page 1 Chapter 3 Java Revision Tour Rapid Appication Development - It is a method of developing software through the use of pre programmed tools and wizards. it helps the programmer to deve lop programs and softwares rapidly. IDE - Integrated Development Environment ) - It is a programming environment provided to programmer which helps of programming to perform various tasks. Netbeans is an Integrated Development Environment for Java. other one is eclipse Components of IDE 1. Title Bar 2. Menu Bar 3. Toolbar 4. GUI Builder 5. The Palette 5. Inspector Window 7. Properties Window 8. Code Editor Window etc .

Transcript of Java Revision Tour

Page 1: Java Revision Tour

7/21/2019 Java Revision Tour

http://slidepdf.com/reader/full/java-revision-tour 1/13

 visit @ http://www.infotechcomputer.in 

INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 1

Chapter 3 Java Revision Tour

Rapid Appication Development - It is a method of developing software through the use of preprogrammed tools and wizards. it helps the programmer to develop programs and softwares rapidly.

IDE - Integrated Development Environment ) - It is a programming environment provided to programmer

which helps of programming to perform various tasks. Netbeans is an Integrated Development

Environment for Java. other one is eclipse

Components of IDE

1. Title Bar

2. Menu Bar3. Toolbar

4. GUI Builder

5. The Palette

5. Inspector Window

7. Properties Window

8. Code Editor Window etc.

Page 2: Java Revision Tour

7/21/2019 Java Revision Tour

http://slidepdf.com/reader/full/java-revision-tour 2/13

Page 3: Java Revision Tour

7/21/2019 Java Revision Tour

http://slidepdf.com/reader/full/java-revision-tour 3/13

 visit @ http://www.infotechcomputer.in 

INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 3

d. character literal - a='z'

e. string literal - a="Ram" a="z" a="9"

f. null literal - a=null

Punctuator - These are also called as seperators few of them are () [ ] ; , etc

Operators - Operators are the elements which performs some action on operands. for eg. c=a+b. in this

statement a,b and c are the operands and +,= are operators.

Types of Operators :

1. Mathematical Operators :

+

-

*

/

%

2. Increament and Decreament Operators :

++ (prefix and postfix) a++ and ++a--

a=5

sout a++) : first print the value of x and then increase the value of x

sout ++a) : First increase the value of x and then print it

3. Relational Operators :

> : greater than

< : less than

>= : greate than equals to<= : less than equals to

!= : Not equals to

== : comparison operator

4. Logical Operators :

&& (Logical And Operator)

|| (Logical OR Operator)

! (Logical Not Operator) eg. !(5>7)

Page 4: Java Revision Tour

7/21/2019 Java Revision Tour

http://slidepdf.com/reader/full/java-revision-tour 4/13

 visit @ http://www.infotechcomputer.in 

INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 4

5. Bitwise Operators :

& (Bitwise AND Operator)

| (Bitwise OR Operator)

! (Bitwise NOT Operator)

6. Assigment Operators :

=

+= a=a+5 a+=5

-=

/=*=

%=

7. Shift Operators

Right Shift >> (Right shift 1 time means divide the value by 2)

Left Shift << (Left shift 1 time means multiply the value by 2)

8. Conditional Operator also called as ternary operator)

c=a>b?a:b

Escape Sequence : these character combinations have special meanings.

\n = next line

\t = tab

\a = alert bell

Data Types : They are the types which are used to identify the data items that can be stored under it and

the operations that can be done on them.

Types of Data Types :

1. Primitive Data Types : (Implicit Data Types) (Inbuilt Data Types)

2. Non Primitive Data Types : (Explicit Data Types) (Reference Data Types) (User Defined Data Types)

Primitive Data Types are the inbuilt data types of java like int, double, float etc.

Non Primitive Data Types of reference data Types are the user defined data types created by the help of

primitive data types for eg. classes and interfaces etc.

Page 5: Java Revision Tour

7/21/2019 Java Revision Tour

http://slidepdf.com/reader/full/java-revision-tour 5/13

 visit @ http://www.infotechcomputer.in 

INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 5

Variables : A Variable is a name of memory location which holds a data value of particular data type.

declaration of variable - int a;

initialization of variable - a=5

Constant - A variable whose value can't be changed

for eg. final pi=3.14;

Operator Precedence - Operator precedince determnes the order in which expressions are evaluated. forexample if the statement is

a+b*c/d then first of all * operator will be solved beacuse precedence of * and / is same but associativity

is left to right, then / is solved and in the last + is resolved.

Expressions - An expression in java is any valid combination of operator,s, constants, and variables i.e. a

legal combinations of java tokens. 

Types of java expressions are as follows :

1. Arithmetic expression

2. Compound Expression

3. Relational or logical expression.

1. Arithmetic Expression : These expressions are either pure integer expressions or pure real expressions.

we can also form mixed expressions with combining integer and real values for example

Given

int a,b,c

float p,q,r

1. a/b is a pure integer expression

ii. p/q is a pure real expression

iii. a*p/q is a mixed expressioin

2. Relational or Logical expression :

the expressions that result in true or false values are called boolean

expressions. these are combination of constants, variables and logical and relational operators. for

example

i. x>y ii. (y+z)>=(x/z) etc

3. Compound Expressions :

A compound expression is the one which is made up by combining two or

more simple expressions with the help of operators. for example

(a+b)/(c+d)

or

(a>b) || (b>c)

Page 6: Java Revision Tour

7/21/2019 Java Revision Tour

http://slidepdf.com/reader/full/java-revision-tour 6/13

Page 7: Java Revision Tour

7/21/2019 Java Revision Tour

http://slidepdf.com/reader/full/java-revision-tour 7/13

 visit @ http://www.infotechcomputer.in 

INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 7

if a>b)

{

...

...

...

...

}

in the above if construct dotted lines are represented as a block. a block always starts with a { symbol

and ends with a } symbol.

Note: if there is only one statement in any (if, while , do-while , for) construct then we can omit theblock characters ( { ..... } ). In this case Only a single line will be termed as a block in that construct.

Null or Empty Statement : We know that all of the java statements are terminated with a semicolon

symbol. if there is only a semicolon in a java statement then it can be termed as a empty or null

statement for example

;

JAVA PROGRAMMING CONSTRUCTS :

In java there are three types of programming constructs just like any other programming language.

these basic programming constructs are1. sequence

2. selection

3. iteration

1. Sequence :

it means any set of statements in a java program that are executed in a sequence

2. Selection : it means the execution of a statement or a set of statements depending upon a condition

test. if the given condition is true then one set of statements execute otherwise the other set executes.

it is also called as decision construct. Normally if , switch and conditional statement comes into this

category of java constructs.

Page 8: Java Revision Tour

7/21/2019 Java Revision Tour

http://slidepdf.com/reader/full/java-revision-tour 8/13

 visit @ http://www.infotechcomputer.in 

INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 8

3. Iteration : it is also called as a loop. here a statment or a set of statements are executed repeatatively

based on a given condition test. while, do-while and for loop comes into this category of constructs.

Selection Statements in Java : In java there are two Selection Statements

1. If Statement

a. Simple If Statement

b. If - else statement

c. Nested If Statement

d. conditional Statement

2. Switch Statement

1. If Statement

: if we want to execute a statement or a set of statements according to a given condition

or criteria then we use simple if statement as follows:

if (a>b && a>c)

{

sout ("Largest is "+a);

}

2. If - else statement : if we want to execute a statement or a set of statements among the two sets

according to a given condition or criteria then we use if - else statement as follows :if (a>b)

{

sout("Largest is "+a);

}

else

{

sout("Largest is "+b);

}

3. Nested If statement : if there are various conditions to be check to execute a set of statments amongthe few sets then we use nested if statement as follows :

if(a>b)

{

if(a>c)

{

sout("Largest is "+a);

}

else

{

sout("Largest is "+c);

}

Page 9: Java Revision Tour

7/21/2019 Java Revision Tour

http://slidepdf.com/reader/full/java-revision-tour 9/13

 visit @ http://www.infotechcomputer.in 

INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 9

}

else

{

if(b>c)

{

sout("Largest is "+b);

}

else

{

sout("Largest is "+c);}

}

4. Conditional Statement : if we want to replace the simple if statement or the nested if statement with a

single statement then we can use conditional statement as follows :

example 1

c=a>b?a:b;

example 2

c=a>b?a>c?a:c:b>c?b:c;

2. Switch Statement : it is a better replacement of if statement only if the condition set of if statement is

related to a single value. if is known as multiple branch selection statement. it is used as follows:

switch(a)

{

case 1: sout("Monday");

break;

case 2:sout("Tuesday");

break;

case 3:sout("Wednesday");

break;

case 4:sout("Thursday");

break;

Note : the fall of control to the cases of matching case in a switch statement is called Fall-through 

Iteration:

In Java there are three Iterative Constructs. Iterative Constructs are also called as loops

1. While

2. Do - While

3. For

Page 10: Java Revision Tour

7/21/2019 Java Revision Tour

http://slidepdf.com/reader/full/java-revision-tour 10/13

 visit @ http://www.infotechcomputer.in 

INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 10

Each of the loop contains the following basic components

1. Initialization Expression (a=1)

2. Test Expression (a<=10)

3. Update Expression (a++)

4. Body of the Loop {......}

1. While Loop - when we want to execute a statement or a set of statements repeatatively a number of

times according to a given condition or criteria then we use while loop. it comes under the category of

conditional looping. when we do not know about the exact number of repeatative executions of the setof statements then we use while loop. its syntax and example is as follows :

syntax.

initialization expression

while (test expression)

{

.

body of the loop

.

update expression

}

Example

a=1;

while(a<=10)

{

sout(a);

a++;

}

2. Do - while loop - It is same as while loop but the basic differences between while loop and do - whileloop are as follows :

While Do While

1. While is a entry controlled loop it is an exit controlled loop

2. While is also called as Top-tested or pre-tested loop it is also called as bottom-tested or

post-tested loop

3. it is not necessary that this loop must execute at least once it is necessary that this loop will execute

at least once

Page 11: Java Revision Tour

7/21/2019 Java Revision Tour

http://slidepdf.com/reader/full/java-revision-tour 11/13

Page 12: Java Revision Tour

7/21/2019 Java Revision Tour

http://slidepdf.com/reader/full/java-revision-tour 12/13

 visit @ http://www.infotechcomputer.in 

INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 12

JUMP OR BRANCH STATEMENTS IN JAVA

--------------------------------------------------------------------------------------------------------------------------------------

The jump statements unconditionally transfer program control within a function. Java has three jump

statements

1. return

2. break

3. continue

1. Return statement : it is mainly used inside a method to return a value. example of return statement is

as follows:

static int sum(int x,int y)

{

int c;

c=x+y;

return(c);

}

public static void main(String args[])

{

int t;t=sum(5,7);

System.out.println("Sum is "+t);

}

2. Break Statement - It is used to take the control out of the innermost loop. it takes the control out of

the while, do-while, for or switch statement. example of break statement is as follows :

int x,i,flag=0;

x=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Value"));

for(i=2;i<=x-1;i++){

if(x%i==0)

{

flag=1;

break;

}

}

if(flag==0)

sout("Number is prime");

else

sout("Number is not prime");

Page 13: Java Revision Tour

7/21/2019 Java Revision Tour

http://slidepdf.com/reader/full/java-revision-tour 13/13

 visit @ http://www.infotechcomputer.in 

INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 13

Note : In java Labelled Break are also allowed. we can transfer the control outside any of the loop using

labelled break statement.

3. Continue Statement : it is an another jump statement which takes the control back to the next

iteration of the loop and skips the rest code in body of the loop. example of continue statement is as

follows :

int x;for(x=1;x<=10;x++)

{

if(x==2 || x==5 || x==7)

continue;

System.out.println(x);

}

Output 1 3 4 6 8 9 10