ICSE 10th Notes
ICSE 10th Notes
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
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, 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:
Assigning a character
A Character is declared under char data type.
Syntax with example:
1.
2. ;
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:
40
41 Java Notes Class X
41