88% found this document useful (57 votes)
60K views40 pages

Computer Notes Class 9TH Icse

The document discusses different types of programming languages and features of object-oriented programming. It describes high-level languages as those that can be easily understood by humans, while low-level languages are closer to computers and harder for humans to understand. It also defines procedural, functional, and object-oriented languages. The document then discusses classes and objects in object-oriented languages, describing classes as blueprints and objects as instances of classes. It lists the main features of object-oriented programming as encapsulation, abstraction, inheritance, and polymorphism.

Uploaded by

vishal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
88% found this document useful (57 votes)
60K views40 pages

Computer Notes Class 9TH Icse

The document discusses different types of programming languages and features of object-oriented programming. It describes high-level languages as those that can be easily understood by humans, while low-level languages are closer to computers and harder for humans to understand. It also defines procedural, functional, and object-oriented languages. The document then discusses classes and objects in object-oriented languages, describing classes as blueprints and objects as instances of classes. It lists the main features of object-oriented programming as encapsulation, abstraction, inheritance, and polymorphism.

Uploaded by

vishal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Types of Languages

21 December 2020 19:41

Types of programming languages


1. High-level Language
Language near to the user and far from the computer , i.e can be easily
understood by humans
2. Low-level language
Language near to the computer and far from the USER , i.e can't be easily
understood by humans

5,6
{
Output 5+6
}

They can be also classified as


1. Procedural Programming Language
A sequence of statement is followed which leads to the result.
2. Functional Programming Language
They are primary focused on functions (a block of code to perform some task)
3. Object-Oriented Language
These treats everthing as an objects ( a entity with some data and functions)

Notes Class X Page 1


What are classes and Objects ?
21 December 2020 23:46

Java is an Object Oriented Language!


So what actually are objects ?

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 !

The data of the class is called as member data


The functions of the class are called as member functions

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.

More will be discussed on classes and objects later !

Notes Class X Page 2


Feature of OOP's
22 December 2020 00:04

The main features of OOP's are


1.Encapsulation
2.Abstraction
3.Inheritence
4.Polymorphism

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

Notes Class X Page 3


Compiler vs Interpreter
22 December 2020 00:14

Compiler
It executes the whole program at once
Interpreter
It executes the whole program line by line

Flow of code in Java

Java has 2 compilers : javac and jit


Java has 1 Interpreter :- JVM

Notes Class X Page 4


Java Compiler || JVM
22 December 2020 00:19

Java has 2 compiler


1.javac
2.jit
Java Byte Code
javac It is a machine independent code and can
It converts the whole program to byte code at once be termed as the machine instructions for
the JVM(Java virtual machine)
jit(Just in time) It can be in simple terms termed as
It compiles the most frequently used commands only once and hence improving the binary code in 0/1 form and thus can be
efficiency of the program. converted by the JVM from the source code
that we write and thus making it readable
After javac and jit have compiled the program , the code can be send to across any device and then through JVM can be by every device in the world .
executed on any device

JVM(Java Virtual Machine)


The programs written in Java are first compiled to byte
code and then are interpreted by a special java interpreter
that is unique for each machine/platform , this is known as
Java Virtual Machine.

Notes Class X Page 5


Characterstics of Java
22 December 2020 00:32

Types of Java Program

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

Notes Class X Page 6


Tokens
23 December 2020 15:21

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)

Fixed data values are called as literals.

3.Punctuators

They separate or connect parts of code


NAME= "ARYAN" with each other

NAME= "AKASH" They are :-


, (comma), ; (semicolon), . (period), (,)
(group of parenthesis), {,} (Pair of
braces), [,] (pair of square brackets).

4.Operators

They are used to perform certain actions


on operands(variable or literals ) to
gain some useful results.

Notes Class X Page 7


Character Set
27 December 2020 02:25

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.

Java uses Unicode as it's character set.

Unicode is a universal international standard encoding system , that’s capable of


representing most of the world's languages.
ASCII code is the American Standard Code for Information Interchange.

ASCII code Unicode


It is a 7 bit system It is a 16-bit set
It ranges from 0 -255 i.e total 256 It ranges from 0 - 65535 i.e total 65536 charatcers
characters
It comprises of all english alphabets The first 0 -255 characters are same as ASCAII code but it
along with some additonal special also includes characters of many languages apart from
characters english.
Represtend by \uXXXX , where XXXX is 16 bit representation of
the character
Egs:- 'A' -> 65 , '_' -> 32 Egs:- A -> \u0041 , \u0000 -> null character.

a-z 97 - 122 98 , 99 ---


A-Z 65 - 90
_ (space) 32

Base 10 / decimal

Notes Class X Page 8


Escape Sequences
27 December 2020 02:25
\t -> tab space
\u -> follows a unicode charatcer
\b -> backspace
\n -> new line
Ggfdgdh
gdhdhbf

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.

\\ -> \

\\ -> \

Carriage return , generally moves the output text in


the next line without moving the cursor to the next
line.
Form feed means a page break , (it’s quite old and not
used now)

Questions:-

Output when :-
\\\" --> \"
\" --> "
\a --> a

Notes Class X Page 9


Data Types
27 December 2020 03:25

They specify the type of data a variable can hold. a

They are of 2 types :-


1. Primitive data type -> predefined by the compiler
2. Non Primitive data type / User defined / Referential

Data Types

Primitive Non Primitve

Numeric Non-numeric Class Array Interface String

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.

Notes Class X Page 10


Data Type
27 December 2020 03:51

Type Size Range 1. Byte


a. It represents 8 bits of storage
byte 8 bits -128 to 127 b. Is used to store very small numbers.
char 16 bits 0 - 255 c. Not used in general
d. Egs:- 10 , -20
short 16 bits -32,768 to 32767
2. Char
int 32 bits -2^31 to 2^31 - 1 a. Represents a single character
long 64 bits -2^63 to 2^63 - 1 b. Surrounded by single quote.
c. Its range is \u0000 to \u65535
float 32 bits upto 7 decimal
d. Egs:- 'a' , '4' , 'A'
double 64 bits upto 16 decimal 3. Short
boolean 1 bit true/false a. It is also used to store numbers in small range
b. Not used generally
c. Egs:- 2000 , - 500
4. Int
a. Generally used for storing integers
b. Means number without decimal point
c. Egs: - 100000 , 200 , 10
5. Long
a. Used when integer can’t meet our needs of range boolean male = true;
b. Egs:- 10000L , 200L
c. L represents long.
6. Float
a. Used to store decimal number
b. Not generally in Java
c. Not used when we require precise result as it supports only 7 decimals
d. Egs:- 234.6F
e. F represents float.
7. Double
a. a.generally used to store decimal numbers.
b. It very precise
c. Egs:- 234.6 , 45.0 , -29.2 , 29.2D
8. Boolean
a. Used to track conditions.
Both are valid
b. Can be either true or false
c. Egs; true , false

Notes Class X Page 11


Program #1
27 December 2020 04:24

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

int product= num1 * num2;

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);
}
}

Notes Class X Page 12


Operators
23 December 2020 19:51
2.Assignment Operators

Used to assign values to the variables


Operators are divided into following groups :-

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

Used to perform mathematical operations

4.Comparison/Relational Operators

Used to compare 2 values

3.Unary operators

They require only 1 operand.

Number % 2 = 0 int num1 = 5;

Number % 2 = 1

Notes Class X Page 13


Operators
23 December 2020 20:01
true && true

False || true

4.Logical Operator's Ternary Operator

Used to determine logic between variable/values. Only conditional operator that takes 3 operands.
Its and replacement for if-then-else

Symbol--> ? :

5.Java Bitwise Operators

Used to perform binary logic with bits of interger

Egs:-
num1 = 10;
num2 = 20;
res=(num1>num2) ? (num1+num2):(num1-num2)
Since num1<num2,
the second operation is performed

Notes Class X Page 14


res=(num1>num2) ? (num1+num2):(num1-num2)
Since num1<num2,
the second operation is performed
res = num1-num2 = -10

Notes Class X Page 15


Precedence of Operator
27 December 2020 04:22

Certain operators have higher precedence than others and therefore precedence of operator decides how an expression
should be evaluated.

Arithmetic > Relational > Logical Boolean b= 5>6 && (6+7)<4 + 9;

In Arithemtic:- BEDMAS rule is followed ( Bracket Exponent Division/Multiplication Addition/Subtraction


In Logical :- NAO rule ( NOT > AND >OR)

ICSE 2015

Notes Class X Page 16


PREFIX/INFIX/POSTFIX
28 December 2020 15:36

In an expression there are 2 things , operators and operands. 5 + 6 -- infix

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.

Infix:- If the operator is between the operands in the expression.


b+c
Prefix:- If the operator is before the operands in the expression.
+bc
Postfix:- If the operator is after the operands in the expression.
Bc+

Notes Class X Page 17


Increment & Decrement operator
28 December 2020 15:42

Both preorder and postorder do the same thing that is


Earlier we have seen the ++ and -- operator. increase(++) or decrease (--) the value of variable by 1.
But there is a slight difference.
a=++a;
These operator can also be put as post-order or pre-order
In post-order expression, the variable is first used and then
POST ORDER a++ increased.
In pre-order expression , the variable is first increased and then
a-- a=5; used.
a++;
PRE ORDER a=6;
a--;
++a a=5;

a=5; //5
a=a++;
A //6

v=x+ --z + y++ + y;

v=2 + 0 + 3 + 4; v=9

Notes Class X Page 18


Type Casting
28 December 2020 16:01

Conversion of one type of data to another Implicit Casting :- Explicit Casting :-


It is of 2 type 1. done automatically by the compiler 1. Done forcefully by the user
1. Implicit 2. Lower data type to higher data type 2. Higher data type to lower data type
2. Explicit 3. Loss of data is not there 3. Loss of data is there

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

Notes Class X Page 19


Mathematical functions
28 December 2020 16:10

Packages are a way to encapsulate a group of classes together.


Some packages in java are:- Math.pow(2,3)

4.2 -> 4
4.6->5

Java.lang package contains all the functions for mathematical operation.

Math.rint() returns the closest even interger

Notes Class X Page 20


Mathematical functions
31 December 2020 01:44

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

Notes Class X Page 21


Control Structure's
31 December 2020 01:55

They specify the flow of the program.


The program can be more clear and understood if
they use self-contained modules called as control
structures.

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)

Notes Class X Page 22


If you want to interept the flow of program and terminate it then you can use System.exit(0)
It actually terminates the JVM.

Notes Class X Page 23


Selection Statements
31 December 2020 02:15

They are of 3 types


1.The if - statement
1.if
2.if-else It tells whether a specific part of code would be executed or not.
3.switch i.e if a condition is true then the part of code is executed else its not.

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.

Notes Class X Page 24


If-else
31 December 2020 02:33

We can add an else block to the if statement that runs if the if statement is false.

Notes Class X Page 25


If-else-if
31 December 2020 02:40

We can combine else and if statements to make a ladder of conditions .


i.e until a condition is satisfied it jumps to the next condition.

Dangling if problem

Notes Class X Page 26


Notes Class X Page 27
Switch statement
31 December 2020 02:45

Used when one block of code is to be executed among several blocks.

If no block of code is matched then the default block runs.

The break statements break the flow of switch block and shifts the
control to the line following the switch statement.

Both default and break are optional

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

As default statement is generally the last statement therefore break is


optional.

They are also called Menu driven as out of several options only one is
selected and executed.

Notes Class X Page 28


Nested Statements(if)
31 December 2020 03:04

Nested means one within another.


Therefore one if can be put within another if to check several conditions.

Notes Class X Page 29


COMMENTS
31 December 2020 03:12

They are statements that are ignored or not executed by java.


They are used to provide explanation about any part of code. //this is a single line comment
They are of 2 type
1. Multi-line comments /* ffgdgfbbfgnbfg */
2. Single-Line comments

Notes Class X Page 30


Streams
03 January 2021 12:57

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

In this , InputStreamReader is used as a


bridge between byte stream and
character stream.

Above both always reads data in form of String.

In this br can be replaced by dis (datainputstream) if you are using it.

Notes Class X Page 31


DIS - 2
03 January 2021 14:42

Notice the import java.io.* in the Both datainputstream and buffered


first line , it is used to include the reader throw error unknown to the
package for input/output java compiler therefore we use
operations throws IOException to throw the
input/ouput errors from the program

Notes Class X Page 32


Here we see a new thing that in
print statement the expression
inside it is evaluated first.

javac command is used to


compile the program , it
converts the .java file to .class
file

java command is used to


execute our class file.

Notes Class X Page 33


Scanner
03 January 2021 14:53

Used to take input in primitive data types.


It used java.util class.
Throws no unknown excpetion
to the compiler.

Notice the util class and no throws exception after the main function

Notes Class X Page 34


Errors in java
03 January 2021 15:00

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

Notes Class X Page 35


Iterative Constructs
03 January 2021 15:13

They are the looping statements that is Loops are of 2 types


they are used to execute a part of code 1. Entry controlled loop :- condition is checked first before executing the body of the loop
multiple times. 2. Exit controlled loop :- condition is checked after executing the body of the loop.

Entry controlled loops are of 2 types


1. For loop
2. While Loop

Exit controlled loop is of 1 type


1. Do-while loop

Notes Class X Page 36


For loop
03 January 2021 15:24

Phase 1 Phase 2

First the variable in initialised and then checked with the


condition , if condition is true then body of loop is executed
After that the value of variable is updated according to updating
statement and then checked with the condition

Notes Class X Page 37


Jump Statements
04 January 2021 20:11

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.

Notes Class X Page 38


While Loop
04 January 2021 20:49

Infite loop

Notes Class X Page 39


Prime number
04 January 2021 21:08

Notes Class X Page 40

You might also like