Himanshu JAVA FILE'
Himanshu JAVA FILE'
(ETCS-357)
The principles for creating Java programming were "Simple, Robust, Portable,
Platform-independent, Secured, High Performance, Multithreaded, Architecture
Neutral, Object-Oriented, Interpreted, and Dynamic". Java
was developed by James Gosling, who is known as the father of Java, in 1995.
James Gosling and his team members started the project in the early '90s.
1) James Gosling
, Mike Sheridan, and Patrick Naughton initiated the Java language project in
June 1991. The small team of sun engineers called Green Team. Play Vide ox.
2) Initially it was designed for small, embedded systems in electronic appliances
like set-top boxes.
3) Firstly, it was called "Green talk" by James Gosling, and the file extension
was.gt.
4) After that, it was called Oak and was developed as a part of the Green
project.
Why Java was named as "Oak"?
Java History from Oak to Java
5) Why Oak? Oak is a symbol of strength and chosen as a national tree of many
countries like the U.S.A., France, Germany, Romania, etc.
6) In 1995, Oak was renamed as "Java" because it was already a trademark by
Oak Technologies.
Why Java Programming named "Java"?
7) Why had they chosen the name Java for Java language? The team gathered to
choose a new name. The suggested words were "dynamic", "revolutionary",
"Silk", "jolt", "DNA", etc. They wanted something that reflected the essence of
the technology: revolutionary, dynamic, lively, cool, unique, and easy to spell,
and fun to say.
According to James Gosling, "Java was one of the top choices along with Silk".
Since Java was so unique, most of the team members preferred Java than other
names.
8) Java is an island in Indonesia where the first coffee was produced (called
Java coffee). It is a kind of espresso bean. Java name was chosen by James
Gosling while having a cup of coffee nearby his office.
9) Notice that Java is just a name, not an acronym.
10) Initially developed by James Gosling at Sun Microsystems
(Which is now a subsidiary of Oracle Corporation) and released in 1995.
11) In 1995, Time magazine called Java one of the Ten Best Products of 1995.
12) JDK 1.0 was released on January 23, 1996. After the first release of Java,
there have been many additional features added to the language. Now Java is
being used in Windows applications, Web applications, enterprise applications,
mobile applications, cards, etc. Each new version adds new features in Java.
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
Features of Java
The primary objective of Java programming
language creation was to make it portable, simple and secure programming language. Apart from
this, there are also some excellent features which play an important role in the popularity of this
language. The features of Java are also known as Java buzzwords.
A list of the most important features of the Java language is given below.
Types of Java Applications
There are mainly 4 types of applications that can be created using Java
programming:
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.
3) Enterprise Application: -
An application that is distributed in nature, such as banking applications, etc. is
called an enterprise application. It has advantages like 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 that is mainly used to develop web and enterprise
applications. It is built on top of the 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 that is dedicated to mobile applications.
4) JavaFX: -
It is used to develop rich internet applications. It uses a lightweight user
interface API.
Experiment -2
AIM: - WAP to find factorial of a number in java.
CODE: -
import java.util.Scanner;
public class factorial {
public static void main(String[] args) {
int fact = 1, i = 1;
Scanner sc = new Scanner (System.in);
System.out.println("Enter a number whose factorial is to be found: ");
int num = sc.nextInt();
while (i <= num) {
fact = fact * i;
i++;
}
System.out.println("\nFactorial of " + num + " is: " +fact);
}
}
OUTPUT: -
Experiment -3
AIM: - WAP to print Fibonacci series till nth term.
CODE: -
import java.util.Scanner;
public class NthFibonacci {
public static void main(String[] args) {
Scanner s= new Scanner(System.in);
int n=s.nextInt();
int f1 = 0, f2 = 1, f;
System.out.print(f1+" "+f2);
}
OUTPUT: -
Experiment – 4
AIM; - WAP to calculate sum of number until negative number is enter.
CODE: -
import java.util.Scanner;
public class SumofNumberNegative {
OUTPUT: -
Experiment – 6
AIM; - WAP that takes three inputs from the user: one operator and 2
numbers. Based on the operator provided by the user, it performs the calculation
on the numbers. Then the result is displayed on the screen.
CODE: -
import java.util.Scanner;
public class Operator {
switch (operator) {
default:
System.out.println("Invalid operator!");
break;
}
}
OUTPUT: -
Experiment – 7
AIM; - WAP to calculate area of circle using the radius.
CODE: -
import java.util.Scanner;
public class CircleRadius {
}
OUTPUT: -
Experiment – 8
AIM; - WAP to display personal data of user using scanner class.
CODE: -
import java.util.Scanner;
public class scannerwithUSer {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = input.nextLine();
System.out.println("My name is " + name+".");
}
}
OUTPUT: -
Experiment – 9
AIM; - WAP to display odd number up to 20.
CODE: -
import java.util.Scanner;
public class OddNumber {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int number = s.nextInt();
System.out.print("List of odd numbers from 1 to " + number + ": ");
for (int i = 1; i <= number; i++) {
if (i % 2 != 0) {
System.out.print(i + " ");
}
}
}
}
OUTPUT: -
Experiment – 10
AIM; - WAP to calculate sum, difference, product, quotient of two number
enter by the user.
CODE: -
import java.util.Scanner;
public class TwoNumberUser {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int a= s.nextInt() , b=s.nextInt();
int sum = a+b;
int diff = a-b;
int product = a*b;
double quot = a/b;
System.out.println("Sum: " +sum);
System.out.println("Difference: " +diff);
System.out.println("Product: " +product);
System.out.println("Quotient: " +quot);
}
}
OUTPUT: -
Experiment – 11
AIM; - WAP to implement stack and queue concept in java.
1. Implement Stack
CODE: -
public class Implementstack {
private int arr[];
private int top;
private int capacity;
Implementstack(int size) {
// initialize the array
// initialize the stack variables
arr = new int[size];
capacity = size;
top = -1;
}
public void push(int x) {
if (isFull()) {
System.out.println("Stack OverFlow");
stack.push(1);
stack.push(2);
stack.push(3);
System.out.print("Stack: ");
stack.printStack();
stack.pop();
System.out.println("\nAfter popping out");
stack.printStack();
}
}
OUTPUT: -
2. Implement Queue
CODE: -
public class ImplementQueue {
int SIZE = 5;
int items[] = new int[SIZE];
int front, rear;
ImplementQueue() {
front = -1;
rear = -1;
}
// if queue is full
if (isFull()) {
System.out.println("Queue is full");
} else {
if (front == -1) {
// mark front denote first element of queue
front = 0;
}
rear++;
// insert element at the rear
items[rear] = element;
System.out.println("Insert " + element);
}
}
// if queue is empty
if (isEmpty()) {
System.out.println("Queue is empty");
return (-1);
} else {
// remove element from the front of queue
element = items[front];
OUTPUT: -
Experiment – 12
AIM; - WAP to implement single inheritance concept in java.
CODE: -
public class Shape {
int length;
int breadth;
}
import java.util.Scanner;
public class Rectangle extends Shape {
int area;
public void calcualteArea() {
area = length * breadth;
System.out.println(area);
}
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
Rectangle r = new Rectangle();
r.length = s.nextInt();
r.breadth= s.nextInt();
r.calcualteArea();
}
}
OUTPUT: -
Experiment – 13
AIM; - WAP to implement multiple inheritance concept in java.
CODE: -
interface Event {
public void start();
}
interface Sports {
public void play();
}
interface Hockey extends Sports, Event {
public void show();
}
public class Tester {
public static void main(String[] args){
Hockey hockey = new Hockey() {
public void start() {
System.out.println("Start Event");
}
public void play() {
System.out.println("Play Sports.");
}
public void show() {
System.out.println("Show Hockey.");
}
};
hockey.start();
hockey.play();
hockey.show();
}
}
OUTPUT: -
Experiment – 14
AIM; - WAP to implement multilevel hierarchical inheritance concept in java.
CODE: -
public class A {
void funcA() {
System.out.println("This is class A");
}
}
public class B extends A {
void funcB() {
System.out.println("This is class B");
}
}
public class C extends B {
void funcC() {
System.out.println("This is class C");
}
}
public class Demo {
public static void main(String args[]) {
C obj = new C();
obj.funcA();
obj.funcB();
obj.funcC();
}
}
OUTPUT: -
Experiment – 15
AIM; - WAP to show multithreaded producer and consumer application.
CODE: -
public class Multithreading {
public static void main(String[] args) throws InterruptedException {
final PC pc = new PC();
// Create producer thread
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
try {
pc.produce();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
// Create consumer thread
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
try {
pc.consume();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
// Start both threads
t1.start();
t2.start();
// t1 finishes before t2
t1.join();
t2.join();
}
// and sleep
Thread.sleep(1000);
}
}
}
}
}
OUTPUT: -
Experiment – 16
AIM; - Create a customized exception and make use of all the 5 exception
keywords.
CODE: -
public class CustomizedException {
public static void main(String[] args) {
try {
String welcomeMessage = welcomeMessage("SJ");
System.out.println("The returned welcome message : " + welcomeMessage);
} catch (NullPointerException npex) {
System.out.println("Exception handled : " + npex.toString());
} finally {
System.out.println("Rest of the clean-up code here");
}
}
// division method returning quotient
public static String welcomeMessage(String name)throws NullPointerException
{
if (name == null) {
throw new NullPointerException("Invoke method with VALID name");
}
String welcomeMsg = "Welcome " + name;
return welcomeMsg;
}
}
OUTPUT: -