Sunday, 17 May 2015

CONDITON CHECKING

CONDITON CHECKING

There are three programming construct followed by java programming language
Ø  SEQUENCE
Ø  SELECTION/CONDITION CHECKING
Ø  REPETITION/ITERATION

3.1 SEQUENCE: - Sequence indicates the flow of control passes from one instruction to the next in sequence. In other word statement executes one after other in an order in which they are written.
3.2 SELECTION;-It indicates the flow of control depends upon condition. If one condition is true then one set of statement will execute otherwise another set of statement will execute.
There are two type of selection
i.                    single selection structure e.g if –else
ii.                  multiple  selection structure e.g switch case
3.3 REPETITION; - It indicates that some set of statements is to be executes till particular condition is been satisfied. In other words if a statement executed more than once, the technique of repetition is applied.
There are three iteration statements;-
While loop
do while loop
for loop

3.4 IF STATEMENT; - the if statement allows branching (decision making) depending upon the value of the variable.
Syntax :- if(condition)
                        {
Statement _1(s);
}
else
{
statement_2(s)
}
=>Here condition must be given in such a manner so that it returns Boolean value.
=>If  condition will be true then statement_1 will execute otherwise statement_2 will execute.
=>else is optional, we can have if without else.
Example 1
// program to find higher number out of two number.
class check1
{
public static void main(String args[])
{
int  x=10,y=30;
if(x>y)
{
            System.out.println(“ higher no is ”+x);
}
else
{
            System.out.println(“ higher no is ”+y);
}
}
}
// output is
higher no is 30

Example 2
// program to find absolute value of number
class check2
{
public static void main(String args[])
{
int x=-25;
if(x<0)
{
x=x * -1;
}
System.out.println( “absolute value of x is ”+x);
//Output is
Absolute value of x is 25

Ø  here is x is a positive number the condition will become false and x will remain positive so no operation  needed to take place that is why else block is not used.


Example 3
// program to find character ch is alphabet or not.
class check2
{
public static void main(String args[])
{
char ch=’B’
if((ch>=’a’ && ch<=’z’) && (ch>=’A’ && ch <=’Z’))
System.out.println( ch+” is an alphabet”):
else
System.out.println( ch+” is not an alphabet”):

}
}
//output
B is an alphabet
Ø  If single statement is to be followed by an if or else block then curly brackets can be omitted.

3.5 NESTED IF:- Nested if/else structures test for multiple causes by placing if/else selection inside if/else selection structure. The if/else selection structure uses the condition till three levels. The following illustrates if format

if(condition)
{
            if(conditions)
            {
                        Statement(s)
            }
            else
{         
                        Statement(s)
            }
}          //end of if
else
{
            // another if else block
}



Example 4
// program to find highest of three number using nested if
import java.util.*;
class check2
{
public static void main(String args[])
{
Scanner Sn=new Scanner(System.in));
int x,y,z,m;
Systemout.println(“enter three number”);
x=Sn.nextInt();
y= Sn.nextInt();
z= Sn.nextInt();
if(x>=y)
{         
            if(x>=z)
                        m=x;
            else
                        m=z;
}
else
{
            if(y>=z)
                        m=y;
            else
                        m=z;
}
System.out.println(“highest  number is ”+m);
}
}

// above program will input 3 number from user if x is greater than y  then x will be compared with z if this condition is also true then it will display x otherwise it will display z else if x is less then y then y will be compared with z and depending upon condition given in else block y or z will be displayed.

Example 6:-
// program to find calculate net salary of the employee depending upon basic salary.


Basic                                       DA      HRA
Less than 2000                        10%     5%
Greater than equal to 2000     25%     15%
But less than 4000
Greater than equal to 4000     30%     25%
But less than 8000
Greater than 8000                   40%     30%
import java.util.*;
class check2
{
public static void main(String args[]) throws Exception
{
Scanner Sn=new Scanner(System.in));
int basic;
double da,hra,net;
Systemout.println(“enter basic salary”);
basic=Sn.nextInt();
if(basic<2000)
{
da=0.10*basic;
hra=0.05*basic;
}
else if(basic<4000)
{
da=0.25*basic;
hra=0.15*basic;
}
else if(basic<8000)
{
da=0.30*basic;
hra=0.25*basic;
}
else
{
da=0.40*basic;
hra=0.30*basic;
}
net=basic+da+hra;
System.out.println(“Basic Salary “+basic);
System.out.println(“Dearness allowance “ + da);
System.out.println(“House rent “+hra);
System.out.println(“Net Salary “+net);
}
}

Example 7:-

A cloth showroom has announced the following discounts on the purchase of items, based on the total cost of the item purchased:-
Total Cost                                    Discount(in percentage)
Less than Rs 2000                       5%
Rs 2001 to Rs. 5000         25%
Rs. 5001 to Rs 10000       35%
Above Rs. 10000              50%
Write a program to input the total cost and to compute and display the amount to be paid by the customer after availing the discount.                                             [2006]
import java.util.*;
class prog2
{
public static void main(String args[]) throws Exception
{
Scanner Sn=new Scanner(System.in));
int cost;
double amt,dis;
Systemout.println(“Enter Cost to the item”);
cost=Sn.nextInt();
if(cost<=2000)
  dis=cost*0.05;
else if(cost<=5000)
  dis=cost*0.25;
else if(cost<=10000)
  dis=cost*0.35;
else
  dis=0.50;
amt=cost-dis;
System.out.println(“Amount to be paid “+amt);
}
}

3.6 SWITCH CASE:- the switch case is multiple branching statement used to compare one variable with many constants but only for equality.
Syntax:-
switch (expression)
{
  case <value1> : expression(s)
                                    break;
  case <value2> : expression(s)
                                    break;
:
            :
 default : expression(s)
}
Example 8:-

program to input two numbers and an operator perform arithmetic operation as per operator
import java.util.*;
class check7
{
public static void main(String args[]) throws Exception
{
Scanner Sn=new Scanner(System.in));
int a,b;
char op;
System.out.println(“enter 2 numbers and one operator”);
a= Sn.nextInt();
b= Sn.nextInt();
op=Sn.next().charAt(0);
switch(op)
{
case  ‘+’: System.out.println(a+b);
                break;
case  ‘-’: System.out.println(a-b);
                break;
case  ‘*’: System.out.println(a*b);
                break;
case  ‘/’: if(b==0)
                System.out.println(“divide by zero”);
               else
                        System.out.println(a/b);
                break;
default : System.out.println(“invalid operator”);
            break;
}
3.7 When is it better to use switch statement instead of if ? why?
OR
COMPARE switch WITH if
The switch statement is java’s multiple branch selection statement. It provides an easy to dispatch execution to different parts of the code bases on the value of a expression. It provides a better alternative for a large series of if-else-if statement. Some important features of switch statement are listed below:-
  1. The switch statement can only test for equality, the statement can evaluate any type of Boolean expression.
  2. The switch only look for a match between the value of the expression and one of its case constants values. The if-else statement uses a series of expression having unrelated variable
  3. No two case constants in a switch can have identical values.
  4. switch case can work only upon int and char data type where as if else can work with all data types.

3.8 What is the effect of absence of break statement in switch case statement?
Break is to terminate the sequence , without break each and every following case of the switch statement will be executed. This situation also known as Fall through.
Eg.
switch(ch)
{
case ‘a’ : System.out.println(“A says Apple”);
case ‘e’ : System.out.println(“E says Egg”);
case ‘i’ : System.out.println(“I says Ink”);
}
When user input a into ch the output will be as follows
A says Apple
E says Egg
I says Ink


3.9 Explain with the help of an example each of the following in a switch-case statement
i.                    break
ii.                  default                                    [2005]
i.                    break:- the keyword break is used with the switch statement to break the sequential control of execution and brings the control to the statement immediately following the switch block.
If break is missing then fall through takes place.
ii.                  Default is optional statement, it executed the statements when no choice is satisfied. .i.e. when data with the switch does not match  with any of the cases.
If default is missing then no action takes place if all case matches fail.
Example.
switch(var)
{
case 1: System.out.print(“one”);
            break;
case 2: System.out.print(“two”);
            break
default: System.out.print(“none”);
            break;
}
if the value of variable is 1 then it will display one and follow the statement given after switch.
If value of the variable is other than 1 or 2 then is will follow default and display none.
3.10 Differentiate between if and switch statements.                                             [2006] 
 If can use relational or logical operator where as switch can compare only for equality.
If can use any type of variable for comparison where as switch can use only int and char data types.

3.11 Turnary to if else
e.g. 1->  x=(x<0)? X*-1 : x;
Ans:-  if(x<0)
                x=x*-1;
            else
                x=x;
e.g.2 ->  c=(a!=b)? a :b;
Ans      if(a!=b)
            c=a;
            else
            c=b;

Do yourself
a)      System.out.println(x%2==)?”even”:”odd”);
b)      Tax=value<=10000?0:0.10*value
c) System.out.println(n%4==0?”leap year”:”not  leap year”);
d) grade=mark>=80?’A’:mark>=60?’B’:    mark>=40    ’C’:’D’;
3.12 if else to  using turnary
e.g. 1   if(x>10)
y=y+1;
else
y=y+5
Ans:-
 y+=x>10? 1 : 5 ;
Do your self
A) if(y%4)
flag=1;
    else
flag=0;
B) if(mark>=80)
grade=’A’;
     else if(mark>=60)
grade=’B’;
     else
grade=’C’;
C) if(per>=40)
System.out.println(“pass”);
    else
Systen,out.println(“fail”);
c)      if(sale<=5000)
   comm.=0.05*sale;
 else if (sale<=10000)
  comm.=0.10*sale;
else
 comm.=0.15*sale;

3.13 if else to switch case
if(grade==’A’)
            System.out.println(“Excellent”);
else if(grade==’B’)
            System.out.println(“Well Done”);
else if(grade==’C’)
            System.out.println(“Satisfactory”);
else if(grade==’D’ || grade==’E’)
            System.out.println(“Work Hard”);
else
            System.out.println(“Failed”);

Using switch case
switch(grade)
{
case ‘A’: System.out.println(“Excellent”);
               break;
case ‘B’:System.out.println(“Well Done”);
               break;
case ‘C’: System.out.println(“Satisfactory”);
               break;
case ‘D’:
case ‘E’: System.out.println(“Work Hard”);
               break;
default: System.out.println(“Failed”);
             break;
}

3.14 switch case to if else
EXAMPLE 1
switch(ch)
{
case ‘a’:
case ‘A’: System.out.println(“ AIRTEL”);
               break;
case ‘e’:
case ‘E’: System.out.println(“E-Comm”);
                break;
case ‘i’:
case ‘I’: System.out.println(“IDEA”);
             break;
case ‘o’:
case ‘O’: System.out.println(“ORANGE”);
              break;
case ‘u’:
case ‘U’: System.out.println(“U-tube”);
                        break;
default: System.out.println(“not vowel”);
              break;
}

using if else
if(ch==’a’ || ch==’A’)
 System.out.println(“ AIRTEL”);
else if(ch==’e’ || ch==’E’)
 System.out.println(“E-Comm”);
else if(ch==’i’ || ch==’I’)
             System.out.println(“IDEA”);
else if(ch==’o’ || ch==’O’)
 System.out.println(“ORANGE”);
else if(ch==’a’ || ch==’A’)
            System.out.println(“U-tube”);
else
            System.out.println(“Not vowel”);

EXAMPLE 2
switch(grade)
{
case ‘A’: switch(slab)
              {
             case 1: sal+=4000;
                        break;
            case 2: sal+=3000;
                        break;
             }
            break;
case ‘B’:switch(slab)
             {
            case 1: sal+=2000;
                        break;
            case 2: sal+=1000;
                        break;
}
                  break;
}
 using if else
if(grade==’A’)
{
     if(slab==1)
              sal+=4000;
     else if (slab==2)
 sal+=3000;
}
else if(grade==’B’)
{   
    if(slab==1)
            sal+=2000;
    else if(slab==2)
 sal+=1000;

}

MATMATICAL FUNCTION

PI():- This is also a field of the Method class which returns you a default pi value, the ratio of the circumference of a circle to its diameter.
e.g  System.out.println("pi = " + Math.round(Math.PI*100)/100f);
output ;- pi = 3.14

abs():- This is the abs() function which returns you the absolute number.
e.g. System.out.println("Absolute number = " + Math.abs(Math.PI));
output Absolute number = 3.141592653589793

ceil()This is the ceil() function which returns you the smallest value but greater than the argument.
System.out.println("Smallest value but greater than the argument = " + Math.ceil(Math.PI));
System.out.println("Round up Math.ceil(28.29)= " + Math.ceil(28.29));
System.out.println("Round up Math.ceil(-28.29)= " + Math.ceil(-28.29));
output:-
Smallest value but greater than the argument = 4.0
Round up Math.ceil(28.29)= 29.0
Round up Math.ceil(-28.29)= -28.0

exp()This is the exp() function which returns you the exponential value raised to the power of a double value.
System.out.println("Exponent number powered by the argument = " + Math.exp(0));
output:-
Exponent number powered by the argument = 1.0

floor()This is the floor() function which returns you the largest value but less than the argument.
System.out.println("Largest value but less than the argument = " + Math.floor(Math.E));
System.out.println("Round down  Math.floor(28.89)= " + Math.floor(28.89));
System.out.println("Round down Math.floor(-28.89)= " + Math.floor(-28.89));

output:-
Largest value but less than the argument = 2.0
Round down  Math.floor(28.89)= 28.0
Round down Math.floor(-28.89)= -29.0

max()This is the max() function which distinguishes the maximum value from the two given value.
System.out.println("Maximum Number = " + Math.max(10,10.3));

Output:-
Maximum Number = 10.3

min()This is the min() function which distinguishes the minimum value from the two given value.
System.out.println("Minimum Number = " + Math.min(10,10.3));
Output:- Minimum Number = 10.0

pow()This is the pow() function which returns you the number raised to the power of a first given value by the another one.
System.out.println("Power = " + Math.pow(10,3));
output:- Power = 1000.0

random()This is the random() function which returns you the random number. It is absolutely system generated.
System.out.println("Random Number = " + Math.random());
Output:-
Random Number = 0.8746318896388414

rint()This is the rint() function which returns you a value closest to the given value.
System.out.println("Closest to the Argument = " + Math.rint(30));
Output:-
Closest to the Argument = 30.0

round()This is the round() function which returns you a value that is in the rounded form.
System.out.println("Round = " + Math.round(2.72));
System.out.println("Round  Math.round(28.89)= " + Math.round(28.89));
System.out.println("Round  Math.round(28.29)= " + Math.round(28.29));
Output:-
Round = 3
Round  Math.round(28.89)= 29
Round  Math.round(28.29)= 28

sqrt( ) This is the sqrt() function which returns you the square root of the specified value.
System.out.println("Square Root = " + Math.sqrt(400));

Output:- Square Root = 20.0



ICSE COMPUTER APPLICATIONS  Math class Output based Questions
CHAPTER: CLASS AS BASIS OF ALL COMPUTATION WORKSHEET # 3


11)      System.out.println(Math.sqrt(4.0)+Math.sqrt(9.0));
Ans______________________

22)      System.out.println(Math.pow(2,4))
Ans______________________

33)      System.out.println(Math.max(Math.max(2,3),Math.max(9,7)));
Ans______________________

44)      System.out.println(Math.min(Math.max(20,13),Math.min(9,7)));
Ans______________________

55)      System.out.println(Math.round(2.4));
Ans______________________

66)      System.out.println(Math.round(2.9));
Ans______________________

77)      System.out.println(Math.round(2.5));
Ans______________________

88)      System.out.println(Math.rint(2.4));
Ans______________________

99)      System.out.println(Math.rint(2.9));
Ans______________________

110)  System.out.println(Math.rint(2.5));
Ans______________________

111)  System.out.println(Math.rint(3.5));
Ans______________________

112)  System.out.println(Math.ceil(2.4));
Ans______________________

113)  System.out.println(Math.ceil(2.9));
Ans______________________

114)  System.out.println(Math.ceil(2.0));
Ans______________________

115)  System.out.println(Math.ceil(2.4));
Ans______________________

116)  System.out.println(Math.ceil(-2.4));
Ans______________________

117)  System.out.println(Math.ceil(-2.9));
Ans______________________

118)  System.out.println(Math.ceil(-2.0));
Ans______________________

119)  System.out.println(Math.floor(2.4));
Ans______________________

220)  System.out.println(Math.floor(2.9));
Ans______________________

221)  System.out.println(Math.floor(2.0));
Ans______________________

222)  System.out.println(Math.floor(-2.4));
Ans______________________

223)  System.out.println(Math.floor(-2.9));
Ans______________________

224)  System.out.println(Math.floor(-2.4)+Math.ceil(-2.4)+Math.round(2.7));
Ans______________________

225)  System.out.println(Math.abs(2.4)+Math.abs(-2.4));
Ans______________________

226)  System.out.println(Math.floor(-2.4));
Ans______________________

227)   System.out.println(Math.pow(4,1/2));
Ans______________________

228)   System.out.println(Math.pow(4,1.0/2));
Ans______________________

229)   System.out.println(Math.pow(4,Math.max(2,3)));
Ans______________________

330)   System.out.println(Math.ceil(Math.abs(-9.6));
Ans______________________



CLASSES -AS BASIC OF ALL COMPUTATION


2.1 CHARACTER SET OF JAVA: - java uses Unicode character set. It occupies 2 byte to store a character. Unicode can represent 65536 characters. It can recognize character of most of the language used in the world.
2.2 TOKEN: - Each individual character used in a Java Statement is known as Token
TYPES OF TOKEN: - The various type of token available in java is i. Literals ii. Identifier iii. Keywords. iv puncturators v. operator
2.3 KEYWORD: - They are the reserve word by the language which conveys special meaning to the programming language.
Imp- The keyword const and goto are reserved even though they are not currently used.
Imp- true and false might appear to be keyword but they are Boolean literals. null is not a keyword it is null literals.
2.4 LITERALS(CONSTANTS):- there are 6 types of literals in java. i. Integer literals ii. Real literals iii. Character literals iv String Literals v. Boolean literals vi Null literals.
2.5 INTEGER LITERALS; - an integer literal are whole numbers have at least one digit and must not contain and decimal point. It may contain either + or – sigh. Commas cannot appear in an integer literal.
2.6 FLOATING LITERAL: - floating literals are number having fractional parts. These may be written in one of the two forms fractional form or the exponent forms.
2.6.1 FRACTIONAL FORM; - a real literal in fractional form must have at least one digit before a decimal point and one digit after decimal point. It may also have either + or – sigh preceding it.
2.6.2 EXPONANT FORM: - a real literal in exponent form has two parts; - a mantissa and an exponent. The mantissa must be either an integer or a proper real number. The mantissa is followed by a letter E or e and the exponent. The exponent must be an integer.
2.7 BOOLEAN LITERALS: - the Boolean type has two values represented by the literal true and false.
2.8 CHARACTER LITERALS; - A character literals in java must contain one character and must be enclosed in single quotation marks.
2.9 NON GRAPHIC CHARACTER;- are those character which can not be directly type from the keyboard. e.g backspace, tabs, carriage return etc.
2.10 ESCAPE SEQUENCE; - non graphic character can be represented by using escape sequence. An escape sequence is represented by a backslash (\) followed by one or more characters. E.g.  \b   backspace,  \a alert bell,  \n  new line, \t  horizontal tab, \\  backslash, \? question mark, \’ single quote, \” double quote.
2.11 STRING LITERALs :-is a sequence of zero of more character surrounded by double quotes. Each character may be represented by and escape sequence.
2.12 VARIBLES: -  A variable is a named memory location, which contains a value. The value of variable can be changed depending upon the circumstances and problem in the program.
2.15 IDENTIFIERS: - Identifiers are the name given to different parts of the programs e.g. function names, variable names, class or object names etc.
2.14 RULES OF NAMING IDENTIFIERS
An identifier name can be of any length containing alphabet, digit and underscore. It can not start with a digit. It can not be a keyword.
Identifier name should be meaning full which it easily depicts the logic.
2.15 DATA TYPE- Data types are means to identify the type of data and associated operation of handling it.
DATA TYPE IN JAVA:-there are two type of data type. A: - Primitive type B: - Non –primitive (Reference) type.
 2.16 PRIMITIVE DATE TYPE: - The type of data which are independent of any other type, are known as Primitive data types. These types are known as fundamental or basic data type. They are pre-defined or built in data type. E.g. byte, short, int, long, char, float, double Boolean.
2.17 REFRENCE DATA TYPE; - they are composed of primitive data type e.g. array, string, class, interface etc.
2.18 INTEGER TYPE: - A variable declared integer type contains a whole number.


Data type
Size
Range
Default
Byte
1 byte
-128 to 127
0
Short
2 byte
-32768 to 32767
0
Int
4 byte
-231 to 231-1
0
Long
8 byte
-263 to 263-1
0L

2.19 FLOATING TYPE: - a variable to be floating type if we want to store real numbers in it.
Data type
Size
Range
Default
Float
4 byte
3.4 x10-38 to 3.4 x1038 
0.0F
Double
8 byte
1.7 x 10-308 to 1.7 x 10308
0.0
Note; - By default java treats fractional numbers as of double data type.
2.20 CHARACTER TYPE :- A character type variable contains a single character. It occupies 2 bytes. It can store 65536 characters. It default value is ‘\u0000’.
2.21 BOOLEAN TYPE: - it is special type in which a variable contains a constant as true of false these are nonfigurative constant. It occupies 1 byte in memory
2.23 PUNCTUATORS:-are the punctuation sign used as special character in java. Some punctuators are : ; ,  etc
2.24 SEPARATORS;- are special character used in java to separate the character or varibles e.g       ( ),{}, [] etc
2.25. TYPE CONVERSION(TYPE CASTING) in a mixed expression the result can be obtained in  any one from of its data types. Hence, it is needed to convert the various data type into the single type. Such conversion is termed as type casting.
2.25.1 IMPLICT TYPE CASTING- the data type of the result get converted automatically into its higher type without intervention of the user. This system of type conversion is known as implicit type conversion.
2.25.2 EXPLICIT TYPE CONVERSION:- is another way of type conversion in which the data type gets converted to another type of depending upon choice. This means the user forces the system to get back into the desired data type.
e.g. int a,b;
float x=(float) (a+b);
2.26 VARIBLE SCOPE:- generally refers to the program region with in which a variable is accessible.
2.27 final KEYWORD. This keyword is used while declaring a variable. These variables are
initialised during the declaration and their values cannot be modified further in the program. This way keyword final makes the variable as constants.
Example:- final double pi=3.14;

2.28 OPERATOR;-are the symbol which tell the computer which operation to take place
Operand: - are the data items on which operation takes place.
TYPE OF OPERATOR;-
·         Arithmetical Operator
·         Relational Operator
·         Logical Operator
·         Assignment operator
2.29 ARITHMATICAL OPERATOR: - the operators which are applied to perform arithmetical calculation in a program are known as arithmetical operator. Some basic calculation like addition, subtraction, multiplication and division and modulus often needed during programming.
Type of arithmetical operator; - unary  and binary 
Unary operator :- uses only one operand.
Binary operator :- uses two operand
Type of unary operator i.) unary + ii.) unary –
iii) unary increment and unary decrement operator
2.30 INCREMENT/DECREMENT OPERATOR: - they are used to increment/decrement  the value of a integer variable by 1
x++, ++x will increment value of x by 1
x--, --x will decrement value of x by 1
2.30.1 POSTFIX:- evaluates to the value of the operand after the increment /decrement operation
e.g       if x=5 initially then y=x++; will store 5 into y and x will become 6.
if x=5 initially then y=x--; will store 5 into y and x will become 4.
2.30.2 PREFIX:- evaluates to the value of the operand before the increment /decrement operation
e.g       if x=5 initially then y=++x; will store 6 into y and x will become 6.
if x=5 initially then y=--x; will store 4 into y and x will become 4.
2.31 RELATIONAL OPERATOR:- are used to show relationship among the operands. Relational operators compare the values of the varibles and results in terms of true or false. Eg:-  > ,<, >=,<=,!=, ==
2.32 LOGICAL OPERATOR:- are used to combine two or more conditions. &&, ||, !
&&(AND) evaluates the condition as true when all conditions combined with it is true.
||(OR) evaluates the condition as true when any on of the conditions combined with it is true.
! (NOT ) is used to invert the result of the condition
2.33 TURNARY OPERATOR;- deal with three operands. It also called condition assignment statement because the value assigned to a variable depends upon a logical expression.
Syntax: variable= (test expression) ? expression 1: expression 2;
Ex.   z=(x>y)?x:y;
Here value of z will be x if condition is true otherwise z will be y.
Ex. Boolean flag=age>18? true:false
Here value of variable flag will be true if age is greater than 18 otherwise flag will become false.

2.34 OPERATOR PRECEDENCE: determines the order in which expressions are evaluated. It is a set of rules that establishes which operators get evaluated first and how operators with in the same precedence level associate.
2.35 OPERATOR ASSOCIATIVITY: - rules determine the grouping of operands and operator in and expression with more than one operator of the same precedence.
2.36 EXPRESSION; - in java is any valid combination of any valid combination of operators, constants and variable.
2.36.1 PURE EXPRESSION: - all the operands are of same data type.
2.36.2 MIXED EXPRESSION: - the operands are of mixed or different data type.
2.36.3 INTEGER EXPRESSION: - are formed by connection integer constants or integer variable using integer arithmetic operator.
2.36.4 REAL EXPRESSION; - are formed by connection real constants or real variable using arithmetic operator (except %)
2.37 INSTANCE VARIBALE: - the variable which are declared inside a class and treated as data members of the same class called instance variable. Individual copy of instance variable is created for each object.
2.38 print() and println():-  the print and println methods send information to standard output because they are part of System.out.
DIFFERENCE BETWEEN print() and println():- print(0 displays the given data/information but do not change line after display where as println() displays the given data/information and changes line after displaying it.
Name two specific purpose of + operator.
The + operator is used for arithmetic addition and string concatenation.
e.g.  System.out.print(“Computer “);
      System.out.println(“Application”);
      System.out.println(“Class X”);
Output:- computer Application
               Class X
2.39. DIFFERENCE BETWEEN OPERATOR AND EXPRESSION. An operator is a symbol that performs a specific operation on the operands. An operator can be unary operator and binary operator depending on number of operands it operates upon.
e.g +,-,*,/, % are binary operator.
An expression is formed by the combination of operator of operators with operands. E.g a+b/2 * c is and arithmetic expression. [2005]
2.40 DIFERENCE BETWEEN = AND ==:- The ‘=’ (assignment operator) is to assign the value of the variables, whereas ‘==’ (relational operator) is to compare two values. For example.
int x=95;          //assignment
int y=102;        //assignment
if(x==y)           //condition check
2.41 Difference between unary and binary operator
Unary Operator
Binary Operator
i. Operators that act on on operand are reffered to as unary operator.


ii. ++,--, unary + or unary – are unary operator
i.                   Operator which require two operands for their functing are calles binary operator.

ii. Arithmatic operator, Relational operator are Binary operator.

2.42 Difference between Primitive data type and Refrence Data Type.
Primitive Data Type
Refrence Data Type
i. These are the basic of fundamental data type supported by java.
ii. The primitive data type variables store the actual value and their operations deal with rvalue.


iii. example int, char , float, double
iv. use of new operator is not necessary
1. These data types are constructed from primitive data types.

ii.                  The reference data type variables store the addresses or the references of the memory location of the actual data. These deal with the lvalue.
iii.                Examples:- class, array, refrences.
iv.                Use of new operator is must.
2.43 Similarity and Difference between java character set (Unicode) and ASCII code.
Similarity:- The first 128 characters in the Unicode character set are same as ASCII character set. i.e. they represent the same characters.
Difference:-
Unicode
ASCII code
i.                    It is a 2 byte character code set
ii.                  It can represent 65536 characters.
i.                    it is a 1 bypte character code set.
ii.                  It can represent only 128 characters.

2.44 Difference between Implicit and Explicit type conversion.
Implicit type conversion
Explicit type conversion
1.                   This type of conversion is performaed by compiler user intervension not required.
2.            No keyword is requied to perform this conversion.
int x=12;
double d=x;
1.                   This type of conversion is forces by the user.
  1. keyword data type is used to force explicit type conversion.
Ex. double x=12.5;
int i=(int)x;


2.45 Difference between rvalue and lvalue.
rvalue is called real value. It referes to data item stored in the variable. Rvalues is calles location value it refers to the memory address where variable is allocated.


important point
1.  Differentiate between operator and expression.                                           [2005]
 an operator is a symbol which specifies that which operation to take place on operand. where as expression is formed using valid combination of operator and operand.
e.g +,-,++,--,>,< are operator where is x=y+z is an expression
2.  if m=5 and n=2 output the values of m and n after exceution in (i) and (ii) :             [2005]  
i)m-=n
(ii) m=m+m/n
if m=5 and n=2 then
(i) m-=n  -> m=m-n -> m=5-2=3
(ii) m=m+m/n -> 5+5/2=7
3.) What is a compound statement? Give an Example.                                     [2005]
Compound statement is a set of two of more programming statements. it is also called a block.
A compound statement is seen in an if- construct, while loop, do while loop, for loop and switch
construct.
e.g. if(x>y)
            {
            t=x;
            x=y;
            y=x;
            }
e.g. int num[]={1,2,3,4,5};
4.  what will be the output of the following. if x=5 initially?                                          [2005]
(i) 5*++x
(ii) 5*x++
(i)5*6=30
(ii)5*5=25

5. What is the output of  the following? [2005] 
char ='A';
short m=26;
int n=c+n;
System.out.println(n)
ASCII code of A is 65 so
n=65+26=91
6. What is the purpose of the new operator? [2006]
new:- The new operator is used to create an object of a class and associate the object with a variable that names it.
Question 2
7.State the two kinds of data types. [2006]
Two kinds of data types are i. Primitive data type e.g. int, char, float.
ii. Refrence data type e.g. object and array                                                          s.
i.                    8.  
9.What will be the output for the following program segment?                           [2006]
int a=0,b=30,c=40;
a= --b + c++ +b ;
System.out.println(a);
Output :- a=98

//Write a program  to input a time in seconds and convert it into hrs, minutes and seconds.
import java.util.*;
class convert
{
public static void main(String args[]) Throws Exception
{
Scanner Sn=new Scanner(System.in));
int hr,min,sec, s;
System.out.println(“enter time in seconds”);
s=Sn.nextInt();
hr=s/3600;
s=s%3600;
min=s/60;
sec=s%60;
System.out.println(hr+” Hrs “+min+” minutes      “+sec+” seconds”);
}
}

Specify output of given if a=5 and b=3 initially

C=++a+ --b + ++a +--b
System.out.println(a+” “+b+” “+c);
Output:- 7  1  16
Specify output of given if a=5 and b=3 initially
C=a++ + --b + a++ + --b
System.out.println(a+” “+b+” “+c);


Output:- 7  1  14

CONCEPT OF OBJECT – INTRODUCING CLASSES- INTRODUCTION JAVA

1.1 OBJECT ORIENTED PROGRAMMING
An object oriented programming (OOPS) is a modular approach, which allows data to be applied within stipulated program area. It also provides the reusability feature to develop productive logic, which means to give more emphasis on data.
1.2 FEATURES OF OBJECT ORIENTED PROGRAMMING
i.                    It gives stress on the data items rather than functions.
ii.                  It makes the complete program / problem simpler by dividing it into number of objects.
iii.                The object can be used as a bridge to have data flow from one function to another.
iv.                We can easily modify the data without any change in the function.
1.3 BASIC ELEMENTS OF OOP (PRINCIPALS OF OOP
  1. Object  2. Classes  3. Data Abstraction  4. Encapsulation  5. Data hiding  6. Inheritance  7. Polymorphism
1.4 OBJECT :- Object is a unique entity, which contains data and function(Characteristics and behaviour) together in an object oriented programming OOPs Language.
i.           It is visible.   
ii.        It can be defined and described easily .
1.5 CLASSES:- Class is a set of different objects. Each object of the class possesses same attributes and behaviour defined within the same class. Hence class is also termed as object factory.
1.6 ENCAPSULATON:- The system of wrapping data and function into single unit( called class) in known as encapsulation.
1.7 DATA HIDING:- Such insulation of data , which can not be accessed directly outside class premises although they are available in the same program, is known as data hiding.
1.8 DATA ABSTRACTION:- Abstraction refers to the act of representing essential features without including background details.
1.9 INHERITANCE:- Inheritance is the process by which object of one class can link & share some common properties of object from another class.
 * Process of acquiring  properties of an existing class is called inheritance.
1.10 USE OF INHERITANCE:- (i) No need to repeat the code ii) reusability of the class.
(ii) It in transitive in nature.
1.11 REUSABLITY:-It is the process of adding some additional features to a class without modifying its contents.
1.12 POLYMORPHISM; - Allows two or more class to respond to the same message in different ways, this means we can use the same name for a method in two different class or same class. It also means that the user can send the same message to two different classes and still get the correct response.
* The process of representing one thing in many forms is called polymorphism.
1.13.  What is a state and behaviour of an object? Explain with examples.
Object share two characteristics: they all have state and behaviour. For example, your dog has state (name, colour, and breed) and behaviour (barking, fetching and wagging tail.)
            Real world object have state and behaviour. Software objects state is implemented through member data and behaviour is implemented through member function /methods.
1.14 Why is data considered safe when encapsulated?
This keeps the code and the data, safe from outside interference and misuse. It prevents the data from being accessed by any other code defined outside the wrapper.


1.15 How do object encapsulate state and behaviour?
State and behaviour of object are interweaved. They are said to encapsulate state and behaviour. e.g. a car object has characteristics like number of wheels seats etc. its state is represented as halted, moving or stationary and its behaviour is, it can move, stop, blow horn etc,. Now all these things are wrapped up together in the form of car. Thus we can say the object encapsulates their state and behaviour as their state and behaviour are interlinked, they cannot exist separately.
1.16 RUNTIME  ERROR:- It occurs due to wrong logic of the program. It occurs at the time of execution.
1.17 SYNTAX ERROR; - It occurs when the syntax of the program is not correct .It occurs at the time of compilation.
1.18 JAVA – A high level programming language developed by Sun Microsystems. It was invented by James Gosling and others in 1994.Java were originally called OAK and were developed as a part of Green Project at the sun company. It was designed for handheld devices and set-top boxes.
1.19 FEATURES OF JAVA;-
-          Java is an object oriented programming language.
-          It can access data from a local system as well as from a network.
-          Java program is written within a class. The variable and function are declared and defined within the class.
-          There are two types of java program- Applets and Application programs. Applets are the programs which run on web-browser. Application programs are the general programs like any other programming language.
-          Java           is a case sensitive language. It distinguishes the upper case and lower case letters.
1.20 BYTE CODE AND JVM
-          Java is a high level language and the program written in HLL is compiled and then converted to an intermediate language called byte code.
-          When this Byte code is to run on any other system, an interpreter known as Java Virtual Machine is needed which translates the byte code to machine language. JVM acts as a virtual processor which processes the byte code to machine code instructions for various platforms. That is why it is called Java Virtual Machine.
1.21 Why is java architecture neutral?
Java architecture is neutral because java byte code is not associated with any particular hardware platform. It can be executed on any machine with a java interpreter.
1.22 Difference between .java & .class
Java source code (files with a .java extension) are compiled into a format called byte code (files with a .class extension), which can then be executed by a java interpreter.
Where does java run?
Java virtual machine can run on: Windows 95, Windows NT, Solaries 2.3(or higher), PowerMacs, and java station, set top Box etc

1.23 COMMENTS IN JAVA; - A comment can be expressed in a program by following two styles:
i)                    // for single line comment.
E.g. // this is a remark
ii) /*… */: for multiple line comments. As it have beginning marks and ending marks.
e.g. /* this comment can proceed in different lines*/                                                 [2005]

important question
1.  Name any two OOP'S Principles. [2005]
  Encapsulation and Abstraction
2.Define encapsulation.                     [2006]
ENCAPSULATON:- The system of wrapping data and function into single unit( called class) in known as encapsulation. It mean that wrapping up of data and methods together as a single unit.
3.Explain the term object using an example.[2006
OBJECT :- Object is a unique entity, which contains data and function(Characteristics and behaviour) together in an object oriented programming OOPs Language.
i.           It is visible.  
ii.        It can be defined and described easily

4. Define a variable.                          [2006]
VARIBLES: -  A variable is a named memory location, which contains a value. The value of variable can be changed depending upon the circumstances and problem in the program.
int a=5;
here ‘a’ is a variable of integer type and hold the value 5
5. Mention any two attributes required for class declaration.                                                [2008]
Ans  1.Characteristic and behavior.

2..Member data and Member function