0% found this document useful (0 votes)
84 views5 pages

Java Notes For Class I

The document provides an overview of object-oriented programming concepts in Java including objects, classes, inheritance, encapsulation, and polymorphism. It also discusses Java programming basics like data types, operators, decision making statements, and error handling. Key topics covered include: 1. Objects have characteristics and behaviors while classes are templates that create objects. 2. The four pillars of OOP are abstraction, encapsulation, inheritance, and polymorphism. 3. Java uses the Unicode character set and has primitive data types like int and double as well as reference types like classes. 4. Control structures in Java include if/else statements, switch statements, and loops for decision making and repetition. 5

Uploaded by

Sudipti Tiwari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
84 views5 pages

Java Notes For Class I

The document provides an overview of object-oriented programming concepts in Java including objects, classes, inheritance, encapsulation, and polymorphism. It also discusses Java programming basics like data types, operators, decision making statements, and error handling. Key topics covered include: 1. Objects have characteristics and behaviors while classes are templates that create objects. 2. The four pillars of OOP are abstraction, encapsulation, inheritance, and polymorphism. 3. Java uses the Unicode character set and has primitive data types like int and double as well as reference types like classes. 4. Control structures in Java include if/else statements, switch statements, and loops for decision making and repetition. 5

Uploaded by

Sudipti Tiwari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

Java Notes for Class IX

OBJECT an object is an identifiable entity with some characteristics & behavior. E.g. 1 Orange 2 chair
characteristics
1. It is spherical shape and color is orange
2. It has four legs, back and arms
behavior
1. It is citrus in nature and taste sour. 2. It lets you sit on it
Object interact with each other by passing message.
Basic concept of OOP (object oriented programming)
1.Abstraction refers to the act of representing essential features without including the background details or expressions.
2.Encapsulation the wrapping of data and functions into a single unit (class) is known as encapsulation.
3.Inheritance is the capability of one class of things to inherit capabilities and properties from another class.
4.Polymorphism is the ability for a message or data to be processed in more than one form. (function/constructor
overloading).
The object is implemented in software term as follows.
1. characteristics & Attributes are implemented through member variables or data items of the objects
2. behavior is implemented through member function called
methods/function.
Class represents a set of objects that share common characteristics & behavior.
A class is an object maker or object factory. Created objects are known as instance of class.
Source program the program written in high level language by programmer is called source code.
Machine code Computer needs source code to be converted into low level language to be executed
Byte code in java source code is not converted into machine code but is converted in byte code while compilation which
is same for all machines
Compiler/Interpreter They both are used for translating HLL into machine language. Compiler does it at once while
interpreter does it line by line.
JVM Java Virtual Machine is a java interpreter which translates byte code for specific platforms.
Characteristics of java.
1.Write once run anywhere 2. light weight code 3 security 4. built in graphics 5. object oriented language 6. supports
multimedia 7. platform independent 8. open product
Java Character set character set is a set valid characters that a language can recognize (i.e. letters, digit, sign etc.)
Unicode java uses Unicode character set. Unicode is a 2-byte character code set which represents almost all characters
first 128 are identical two ASCII code.
You refer to a particular Unicode by using \u followed by 4-digit hexadecimal number
Tokens the smallest individual unit in a java program is known as token. which are keywords, identifiers, literals,
punctuators, operators.
Keywords are the words that convey a special meaning to the language compiler (if, for etc.)
Identifiers are the name given to different parts of program e.g. variables, objects, class, arrays, function.
Literals are constant i.e. data item that are fixed values i.e. integer, Boolean, character, null, floating, string.
Punctuators separators e.g. (), [], {}
Operators =,>, <, = =, etc.
Data types are means to identify that type of data and associated operation of handling it.
1) primitive (byte, short, int, long, float, double, char, boolean)
2) Reference (class, array, interface).

Type Size Range Initial


Bits Byte Lowest Highest 0
byte 8 1 -128 127 0
short 16 2 -32768 32767 0
31
int 32 4 -2 231 -1 0
long 64 8 -263 263 -1 0
float 32 4 -3.4E+38 3.4E+38 0.0f
double 64 8 -1.7E+308 1.7E+308 0.0d
char 16 2 0 65536 null
boolean 8 but uses true false false
1 bit
all reference type null
Reference in java is a data element whose value is an address.
Scope generally refers to the program region with in which a variable/method is accessible. The broad rule is a variable
accessible with in the set of braces it is declared.
Final keyword final while declaring a variable makes it constant i.e unchanged
Operators operations are represented by operators and objects(values) of the operation are referred as operands.
Unary +, -, ++, —. Binary +, - *, /, % Ternary?
Relational >, <, ==, >=, <=
Logical AND, OR, NOT Bitwise &, |,!, <<, >>
Prefix follow first change then use (e.g. ++c)
Postfix follow first use then change (e.g. c++)
Shortcuts
1. c=c+1  c+=1 2. c=c*4  c*=4
3. x=x-10 x-=10 4. x=x/2 x/=2
Expression in java is any valid combination of operators, constants and variables. It can be pure or mixed. In pure all
the operands are of same data type in mixed they are of mixed data type.
Type conversion the process of converting one predefined type into another is called type conversion.
Implicit(coercion) type conversion is performed by java compiler where smaller data type are promoted into higher data
types.
Explicit type conversion is performed by the user using type operator.
Block is a group of zero or more statements between balanced braces also known as compound statement.
To declare variable that are members of a class the declaration must be within the class body.
Class variable(static) a data member that is declared once for a class. All objects of the class type share these data
members as there is single copy them available in memory.
Instance variable a data member that is created for every object of the class if there are ten objects of a class type there
would be 10 copies of instance variable one each for an object.
new is used to create an object of a class and associate the object with a variable that names it.
Dynamic Initialization: - When a variable is initialized
through a valid expression than it is known as dynamic initialization e.g. int c= a*b*c+4*5;
rvalue (real value) and lvalue (location value)
rvalue :- the value stored in variable
lvalue :- the memory address where the value is stored
e.g. int a=5;
in the example 5 is the rvalue whereas memory address of a will be lvalue
label: labels are typically used on blocks and loops. Labeled blocks are useful with break and continue e.g.: label name:
statements
Type Promotion conversions of all operands up to the type of the largest operand (implicit type conversion)
Escape sequence or non-graphic characters are those characters which can’t be typed from keyboard. Which is
represented by \ followed by one or more characters
Operator precedence: - determines the order in which expression are evaluated.
Operator associatively: Associatively rules determine the grouping of operands and operators in an expression with
more than one operator of the same precedence.
Types of errors.
1.Compile(syntax)time errors: Syntax errors or errors found while compiling a program.
2.Run time error the errors that occur during runtime because of unexpected situations. Such errors are handled through
exception handling routines.
e.g. Of run time errors: - divide zero, index out of bounds
3.Logical errors. Errors in the logic can be found by viewing the output manually.
More information about class
Composite data type
The data type that are based on fundamentals or primitive data types are known as composite data types. Since these
data types are created by users, these are also known as user defined data types.
Class is also composite type.
A class containing main() method cannot be termed as user defined data type it is termed as application.
To create a object.
Point point1 = new Point()
Classname objectname newoperator constructor
Point point1
Declaration do not create objects they are created using new operator.
The dot operator is used to refer to members of an object (e.g. object reference. member name)
Access specifiers
public members are accessible everywhere in the program.
private members are accessible only inside their own class.
protected members are accessible inside their own class, sub class and package.
The default (friendly or package) members are accessible inside their class as well to the classes in the same package.
The default access specifier is friendly which is not a keyword.
An abstract class is the one whose objects cannot be created however other class can inherit from it.
dot (.) the dot(.) accesses instance member of an object or class members of a class.
DECISION MAKING STATEMENTS
1. Sequential construct: - generally the program is executed sequentially i.e. line by line from top to bottom
2. Selection construct: - means the user wants to execute a statement or statements based a particular condition. If
true, then a particular statement(s) and if false then another set of statement(s). For doing so in java if-else and switch
statements are used.
3. Iteration construct: - means the user wants to repeat a set of statement(s) or process again and again depending
upon a particular condition. In java for forming iteration construct for, while and do- while statements are used.
if-else statement: - the if – else statement tests an expression and returns boolean type of value i.e. true or false
if true then the statement(s) given after if statement are executed and if false statement(s) given after else statement are
executed.
Syntax: if(condition)
{
// statement(s) to be executed if condition is true
}
else
{
// statement(s) to be executed if condition is false
}
 ? : (ternary operator):- it can be used instead of if – else statement
Syntax
(condition)?statement(s):statement(s)
example
if(a>b) using ternary operator
c=a; c=(a>b)?a:b;
else // if condition is true then statement after ?
c=b; will be executed if false statement given
after : (colon)sign will be executed
switch statement : it is a multiple-branch selection statement. This selection statement successively tests the value
of a variable against a list integer or character constants.
Syntax :
switch(variable) // value of variable is to matched with
{ //constant given with case statement and when match is found statements given case constant :statement(s)
// after that case are
break // executed, then control
case constant : statement(s) // is transferred outside
break; // switch block using
case constant : statement(s) // break statement. If no
break; //match is found then the
default :statement(s); //control will be transferred to the statement(s) given after default statement
}
if the control flows to the next case below the matching case in the absence of break is known as FALL THROUGH
Values given with each case should be unique i.e. no matching values can be given with case
 dangling else :- when the number of ifs are more then the number of else then it is known as dangling else.
Example :-
if(a>b) // in this example there is a
if(a>c) //confusion that given
System.out.println(a); // else is related with which if
else
System.out.println(b);
To over come this problem {} curly braces are used.
if(a>b)
{
if(a>c) System.out.println(a);
}
else
System.out.println(b);
 differences between if-else and switch case is
a. using if else we can compare more than one values but using switch case we can test only for one value.
b. using switch case we can test only for equality but using if else we can test for >, <, or equality.
c. in switch case only integer and char type values are used. But in if else all data type values can be used.
d. A switch statement is usually more efficient than a set of nested ifs. both if and switch can be used in nested forms.
ITERATION THROUGH LOOPS
Loops are used for repeating a statement or set of statements or a process again and again. For forming a loops three
steps are
1. Initialization
2. Test Condition
3. Updation(increment or decrement)
In java for formaing loops three statements are used they are
1. for loop 2. while loop 3. do-while loop
1. for loop : generally for statement is used when the number of iterations are known or fixed.
Syntax
for(initialization; test condition; updation)
{
//loop body
}
in the syntax of for statement all the three steps are optional but semicolon signs are must.
example.
1. for(;;)// Example of infinite loop
2. int i=0
for(;i<10;)
3. for(i=0;i<10;)
{
i++;
}
More then one initialization and updation can be done in one for statement separated by comma (,) sign.
Example :
for(i=0,s=0;i<10;i++,s++)
2. while and do-while loop : are used when number of iterations are unknown.
Syntax
a. initialization b. initialization
while(test condition) do
{ {
loop body loop body
updation updation
} }while(test condition);
Some examples of loop variations
a. Infinite loop : the loop which never ends is known as infinite loop.
Example
1. for(;;)//steps are not given
{ loop body
}
2. for(int i=0;;i++)//test condition is not given
{ loop body
}
3. for(int i=0;i<10;)//updation not given
{ loop body
}
4. int i=0; 5. while(true)
while(i<10) {
{ loop body
loop body }
}
time delay loop :- if a loop does not contain any statement in the loop body it is said to be empty loop they are used as
time delay loop in the program
examples ;
1. for(i=0;i<10000;i++) 2. int i=0;
{ while(i<10000)
} {
or i++;
for(i=0;i<10000;i++); }

Jump Statements :-these statements are used for transferring the control of program from one part of the program to
another part of the program. The jump statements used in JAVA are 1. break 2. continue 3 return .
Where as a library function System.exit() is used to jump out from program
1. break statement is used with blocks(eg. switch case) or loops to jump out from loop or block to the statement given
just after that block or loop.
Example :
for(i=0;i<10;i++)
{
if(i==5)
break;
System.out.print(i);
}
statement 1.
2. where as continue statement is used to transfer the control to the next iteration
Example :-
for(i=0;i<10;i++)
{
if(i==5)
continue;
System.out.print(i);
}
3. return statement is used to return a value from the function to the function from where that is called or you can say
return statement is used to make the immediate exit from the function within which it is used.
4. Nested Loops : when there are loops inside loop then they are said to be nested loop.
Differences and similarities in loop statements:-
1. for, do – while and while they all are used for forming loops.
2. They both are entry control loops where as do – while is a exit control loop.
3. In while loop if the test condition is false it will not be executed at least once but in do while even if the condition
is false it will be executed at least once.

You might also like