CLanguage
CLanguage
CLanguage
JAVA NOTES
Revision of Class IX Syllabus
Programming paradigms are a way to classify programming
languages based on their features. Paradigm means organizing
principle of a program. It is an approach to programming.
Procedure Oriented Programming: A Procedure oriented
programming approach allows the users to develop their logic by
using a number of functions that would enhance the program’s
productivity.
Example BASIC, COBOL, C
Object Oriented Programming: An Object Oriented Programming
is a modular approach, which allows the data to be applied with
a stipulated program area. It also provides the reusability feature
to develop productive logic, which means to give more emphasis
on data.
Basic Principles of OOP:
1. Abstraction: The act of representing essential features,
without including the background details.
2. Inheritance: Capability of one class of things to inherit
capabilities or properties from another class.
3. Encapsulation: Wrapping up of data and functions into a
single unit.
4. Polymorphism: Polymorphism is the ability for a message or
data to be processed in more than one form.
1
2 Java Notes Class X
Characteristics of Java:
1. Write Once Run Anywhere (WORA): The Java programs
need to be written just once, which can run on different
platforms without making changes in the Java program.
2. Light Weight Code: With Java, no huge coding is required.
3. Security: Java offers many enhanced security features.
4. Object Oriented Language: Java is Object Oriented
language, thereby, very near to real world.
5. Platform Independent: Java is essentially platform
independent. Change of platform does not affect the
original Java program.
Java libraries:
A package is a collection of various classes. Each class
contains different functions.
A package can be inclued in the program by using a keyword
'import'.
ex) import java.io.*;
import java.util.*;
2
3 Java Notes Class X
The (*) sign denotes that all the classes of the concerning
package will be made available for use in your program.
Keywords or Reserved words:
Java reserved words or the keywords are the words which
carry special meaning to the system compiler. Such words
cannot be used for naming a variable in the program.
case , switch, else, break , static, do, const, throws, float , char,
try, int, double, void, goto, for, while, new, import , boolean,
long, if, byte , package, private, catch, short, public, class ,
default.
3
4 Java Notes Class X
f) Null literal has one value, the null reference. A null literal is
always of the null type.
4
5 Java Notes Class X
Data types:
Data Types are means to identify the type of data and
associated operations of handling it.
Two types:
1. Primitive or fundamental or Instrinsic ( predefined)
5
6 Java Notes Class X
6
7 Java Notes Class X
Types:
7
8 Java Notes Class X
Unary operators:
8
9 Java Notes Class X
max = (a > b) ? a : b ;
2) salary = 15000
bonus = ( salary> 10000) ? salary*15/100 : salary*
5/100 ;
9
10 Java Notes Class X
Special operators:
new: dynamically allocate the memory for the object.
Example: example e = new example( );
Operator precedence:
Operator precedence determines the order in which
the operators in an expression are evaluated.
Object is an instance of a class. It is an identifiable entity with
some characteristics and behavior.
10
11 Java Notes Class X
11
12 Java Notes Class X
12
13 Java Notes Class X
Variables
A variable is defined as a location in the memory of the computer
where the values are stored.
13
14 Java Notes Class X
14
15 Java Notes Class X
for is the easiest to understand of the Java loops. All its loop
control elements are gathered in one place(on the top of the
loop)
15
16 Java Notes Class X
POP OOP
Emphasis is given to functions Emphasis is given to functions
and data
=&==
= = =
= is an assignment operator, = = is a relational operator,
used to assign values to a used to check for equality
variable
16
17 Java Notes Class X
Variable Constant
A variable is defined as a A constant is the value which
location in the memory of the is stored in a variable
computer where the value is
stored.
& &&
& is a bitwise operator ( for the && is a logical operator( the
manipulation of data at the bit logical operator evaluates to
level) true value if either of the 2
expressions is true.
Implicit Explicit
Is a conversion of one data It is user defined that forces an
type into another by the expression to be of specific
compiler without the user’s type
intervention
Implicit –E.g. float a=4.5f; int x=66;
double x=987.9998; char c=(char)x;
17
18 Java Notes Class X
Expression Operators
Expression is a combination of Operators : it is a symbol used
operators, constants and to represent logical or
variables. It can be arithmetic, arithmetic operations
relational etc. E.g. : + - * / %
E.g. : u+1/2 at2
Unary and Binary operators
For While
Can be used for only fixed Can be used when the no of
iteration times for a loop to be done is
not known
Can use only char or int type Any data type
18
19 Java Notes Class X
Do while While
Exit controlled Entry controlled
If the condition is false then If the condition is false then the
also the loop will be done loop will not be done at all
once
E.g.: int a=1; int a=1;
While (a>=5) do
{ {
a++; a++;
} }while(a>=5);
loop will not be done even loop will be done at least
once once
/ and %
/ %
Returns the quotient Returns the remainder
E.g.: int c=7/2 answer =3 E.g.: int c=7%2
float c=7/2 answer = 3.5 Answer =1
Compiler Interpreter
It is a software which converts It is a software which converts
high level language into high level language into
machine language as a whole machine language line by line
It is faster Slower
Debugging is harder Debugging is easier
19
20 Java Notes Class X
Print() Println()
The successive output will The successive output will
come in the same line come in a new line
Break Continue
it serves as a terminator from Continue-causes the control to
the enclosed loop,(i.e.) it transfer from within the block
comes out of an inner loop. to the next iteration of the
And transfers the control to the loop.
statement after the loop.
20
21 Java Notes Class X
Operator Precedence
Precedence Operator Type Associativity
15 () Parentheses Left to Right
[] Array subscript
· Member selection
14 ++ Unary post-increment Right to left
-- Unary post-decrement
13 ++ Unary pre-increment Right to left
-- Unary pre-decrement
+ Unary plus
- Unary minus
! Unary logical negation
~ Unary bitwise complement
(type) Unary type cast
12 * Multiplication Left to right
/ Division
% Modulus
11 + Addition Left to right
- Subtraction
10 << Bitwise left shift Left to right
>> Bitwise right shift with sign
>>> extension
Bitwise right shift with zero
extension
9 < Relational less than Left to right
<= Relational less than or equal
> Relational greater than
>= Relational greater than or equal
instanceof Type comparison (objects only)
8 == Relational is equal to Left to right
!= Relational is not equal to
7 & Bitwise AND Left to right
6 ^ Bitwise exclusive OR Left to right
5 | Bitwise inclusive OR Left to right
4 && Logical AND Left to right
3 || Logical OR Left to right
2 ?: Ternary conditional Right to left
1 = Assignment
+= Addition assignment
-= Subtraction assignment
*= Multiplication assignment
/= Division assignment
%= Modulus assignment
21
22 Java Notes Class X
Constructor
Constructor is a special method which is used to initialize
instance/non-static variable.
Properties of constructors
▪ A constructor has the same name as the class
▪ It does not have a return type, not even void
▪ It doesn’t have a calling statement
▪ The constructor gets called when an object is created
Types of constructors
Parameterised
Constructor
Non Parameterised
22
23 Java Notes Class X
Examples:
Parameterized: Non-Parameterized:
1. Int num1, num2, sum; 1. Int num1, num2, sum;
2. Sum(int num1, num2){ 2. Sum(){
3. num1=num1; 3. Sum=0;
4. num2=num2; 4. }
5. }
23
24 Java Notes Class X
Function/Method
Function is a set of Java executable statements enclosed in a
function definition.
Built in methods
Methods
User defined
methods
Advantages of methods:
▪ Reusability
▪ Manage complex programs into smaller parts
▪ Hide details
Method definition/prototype refers to the first line of a method
which contains the access specifier, modifier, return type, method
name and the method signature.
Syntax
24
25 Java Notes Class X
Parameters
Actual Formal
parameters parameters
In method calling In method definition
25
26 Java Notes Class X
Pass/call by reference:
Any change made in the formal parameters
will reflect in the actual parameters
26
27 Java Notes Class X
Method Overloading
Method overloading: Multiple functions sharing the same name
with different parameters/ method signature.
Example:
Arrays
Array: An Array is a set of like variables which are referred to by a
common name. A number called subscript/index is used to
distinguish one from the other.
Syntax
‘n’ denotes the maximum number of elements that the array can
hold.
Assigning values for an Array
Ex:
1. int arr[]={1, 2, 3, 4}
1. int len=arr.length;
27
28 Java Notes Class X
Input a String
1. //For a string without any space (For a single word):
2. <variable>=<Scanner object>.next();
3. Str=sc.next();
4. //For a String with spaces (For a sentence):
5. <variable>=<Scanner object>.nextLine();
6. Str=sc.nextLine();
28
29 Java Notes Class X
String Functions
For all the below examples, str=”COMPUTER”; Output will be displayed as a single line
comment (//).
Quick Tip
.length() (int)
This function is used to return the length of the string.
.charAt() (char)
This function returns the character from the given index.
29
30 Java Notes Class X
.indexOf() (int)
This function returns the index of first occurrence of a
character.
30
31 Java Notes Class X
.toLowerCase() (String)
This function is used to convert a given String to lowercase
letters (entire string).
Syntax with example:
.toUpperCase() (String)
This function is used to convert a given String to uppercase
letters (entire string).
Syntax with example:
31
32 Java Notes Class X
32
33 Java Notes Class X
.trim() (String)
This function removes spaces at the start and end of the
String. (NOTE: This function does not remove spaces in-between
characters)
Syntax with example:
33
34 Java Notes Class X
.equals() .compareTo()
Returns a Boolean value Returns a an int value
It checks for equality between It checks if a String is equal,
two Strings bigger or smaller than the
other.
Difference Between equals() and compareTo() functions
34
35 Java Notes Class X
Library Classes
JDK (Java Development Kit) V1.5 and above contains Java Class
Library (JCL) which contains various packages. Each package
contains various classes containing different built-in functions.
JDK
JCL
Packages
Classes
Functions
Wrapper Class
Wrapper Classes are a part of java.lang (A Library Class Package).
Wrapper classes contain primitive data values in terms of objects/
Wrapper Class wraps a primitive data type to an object. There are
8 wrapper classes in Java. Ex: Integer, Byte, Double
(NOTE: Wrapper Classes always start with an uppercase letter
Ex: Integer, Boolean, Float)
35
36 Java Notes Class X
36
37 Java Notes Class X
Unboxing
Conversion of an object to primitive type data.
Syntax with example:
Autoboxing
Boxing is the mechanism and autoboxing is the feature of
the compiler which generates the boxing code.
Syntax with example:
37
38 Java Notes Class X
Character
Character is defined as a letter, a digit or any special
symbol/UNICODE enclosed within single quotes. Ex: ‘@’, ‘s’, ‘5’
Assigning a character
A Character is declared under char data type.
Syntax with example:
Input a character
A Character is declared under char data type.
Syntax with example:
Character Functions
Character.isLetter() (boolean)
This function is used to check if a given argument is a letter or
not.
Syntax with example:
Character.isDigit() (boolean)
This function is used to check if a given argument is a digit or
not.
Syntax with example:
38
39 Java Notes Class X
Character.isLetterOrDigit() (boolean)
This function is used to check if a given argument is either a
letter or a digit or none of these.
Syntax with example:
Character.isWhitespace() (boolean)
This function is used to check if a given argument is a
blank/gap/space or not.
Syntax with example:
Character.isUpperCase() (boolean)
This function is used to check if a given argument is an
uppercase letter or not.
Syntax with example:
Character.isLowerCase() (boolean)
This function is used to check if a given argument is a or not.
Syntax with example:
Character.toUpperCase() (char)
This function is used to convert/returns a given
argument/character/letter to/in uppercase character/letter.
Syntax with example:
39
40 Java Notes Class X
Character.toLowerCase() (char)
This function is used to convert/returns a given
argument/character/letter to/in lowercase character/letter.
Syntax with example:
Revision/Review Questions
Revision of Class IX Syllabus
1. What is a token? Give examples
2. What are non-graphic characters? Explain their usage in Java
programming language.
3. Name any two OOPs principles. [ICSE 2015]
4. What is a class?
5. Define encapsulation. [ICSE 2016]
6. What is inheritance? [ICSE 2017]
7. What are keywords? Give an example. [ICSE 2016]
8. Define byte code. [ICSE 2010]
9. Name any two types of programs. [ICSE 2007]
10. What is a literal? [ICSE 2013]
11. Rewrite the following using ternary operator [ICSE 2018]
1. if(bill>10000)
2. dis=bill*10.0/100;
3. else
4. dis=bill*5.0/100;
40
41 Java Notes Class X
41
42 Java Notes Class X
MCQ
1. What does compareTo() return? [ICSE 2014]
a) boolean
b) double
c) int
d) A detailed list of analysis of the values of the Strings
2. What does equals() return? [ICSE 2014]
a) int
b) float
c) String
d) boolean
3. Name a function that removes the blank spaces at the start
and at the end of the String. [ICSE 2015]
a) removeSpace()
b) trim()
c) delSpace()
d) Dear Examiner, there is no such function which does
that. -Candidate
4. What is the value of ind if ind=str.indexOf(‘a’); while str=”Tata,
bye bye!”;
a) 2
b) 2,4
c) 1
d) ERROR. Please check the question!
42
43 Java Notes Class X
Question 1:
Choose the correct answer
43
44 Java Notes Class X
44
45 Java Notes Class X
45
46 Java Notes Class X
46
47 Java Notes Class X
Question 2:
Answer the following questions
47
48 Java Notes Class X
System.out.prindn( “best”);
else
System.out.prindn(“invalid”);
Ans.
switch (ch) {
case 1:
System.out .println( “good”);
break; .
case 2:
System.out .println( “better”);
break;
case 3:
System.out.println( “invalid”);
break;
}
9. State the data type and value of res after the following is
executed :
char ch = ‘9’;
res = Character. isDigit(ch) ;
Ans. boolean true
48
49 Java Notes Class X
Question 3:
Write a program to input 15 integer elements in an array and
sort them in ascending order using the bubble sort technique.
Question 4:
Write a program to input a sentence and convert it into
uppercase and count and display the total number of words
starting with a letter ‘A’.
Question 5:
Write a program to input a number and check and print
whether it is a Pronic number [15] or not. (Pronic number is the
number which is the product of two consecutive integers)
Examples : 12 = 3 × 4 .
20 = 4 × 5
42 = 6 × 7
Question 6:
49
50 Java Notes Class X
Member methods
void accept ( ) — To take input for name, coach, mobile number
and amount
void update ( )— To update the amount as per the coach
selected
Type of Amount
Coaches
First_ AC 700
Second_AC 500
Third _AC 250
sleeper None
Question 7:
Write a program to accept name and total marks of N
number of students in two single subscript array name[] and
totalmarks[ ].
Calculate and print:
(i) The average of the total marks obtained by N Number of
students.
[average = (sum of total marks of all the students)/N]
(ii) Deviation of each student’s total marks with the average.
[deviation = total marks of a student – average] ‘
Question 8:
Using the switch statement, write a menu driven program for
the following :
(i) To print the Floyd’s triangle [given below] :
1
23
456
7 8 9 10
11 12 13 14 15
𝑛2 𝑛3 𝑛3 𝑛3 𝑛𝑛+1
(ii) 𝑆 = + + + …+
1 2 3 4 𝑛
50
51 Java Notes Class X
• Revise and integrate the concepts studied in Class IX with the Class X
syllabus.
• Avoid selective study.
• Give equal importance to all the topics mentioned in the syllabus.
• Practise each topic/sub –topic with as many examples as possible.
• Being an application-oriented subject, apply what is taught in the program
and
explain its outcome.
• Give sufficient practice to output-based questions.
• Learn correct use of all statements to eliminate syntax errors.
• Practise programs on various types of loops, their working, conversion from
51
52 Java Notes Class X
one
loop to another and working of nested loop.
• Use proper variable names and ensure that every program has a variable
description table.
• Avoid writing abbreviations like SOP, SOPLN, PSVM.
• Understand the logic of a program instead of memorising it.
• Explain programs using Mnemonic variables and comments.
• After writing the program, dry run it with different inputs.
• Write variable description /Mnemonic codes for every program.
• Read the questions carefully and write the answers according to their
requirements.
• Utilize the reading time to clearly understand the nature of the question.
GENERAL NOTICE
The notes are as per the latest ICSE curriculum (ICSE 2023)
VERSION: CAT2.7.4
A Document of India
COPYRIGHT NOTICE
©2022-2025 FROZENNOTES
Subject to (CC BY-NC-SA) Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
CC- Creative Commons BY – Attribution is Required for this document
NC – Non-Commercial SA – Adaptations must be shared under the same licence
No individual/team/group/organisation/company/cooperate is allowed to earn profit from/with/through this
document.
EDUCATION IS NOT FOR PROFIT
Additional permission requests can be made (Approval guarantee - subject to request)
FROZENNOTES reserves the right to change the terms anytime without (or) with prior notice
Any doubts/questions/suggestions/permission request regarding the document can be sent to
https://frozennotes.github.io/ICSE_Resources (or)
sanjayrohith@outlook.com
Enhanced with Microsoft Editor AI
Not affiliated with Microsoft or CISCE
52
53 Java Notes Class X
Notes
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
53