Notes For Class XII
Notes For Class XII
Notes For Class XII
What is Java
Java is a programming language and a platform.
Java is a high level, robust, secured and object-oriented programming language.
Platform: Any hardware or software environment in which a program runs, is known as a platform. Since Java
has its own runtime environment (JRE) and API, it is called platform.
Where it is used?
According to Sun, 3 billion devices run java. There are many devices where Java is currently used. Some of
them are as follows:
1. Desktop Applications such as acrobat reader, media player, antivirus etc.
2. Web Applications such as irctc.co.in, javatpoint.com etc.
3. Enterprise Applications such as banking applications.
4. Mobile
5. Embedded System
6. Smart Card
7. Robotics
8. Games etc.
Inheritance
When one object acquires all the properties and behaviours of parent object i.e. known as inheritance. It
provides code reusability. It is used to achieve runtime polymorphism.
Inheritance represents the IS-A relationship, also known as parent-child relationship.
The extends keyword indicates that you are making a new class that derives from an existing class. The
meaning of "extends" is to increase the functionality.
Page 2 of 5
In the terminology of Java, a class which is inherited is called parent or super class and the new class is called
child or subclass.
Example:
Programmer is the subclass and Employee is the superclass. Relationship between two classes is Programmer
IS-A Employee.It means that Programmer is a type of Employee.
class Employee{
float salary=40000f;
}
class Programmer extends Employee{
int bonus=10000;
}
Coding in button (main programme) {
Programmer p=new Programmer();
System.out.println("Programmer salary is:"+p.salary);
System.out.println("Bonus of Programmer is:"+p.bonus);
}
Types of inheritance in java
On the basis of class, there can be three types of inheritance in java: single, multilevel and hierarchical.
Page 3 of 5
The access modifiers in java specifies accessibility (scope) of a data member, method, constructor or class.
Polymorphism
Ability of Method to execute in many forms.When one task is performed by different ways i.e. known as
polymorphism. In java, we use operator overloading ,method overloading and method overriding to achieve
polymorphism.
Example: Operator Overloading
Arithematic + operator and Concat + operator
Method Overloading
1)round() method of Math class - overloaded on the basis of the data type of argument supplied
int a = Math.round(12.5f); here argument is of float type.
float b= Math. Round (123.6789); ); here argument is of double type
2) substring() method of String class- overloaded on the basis of the number of argument supplied
String d= good Morning;
System.out.print (d. substring(5); here only one argument is passed
System.out.print (d. substring(0,4); here two argument are passed
Abstraction
Hiding internal details and showing functionality is known as abstraction. It is not essential to declare
objects to use an abstract class. Abstract classes are used for defining generic methods where there is no
requirement of storing results.
abstract keyword is used to declare a class as Abstract class. Example : JOptionPane class
Page 4 of 5
Encapsulation
Binding (or wrapping) code and data together into a single unit is known as encapsulation. For example:
capsule, it is wrapped with different medicines.
A java class is the example of encapsulation. Java bean is the fully encapsulated class because all the data
members are private here.
Wrapper class in java provides the mechanism to convert primitive into object and object into primitive.
Int i=Integer.valueOf(a);//converting int into Integer
class String
the java.lang.String class provides a lot of methods to work on string. By the help of these methods, we can perform
operations on string such as trimming, concatenating, converting, comparing, replacing strings etc.
Example:
String s = HAPPY
Character Index 0 1 2 3 4
Character Stored H A P P Y
class math:
Page 5 of 5