Computer Notes Class 9TH Icse
Computer Notes Class 9TH Icse
5,6
{
Output 5+6
}
For now , objects can be considered as an entity with some data and some certain actions
to be performed on data !
Objects are blueprint of Class !
i.e class is the layout of an object !
Classes :-
It is the entity that binds the data and functions performed on data in a single
independent entity !
Objects:-
They are the real entities and are exact copy of the class .It is through objects that we
manipulate the data/functions of the class.
1.Encapsulation
The binding and wrapping up of data and the function performed on data in a single unit called class is
known as encapsulation.
It is enabled by the keyword 'class'
2.Abstraction
The act of representing only essential features without including the background detials
3.Inheritence
When properties of 1 class are taken (inherited) from another class
The class that takes the properties are called as child/derived/sub - class
The class that gives the properties are called as parent/base/super - class
4.Polymorphism
Single entity, many forms.
One function behaves differently for different objects
Compiler
It executes the whole program at once
Interpreter
It executes the whole program line by line
Multi-threading:-
Program is partitioned into modules which reduces the complexity of program
and creates a well defined boundey for the programs.
Secure
There is no direct access to the ram , in between lies the JVM
Typed-language
Each variable is specified with the type of data it will hold
1.Keywords
What are tokens ?
These are words that convey special meaning to the compiler
These are 57 in number
The smallest individual unit in a java program.
They include true , false , null.
They are of 5 types :-
1.Keyword
2.Identifier
3.Literals 2.Identifiers & Literals
4.Punctuators
5.Operators Identifiers are named memory location used to store temporary
constants.(literals)
3.Punctuators
4.Operators
Character Set
A set of graphical and textual symbol each of which is mapped to a positive integer.
A -> 65
Character Set in Java
Set of alphabets , letters (including special characters)that are valid in Java language.
Base 10 / decimal
A character preceded by \ (backslash) is known as escape sequence and hold a special meaning to the compiler.
Java has a total of 8 escape sequences.
They are used to print non graphical characters.
\\ -> \
\\ -> \
Questions:-
Output when :-
\\\" --> \"
\" --> "
\a --> a
Data Types
Integer float double Char Boolean Note: they are referential data type i.e
instead of storing the value of the literal
they store the location of the literal.
Write a program(WAP) to assign two numbers and then calculate their sum,difference,product,division in sepeate
variables and then print them .
datatype variable=value;
Each line is terminated by a semicolon
Name of the class should start with a alphabet, can be folllowed by number
Assignment vs declaration.
class mathoperation
{
public static void main(String at[]) PUBLIC STATIC VOID MAIN
{
int num1=5,num2=6;
Int num1=5;
int sum=num1 + num2; 11
int num1; --> declaration
int diff=num1 - num2; num1=5; --> assignment
double div=num1/num2;
"" -> string -> sequence charatcers
System.out.print("Sum= "+sum); "HELLO WORLD"
System.out.println("Difference= "+diff); 'a' -> character
System.out.println("Product= "+product);
System.out.println("Division= "+div);
}
}
1.Arithmetic Operators
2.Assingment Operators
3.Unary Operators They also have a special type called as short-hand operators
4.Comparison/Relational Operators
5.Logical Operators
6.Bitwise Operators
7.Miscleneous Operators
1.Arithemetic Operators
4.Comparison/Relational Operators
3.Unary operators
Number % 2 = 1
False || true
Used to determine logic between variable/values. Only conditional operator that takes 3 operands.
Its and replacement for if-then-else
Symbol--> ? :
Egs:-
num1 = 10;
num2 = 20;
res=(num1>num2) ? (num1+num2):(num1-num2)
Since num1<num2,
the second operation is performed
Certain operators have higher precedence than others and therefore precedence of operator decides how an expression
should be evaluated.
ICSE 2015
b + c -> 5 6 + -- postfix
Here b and c are the operands and + is the operator.
+ 5 6 -- prefix
Now we can put this + operator in 3 ways
1. +bc
2. b+c
3. bc+
Noticed how the operator was put at different locations but all means the same.
a=5; //5
a=a++;
A //6
v=2 + 0 + 3 + 4; v=9
Implicit
byte -> short -> char -> int -> long -> float -> double
Double a=45;
Explicit
a=66; a=45.0
double -> float -> long -> int -> char -> short -> byte
char ch=(char)a;
Double a=45.5;
Egs:-
Int num=(int)a;
double a=45.5;
Num=45;
a= int b=(int)a; --> 45
double a=45;
Int a='A';
int a='A';
Int a=66;
char ch=(char)a;
Ch-> B
4.2 -> 4
4.6->5
Math.rint(5.5) -> 6.0 QUES 2. WAP TO ASSIGN TWO NUMBERS AND SWAP THEM USING A THIRD VARIABLE !
QUES3. WAP TO ASSIGN TWO NUMBERS AND PRINT THE GREATER AND SMALLER OUT OF THEM WITH
56.99 APPROPRIATE MESSAGE !
Floor->56.0
Ceil->57.0
1.Sequential
They are of 3 types
Program is execute line by line i.e a
1. Sequential
sequence is followed.
2. Selection
3. Iteration
2.Selection
Different part of the code are
executed on different condition
3.Iteration
A specific part of code is run again
and again till a condition is
satisfied.
If you want to interept the flow of program and terminate it then you can use System.exit(0)
If only one statement has to be written in the if block then curly braces are optional.
i.e If curly braces are not their then if only consider its next statement under it's block.
We can add an else block to the if statement that runs if the if statement is false.
Dangling if problem
The break statements break the flow of switch block and shifts the
control to the line following the switch statement.
Default can be written anywhere within the switch case i.e it's not
compulsory to write it at last.
Use of break :-
If we don't put break statement after every case then all the cases
following the matched case will be executed unless break statement is
not found or switch case ends.this is also called as fall-through
conditon in switch
They are also called Menu driven as out of several options only one is
selected and executed.
Streams means flow of data Buffer memory : a temporary memory where data is stored before sending to ram
They are of 3 types Java uses 2 types of stream for input/output operations.
1. Input Stream :- flow of data ready for input
2. Output Stream :- flow of data ready for output
3. Error Stream :- flow of data ready to throw error Character Stream Byte Stream
Performs operation on unicode system Performs operation on 8-bit system
Conversion of data is not required Conversion of data is required
Does not requires buffer memory Requires buffer memory
Egs:- Egs:-
DataInputStream InputStreamReader , BufferedReader
Notice the util class and no throws exception after the main function
An operation performed by the user that results in abnormal working of the program RUN TIME ERROR
They are of 3 types Errors that occur during the execution of the program.
1. Run time error Egs:- Math.sqrt(-4);
2. Syntax error
3. Logical error SYNTAX ERROR
Errors that occur during the compilation of the program
Egs:- int x;y;
Logical error
Error that produces different output / unexpected output.
Egs: using a > b instead of b >a
Phase 1 Phase 2
Break Continue
They are of 2 types It terminates the current It skips the current
1. Break iteration of the loop and iteration of the loop
2. Continue shifts the control to the and shifts the control
statement following the to the next iteration
loop.
Infite loop