0% found this document useful (0 votes)
11 views67 pages

Java Icse Notes For Classes 9th and 10th

The document outlines various types of programming languages, including high-level and low-level languages, and categorizes them into procedural, functional, and object-oriented languages. It also explains key concepts in object-oriented programming such as classes, objects, encapsulation, abstraction, inheritance, and polymorphism, along with differences between compilers and interpreters. Additionally, it covers Java's characteristics, data types, operators, and type casting.
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
0% found this document useful (0 votes)
11 views67 pages

Java Icse Notes For Classes 9th and 10th

The document outlines various types of programming languages, including high-level and low-level languages, and categorizes them into procedural, functional, and object-oriented languages. It also explains key concepts in object-oriented programming such as classes, objects, encapsulation, abstraction, inheritance, and polymorphism, along with differences between compilers and interpreters. Additionally, it covers Java's characteristics, data types, operators, and type casting.
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/ 67

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


String
06 January 2021 17:09

String Functions
A sequence of character is called as string.
Egs:- "SKY IS BLUE" String is a class so it contains many functions to perform common operations on string
It's denoted by "". String always start from 0
It's default value is null

String s="SKY IS BLUE"; s.indexOf(' ');

.length() .charAt(index)
It is used to compute the length of the string. It is used to read and return character at a
Egs:- position
Int l=s.length(); Egs:-
l = 11 char c=s.charAt(5);
Length is the only string function that starts c='S'
string from 1.

.indexOf(character/string) .lastIndexOf(character)
It is used to find the first position of the It is used to find the last position of
character/string from the start.If the the character/string.
character is not found it returns -1 If character not found it returns -1.
Egs:- Egs:-
int l=s.indexOf('S'); int l=s.lastIndexOf('S');
l=0 l=5
int p=s.indexOf('A');
p=-1
int q=s.indexOf("IS");
q=3

A starting index can also be given


to search that character from that
index

Notes Class X Page 41


String function
06 January 2021 19:24

k=s.substring(5);
k="S BLUE"
k=s.substring(5,10);
k="S BLU"
k=s.toLowerCase();
k="sky is blue";

String s=" SKY IS BLUE ";


k=s.trim();
k="SKY IS BLUE"

.equals(String)
Checks wether 2 strings are equal or not .isEmpty()
.equalsIgnoreCase(String) To check wether a string is empty or not
Checks wether 2 strings are equal or not ignoring the case boolean b=s.isEmpty();
b=false
.contains(String)
To check wether a string contains a substring or not =null;
="";
.concat(String)
To add 2 strings
k=s.concat("2nd String");
k=SKY IS BLUE2nd String
A alternate to s+"2nd String"

.replace(old char/string,new char/string)


To replace all the occurrence's of given char/string .
k=s.replace('S' , 'A');
k="AKY IA BLUE"

Notes Class X Page 42


String functions S1 ="PROGRAM" // 7
07 January 2021 02:03 S2= "PROGRAMS" // 8

S1. compare to(S2) -1


.compareTo(string)
Used to compare string in lexicographical order(i.e alphabetical order)
Its is case-sensitive , for ignoring the case use .compareToIgnoreCase()

It returns 0 if the 2 strings are equal


+ve if first string comes after in lexographical order
-ve if first string comes before in lexicographical order

It actually gives the difference of ascaii code as output

.replace(oldchar , new char) .startsWith(string) || .endsWith(string)


Used to replace all the characters in a string To check wether a given string starts/ends with the given string or not

.valueOf(any type)
Returns the data In string form

Notes Class X Page 43


String Examples
06 January 2021 20:49

Travelling through string Extracting words from a string

Find occurrence of a char/string in a string

Notes Class X Page 44


String Tokenizer
07 January 2021 02:24

When any string is passed to the string tokenizer , it breaks the string into tokens , each token is a word of the string.

String s="SKY IS BLUE";


StringTokenizer st=new StringTokenizer(s);

It has 3 functions
1. st.countTokens() :- to count the number of tokens
2. st..nextToken() :- to extract the next token from the string tokenizer
3. .hasMoreTokens() :- to check if next token is available or not

If we want our string to be separated by some other character


than white space then we can specify it.

String st=new StringTokenizer(s , "@");

It can be a character or a string , then our word would not be


separated by space

Notes Class X Page 45


String Buffers
07 January 2021 02:32

Strings are immutable that is they can't be changes once they are created so to make them mutable we use StringBuffer

Notes Class X Page 46


Arrays
09 January 2021 21:20

Collections of similar type of data under one variable in linear form.


They also have index's and it starts from 0.

Notes Class X Page 47


String as array
09 January 2021 22:25

String is a sequence of characters so string can be represented as a character array.

Notes Class X Page 48


Linear Sort
09 January 2021 21:37

We select element at first index and


compare it with rest elements and see
for the smallest element and place it at
the first position

Notes Class X Page 49


Selection Sort
09 January 2021 21:48

We select the index of lowest element


and put it at it's appropriate position
i.e we compare the first element with
rest and store the index of lowest
element after that we swap the index's

Notes Class X Page 50


Bubble Sort
09 January 2021 21:58

We compare the current element to next ,


and if it's greater then we swap it

Notes Class X Page 51


Linear Search
09 January 2021 22:02

We simply travel to each position of the array and check for


charatcter

Notes Class X Page 52


Binary Search
09 January 2021 22:06

We first need to have a sorted array.

We move to the side containing the element

Notes Class X Page 53


2-D ARRAY
09 January 2021 22:22

Printing a 2d array

Notes Class X Page 54


2d - array
09 January 2021 22:35

Notes Class X Page 55


METHODS IN JAVA
10 January 2021 23:29

The functions defined inside


Collection of statements grouped together to perform certain tasks. the class are called as instant
Also known as functions methods/member methods
A function is only run when they are called.
The variables are called as data
members

Every function consists of 3 things


1. Return type :- the type of data it will return
2. Function name :- any name of the function
3. Parameters :- parameters to be passed if any

A function with no return has it's return type as void


Return is used to terminate a function.(3rd type of jump statement)

We use methods to make our code modular (i.e divide the code into pieces) and for reusability.

The first line of the function is know as prototype of the function.

New keyword is used to


reallocate memory for a
new object

The paramater's that


are passed during the
call of the function are
called as actual
parameters.

The parameters that are


used during the
declaration of function
are called as formal
paramters

Notes Class X Page 56


Call by value vs Call by reference
11 January 2021 18:57

Changes made in the Changes made in the


formal parameters are formal parameters are
not reflected back in the reflected back in the
actual parameters actual parameters

Happens with primitive Happens with


data types reference data type

A copy of the actual the actual parameter is


parameter is made and itself used and then the
then the function uses it function uses it

Output:

Notes Class X Page 57


Static and Non-Static
14 January 2021 15:30

Static variable/method is a
variable/method that belongs to the
class (not to any particular object)
It is shared across all the objects

By default every member in java is non-


static i.e it belongs to object unless
static keyword is specified

Non-static can access both static and


non-static
static can only access static , to access
non-static we have to create make use
of objects.

Notes Class X Page 58


Notes Class X Page 59
this keyword
14 January 2021 15:57

this refers to the current calling object

Notes Class X Page 60


Polymorphism
14 January 2021 16:34

We can change the parameters of the function

Notes Class X Page 61


Pure and impure methods
14 January 2021 16:43

Pure methods :
Those who don't change the state of the variable
Impure Methods :
Those who change the state of the variable.

Notes Class X Page 62


Constructor
14 January 2021 16:49

A function having same name as that of class


It has no return type.
It is the only function which runs automatically when an object is created.

Default constructor
It is a constructor that is created automatically by the compiler and it initialises the values to the data
members , if we have not created a constructor.

Parametersied Constructor
A constructors with parameters.

Non-paramterseid Constructor
A constructor with no
paramaters

Notes Class X Page 63


Constructor Overloading
14 January 2021 17:01

When more than 1 constructor is created in


the same class having different paramters then
it is known as constructor overloading

Notes Class X Page 64


Wrapper Class
31 January 2021 13:12

Wrapper class is a class whose object wraps the primitive data type.
Value of primitive type in object form

Use of Wrapper Class :-

1.Converting from strings to number or other data types


2.To store primtive types as an object so that they can
be passed usnig call by references

Notes Class X Page 65


Boxing in Java
31 January 2021 13:21

Boxing / Unboxing

The conversion of wrapper class back to it's primitive form is known as unboxing / boxing.

int a=new Integer(5);


Here a is an primtive data type while new Integer(5) is an object and it gets automatically
converted to primtive data type , this is called as unboxing.

Autoboxing

The automatic converison the Java compiler makes from the primitive type to their respective wrapper class

In this we are creating an object of type Integer and passing 5 as primtive data type
Interger number=new Integer(5);

Now we can do the same thing like this


Integer number=5;

In this case 5 would automatically be coverted into Integer obejct, this is called as autobxing

Notes Class X Page 66


Methods in Wrapper Class
31 January 2021 13:28

Converts from String to respective primtive data type Each of the wrapper class contains an constant named MAX_VALUE and MIN_VALUE

They store the maximum and shortest range of that data type

Egs:-

Double.MAX_VALUE

.toString()
Method in character type
Converts an object to string

.valueOf()

Converts an string s into the respective wrapper class.( not primitive type as in case of .parse

Notes Class X Page 67

You might also like