Java Unit 1
Java Unit 1
What is JAVA
• Java is a programming language and a platform. Java is a high level, robust, object-
oriented and secure programming language.
• Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the
year 1995. James Gosling is known as the father of Java. Before Java, its name
was Oak. Since Oak was already a registered company, so James Gosling and his team
changed the Oak name to Java.
• Platform: Any hardware or software environment in which a program runs, is known as
a platform. Since Java has a Runtime Environment (JRE) and API, it is called a
platform.
Java Applications
According to Sun, 3 billion devices run Java. There are many devices where Java
is currently used. Some of them are as follows:
• Desktop Applications such as acrobat reader, media player, antivirus, etc.
• Web Applications such as irctc.co.in, javatpoint.com, etc.
• Enterprise Applications such as banking applications.
• Mobile
• Embedded System
• Smart Card
• Robotics
• Games, etc.
Types of Java Applications
1) Standalone Application
Standalone applications are also known as desktop applications or window-based
applications. These are traditional software that we need to install on every machine.
Examples of standalone application are 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 a dynamic page is called a
web application. Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc.
technologies are used for creating web applications in Java
Types of Java Applications
3) Enterprise Application
An application that is distributed in nature, such as banking applications, etc. is
called enterprise application. It has advantages of the high-level security, load balancing,
and clustering. In Java, EJB is used for creating enterprise applications.
4) Mobile Application
An application which is created for mobile devices is called a mobile application.
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 the Java SE platform. It
includes topics like Servlet, JSP, Web Services, EJB, JPA, etc.
Java Platforms/Editions
Simple
Object-
Dynamic
oriented
Distributed Platform
High
Performan Secured
ce
Interpreted Robust
Architectur
al Neutral
How to set path in Java
E.g.
class Demo {
public static void main (String args[]) {
System.out.println("Welcome to Java”);
}
}
What Is an Object?
E.g.
What Is a Package?
A Java package is a mechanism for organizing Java classes into
namespaces similar to the modules of Modula. Java packages
can be stored in compressed files called JAR files, allowing
classes to download faster as a group rather than one at a time.
Programmers also typically use packages to organize classes
belonging to the same category or providing similar
functionality.
•A package provides a unique namespace for the types it
contains.
•Classes in the same package can access each other's
package-access members.
E.g:-
import java.lang.*;
import java.util.*;
import java.io.*;
import java.awt.*;
What Is Inheritance?
class A
{
//statements;
}
class B extends A
{
//statements;
}
class C extends A
{
public static void main(String ar[])
{
//statements;
}
}
What is an Abstraction?
abstract class A
{
public abstract void sum(int x, int y);
}
class B extends A
{
public void sum(int x,int y)
{
System.out.println(x+y);
}
public static void main(String ar[])
{
B obj=new B();
obj.sum(2,5);
}
}
What Is an Interface?
We have two classes and both classes have a function with the
same name and same Parameters inheritance is necessary.
Eg.
class B
{
public void f1(int x,int y)
{
System.out.println(x+y);
}
}
class A extends B
{
public void f1(int x,int y)
{
System.out.println(x*y);
}