Java File

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Program No.

Aim: Give the brief introduction about the java language.


Introduction: Java programming language was originally developed by Sun Microsystems
which was initiated by James Gosling and released in 1995 as core component of Sun
Microsystems' Java platform (Java 1.0 [J2SE]).
As of December 2008, the latest release of the Java Standard Edition is 6 (J2SE). With the
advancement of Java and its widespread popularity, multiple configurations were built to suite
various types of platforms. Ex: J2EE for Enterprise Applications, J2ME for Mobile
Applications.
Sun Microsystems has renamed the new J2 versions as Java SE, Java EE and Java ME
respectively. Java is guaranteed to be Write Once, Run Anywhere.
Java is:
Object Oriented: In Java, everything is an Object. Java can be easily extended since it
is based on the Object model.
Platform independent: Unlike many other programming languages including C and
C++, when Java is compiled, it is not compiled into platform specific machine, rather
into platform independent byte code. This byte code is distributed over the web and
interpreted by virtual Machine (JVM) on whichever platform it is being run.
Simple: Java is designed to be easy to learn. If you understand the basic concept of
OOP Java would be easy to master.
Secure: With Java's secure feature it enables to develop virus-free, tamper-free
systems. Authentication techniques are based on public-key encryption.
Architectural-neutral: Java compiler generates an architecture-neutral object file
format which makes the compiled code to be executable on many processors, with the
presence of Java runtime system.
Portable: Being architectural-neutral and having no implementation dependent aspects
of the specification makes Java portable. Compiler in Java is written in ANSI C with a
clean portability boundary which is a POSIX subset.
Robust: Java makes an effort to eliminate error prone situations by emphasizing mainly
on compile time error checking and runtime checking.
Multithreaded: With Java's multithreaded feature it is possible to write programs that
can do many tasks simultaneously. This design feature allows developers to construct
smoothly running interactive applications.
Java has the following features:
Interpreted: Java byte code is translated on the fly to native machine instructions and
is not stored anywhere. The development process is more rapid and analytical since the
linking is an incremental and light weight process.
High Performance: With the use of Just-In-Time compilers, Java enables high
performance.
Distributed: Java is designed for the distributed environment of the internet.

Roll No. 3612155 Page-1 C.S.E A-2


Dynamic: Java is considered to be more dynamic than C or C++ since it is designed to
adapt to an evolving environment. Java programs can carry extensive amount of run-
time information that can be used to verify and resolve accesses to objects on run-time.

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.

Supported Operating Systems

Operating Minimum Recommended Minimum Recommended JVM


System Memory Memory Disk Disk Space
Space

Sun Solaris 9, 512 MB 512 MB 250 MB free 500 MB free J2SE


10 (SPARC) 1.4.2_10,
J2SE 5_06
Solaris 9,
10(x86)

Sun Java 512 MB 1 GB 250 MB free 500 MB free J2SE


Desktop 1.4.2_10,
System J2SE 5_06

Redhat 512 MB 1 GB 250 MB free 500 MB free J2SE


Enterprise 1.4.2_10,
Linux 3.0 U1, J2SE 5_06
4.0

Windows 1 GB 2 GB 500 MB free 1 GB free J2SE


Server 2000 1.4.2_10,
SP4+ J2SE 5_06
Operating Minimum Recommended Minimum Recommended JVM
System Memory Memory Disk Disk Space
Space

Windows
2000
Advanced
Server SP4+

Windows
Server 2003

Windows XP
Pro SP1+

Roll No. 3612155 Page-1 C.S.E A-2


Output:

Output: Bubble Sort


Program No. 2

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]);
}
}

Roll No. 3612155 Page-1 C.S.E A-2


Output:

Output: Decimal to Binary conversion


Program No. 3

Aim: Write a program to implement decimal to binary conversion.


Source Code:
public class DbConversion {
public static void main(String[] args) {
int a=32;
int i = 0;
int b[] = new int[10];
while (a != 0)
{
i++;
b[i] = a%2;
a = a/2;
}
System.out.print("Binary value for 32 is= ");
for (int j = i; j > 0; j--)
{
System.out.print(b[j]);
}
System.out.println("");
}
}

Roll No. 3612155 Page-1 C.S.E A-2


Output:

Output: Constructor Implementation


Program No. 4

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);
}
}

Roll No. 3612155 Page-1 C.S.E A-2


Output:

Output: Applet Program


Program No. 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);
}
}

Roll No. 3612155 Page-1 C.S.E A-2

You might also like