Sei sulla pagina 1di 5

Introduction:

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.

Types of Java Applications


There are mainly 4 types of applications that can be created using java programming:
1) Standalone Application
It is also known as desktop application or window-based application. An application that we need to install on
every machine such as media player, antivirus etc. AWT and Swing are used in java for creating standalone
applications.
2) Web Application
An application that runs on the server side and creates dynamic page, is called web application. Currently,
servlet, jsp, struts, jsf etc. technologies are used for creating web applications in java.
3) Enterprise Application
An application that is distributed in nature, such as banking applications etc. It has the advantage of high level
security, load balancing and clustering. In java, EJB is used for creating enterprise applications.
4) Mobile Application
An application that is created for mobile devices. Currently Android and Java ME are used for creating mobile
applications.

Java Platforms / Editions


There are 4 platforms or editions of Java:
1) Java SE (Java Standard Edition)
It is a java programming platform. It includes Java programming APIs such as java.lang, java.io, java.net,
java.util, java.sql, java.math etc. It includes core topics like OOPs, String, Regex, Exception, Inner classes,
Multithreading, I/O Stream, Networking, AWT, Swing, Reflection, Collection etc.
2) Java EE (Java Enterprise Edition)
It is an enterprise platform which is mainly used to develop web and enterprise applications. It is built on the
top of Java SE platform. It includes topics like Servlet, JSP, Web Services, EJB, JPA etc.
3) Java ME (Java Micro Edition)
It is a micro platform which is mainly used to develop mobile applications.
4) JavaFx
It is used to develop rich internet applications. It uses light-weight user interface API.
Page 1 of 5
Object-Oriented Programming is a methodology or paradigm to design a program using
classes and objects. It simplifies the software development and maintenance by providing some concepts:
Object
Class
Inheritance
Polymorphism
Abstraction
Encapsulation

Class and Object:


In object-oriented programming , a class is a template definition of the methods and variables in a particular kind of
object .
An object is a specific instance of a class; it contains real values instead of variables. The class is one of the defining ideas
of object-oriented programming.
Class
Collection of objects is called class. It is a logical entity.
Note :Constructor in java is a special type of method that is used to initialize the object.
Java constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object
that is why it is known as constructor.
There are basically two rules defined for the constructor.
1. Constructor name must be same as its class name
2. Constructor must have no explicit return type
Example
Class A{
A ( ) {} // constructor of class A
}
If there is no constructor in a class, compiler automatically creates a default constructor.
Object
Any entity that has state and behavior is known as an object. For example: chair, pen, table, keyboard, bike etc.
It can be physical and logical.
Example:
String s; here s is object of String class
A obj; here obj is object of A class

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.

Syntax of Java Inheritance


class Subclass-name extends Superclass-name
{
//methods(action) and members(properties)
}

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.

Note: Multiple inheritance is not supported in java through class.


In java programming, multiple and hybrid inheritance is supported through interface only.

Why multiple inheritance is not supported in java?


To reduce the complexity and simplify the language, multiple inheritance is not supported in java.
When a class extends multiple classes i.e. known as multiple inheritance. For Example

Page 3 of 5
The access modifiers in java specifies accessibility (scope) of a data member, method, constructor or class.

There are 4 types of java access modifiers:

1. private - The private access modifier is accessible only within class.


2. default - If you don't use any modifier, it is treated as default bydefault. The default modifier is accessible only
within package.
3. protected - The protected access modifier is accessible within package and outside the package but through
inheritance only.
4. public - The public access modifier is accessible everywhere.

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

Methods of String class:

Method Example Output


concat( String st) s.concat(ram) HAPPYram
length() s.length() 5
substring(startindex,endindex) s.substring(2,3) P
toLowerCase() s.toLowerCase() happy
toUpperCase() s.toUpperCase() HAPPY
tostring s.toString() HAPPY
trim s.trim() HAPPY

class math:

Page 5 of 5

Potrebbero piacerti anche