Java File
Java File
Java File
History of Java:
James Gosling initiated the Java language project in June 1991 for use in one of his many set-
top box projects. The language, initially called Oak after an oak tree that stood outside Gosling's
office, also went by the name Green and ended up later being renamed as Java, from a list of
random words.
Sun released the first public implementation as Java 1.0 in 1995. It promised Write Once, Run
Anywhere (WORA), providing no-cost run-times on popular platforms.
On 13 November 2006, Sun released much of Java as free and open source software under the
terms of the GNU General Public License (GPL).
On 8 May 2007, Sun finished the process, making all of Java's core code free and open-source,
aside from a small portion of code to which Sun did not hold the copyright.
Platform Requirements:
The following table lists the operating systems that are supported for Sun Java System
Application Server Platform Edition 8.2 product.
Windows
2000
Advanced
Server SP4+
Windows
Server 2003
Windows XP
Pro SP1+
Aim: Write a program to implement the bubble sort technique to sort given numbers.
Source Code:
import java.util.Scanner;
public class Bubble {
public static void main(String[] args) {
int n, c, d, t;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of integers to sort");
n = in.nextInt();
int a[] = new int[n];
System.out.println("Enter " + n + " integers");
for (c = 0; c < n; c++)
a[c]=in.nextInt();
for(c=0;c<(n-1);c++)
{
for(d=0;d<n-c-1;d++)
{
if(a[d]>a[d+1]) /* For descending order use < */
{
t=a[d];
a[d]=a[d+1];
a[d+1]=t;
}
}
}
System.out.println("Sorted list of numbers");
for (c=0;c<n;c++)
System.out.println(a[c]);
}
}
Aim: Write a program to implement the use of constructor and calculate the area of
Cylinder, Cube, Rectangle and Square.
Source Code:
public class Area {
public void Area( int a, int b) {
int z,r;
double s;
z=a*b;
s=3.14*r*r;
System.out.println("Area for rectangle is:"+z);
System.out.println("area for cylinder:"+s);
}
public void Area(int x) {
int c,d;
c=x*x;
d=x*x*x;
System.out.println("Area for square is:"+c);
System.out.println("Area for cube is:"+d);
}
public void Area1(int r, int h) {
double u;
u=3.14*r*r*h;
System.out.println("Area for Cylinder is:"+u);
}
public static void main(String[] args) {
Area a=new Area();
Area b= new Area();
b.Area1(5,8);
a.Area(10,40);
a.Area(5);
}
}
Aim: To make an applet program to draw Circle, Rectangle, Ellipse, Line and Cylinder.
Source Code:
import java.applet.Applet;
import java.awt.Graphics;
public class MyApplet extends Applet {
@Override
public void paint(Graphics g) {
// Drawing Cyclinder
g.drawOval(10,10,50,10);
g.drawOval(10,80,50,10);
g.drawLine(10, 15, 10, 85);
g.drawLine(60, 15, 60, 85);
// Drawing Cirlce
g.drawRoundRect(90,25,60,60,60,60);
// Drawing Ellipse
g.drawRoundRect(180,35,90,50,90,50);
// Drawing Line
g.drawLine(310,20, 310, 100);
//Drawing Rectangle
g.drawRect(340, 30, 100, 50);
}
}