History
The Java programming Language evolved from a language named Oak. Oak was developed in the early nineties at Sun Microsystems as a platform-independent language aimed at allowing entertainment appliances such as video game consoles and VCRs to communicate . Oak was first slated to appear in television set-top boxes designed to provide video-on-demand services. Just as the deals with the set-top box manufacturers were falling through, the World Wide Web was coming to life. As Oak’s developers began to re cognize this trend, their focus shifted to the Internet and WebRunner, an Oak-enabled browser, was born. Oak’s name was changed to Java and WebRunner became the HotJava web browser. The excitement of the Internet attracted software vendors such that Jav a development tools from many vendors quickly became available. That same excitement has provided the impetus for a multitude of software developers to discover Java and its many wonderful features.Significant Language Features
- Platform Independence - Java compilers do not produce native object code for a particular platform but rather ‘byte code’ instructions for the Java Virtual Machine (JVM). Making Java code work on a particular platform is then sim ply a matter of writing a byte code interpreter to simulate a JVM. What this all means is that the same compiled byte code will run unmodified on any platform that supports Java.
- Object Orientation - Java is a pure object-oriented language. This means that everything in a Java program is an object and everything is descended from a root object class.
- Rich Standard Library - One of Java’s most attractive features is
its standard library. The Java environment includes hundreds of classes and methods in six
major functional areas.
- Language Support classes for advanced language features such as strings, arrays, threads, and exception handling.
- Utility classes like a random number generator, date and time functions, and container classes.
- Input/output classes to read and write data of many types to and from a variety of sources.
- Networking classes to allow inter-computer communications over a local network or the Internet.
- Abstract Window Toolkit for creating platform-independent GUI applications.
- Applet is a class that lets you create Java programs that can be downloaded and run on a client browser.
- Applet Interface - In addition to being able to create stand-alone applications, Java developers can create programs that can downloaded from a web page and run on a client browser.
- Familiar C++-like Syntax - One of the factors enabling the rapid adoption of Java is the similarity of the Java syntax to that of the popular C++ programming language.
- Garbage Collection - Java does not require programmers to explicitly free dynamically allocated memory. This makes Java programs easier to write and less prone to memory errors.
Areas of Application
- World Wide Web Applets
- Cross-Platform Application Development
- Other Network Applications
SAMPLE PROGRAMMING
Description
This program demonstrates the text output function of the Java programming language by displaying the message "Hello world!".Source Code
class HelloWorld {
public static void main(String args[])
{
System.out.println("Hello world!");
}
}
Click here to download a zip file containing the source code.
Sample Run
Hello world!Click here to download a zip file containing a Java executable class.
Program Notes
This program was compiled and run using the Java Developers Kit, Version 1.0.2, for Win32 on x86 from Sun Microsystems running under Windows 95.Description
This program demonstrates and power of Java graphics along with their ease of use.Source Code
import java.awt.*;public class Lamp extends java.applet.Applet {
public void paint(Graphics g) {
// lamp platform
g.fillRect(0,250,290,290);
//lamp base
g.drawLine(125,250,125,160);
g.drawLine(175,250,175,160);
//lamp shade (top and bottom edges)
g.drawArc(85,157,130,50,-65,312);
g.drawArc(85,87,130,50,62,58);
//lamp shade (sides)
g.drawLine(85,177,119,89);
g.drawLine(215,177,181,89);
//dots on shade
g.fillArc(78,120,40,40,63,-174);
g.fillOval(120,96,40,40);
g.fillArc(173,100,40,40,110,180);
}
}
*------------------------------------------------*
Description
This program demonstrates and power of Java graphics along with their ease of use.Source Code
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class canvasboard extends Applet implements
MouseMotionListener, ItemListener {
Canvas picture;
Point spot;
Choice Colors = null;
public void init() {
setLayout(new BorderLayout());
//add canvas
picture = new Canvas();
addMouseMotionListener(this);
setBackground(Color.black);
//adds canvas to north region
add("North", picture);
//add color choices for foreground
Colors = new Choice();
Colors.addItem("white");
Colors.addItem("gray");
Colors.addItem("red");
Colors.addItem("green");
Colors.addItem("blue");
Colors.addItem("yellow");
Colors.addItem("magenta");
Colors.addItem("cyan");
Colors.addItem("pink");
Colors.addItem("orange");
Colors.addItemListener(this);
add("West", Colors);
}
public void update(Graphics g) {
// wont clear screen when mouse moves.
paint(g);
}
public void mouseDragged(MouseEvent e) {
spot = e.getPoint();
repaint();
}
public void mouseMoved(MouseEvent e) {
//must be implemented
}
public void itemStateChanged(ItemEvent e) {
ItemSelectable is = e.getItemSelectable();
String s = is.getSelectedObjects() [0].toString();
if ("white".equals(s))
setForeground(Color.white);
else if ("gray".equals(s))
setForeground(Color.gray);
else if ("red".equals(s))
setForeground(Color.red);
else if ("green".equals(s))
setForeground(Color.green);
else if ("blue".equals(s))
setForeground(Color.blue);
else if ("yellow".equals(s))
setForeground(Color.yellow);
else if("magenta".equals(s))
setForeground(Color.magenta);
else if("cyan".equals(s))
setForeground(Color.cyan);
else if("pink".equals(s))
setForeground(Color.pink);
else if("orange".equals(s))
setForeground(Color.orange);
repaint();
}
public void paint(Graphics g) {
if (spot !=null)
g.fillOval(spot.x - 2, spot.y - 2, 4, 4);
}
}
import java.awt.*;
ReplyDeleteimport java.awt.event.*;
import java.applet.*;
public class canvasboard extends Applet implements
MouseMotionListener, ItemListener {
Canvas picture;
Point spot;
Choice Colors = null;
public void init() {
setLayout(new BorderLayout());
//add canvas
picture = new Canvas();
addMouseMotionListener(this);
setBackground(Color.black);
//adds canvas to north region
add("North", picture);
//add color choices for foreground
Colors = new Choice();
Colors.addItem("white");
Colors.addItem("gray");
Colors.addItem("red");
Colors.addItem("green");
Colors.addItem("blue");
Colors.addItem("yellow");
Colors.addItem("magenta");
Colors.addItem("cyan");
Colors.addItem("pink");
Colors.addItem("orange");
Colors.addItemListener(this);
add("West", Colors);
}
public void update(Graphics g) {
// wont clear screen when mouse moves.
paint(g);
}
public void mouseDragged(MouseEvent e) {
spot = e.getPoint();
repaint();
}
public void mouseMoved(MouseEvent e) {
//must be implemented
}
public void itemStateChanged(ItemEvent e) {
ItemSelectable is = e.getItemSelectable();
String s = is.getSelectedObjects() [0].toString();
if ("white".equals(s))
setForeground(Color.white);
else if ("gray".equals(s))
setForeground(Color.gray);
else if ("red".equals(s))
setForeground(Color.red);
else if ("green".equals(s))
setForeground(Color.green);
else if ("blue".equals(s))
setForeground(Color.blue);
else if ("yellow".equals(s))
setForeground(Color.yellow);
else if("magenta".equals(s))
setForeground(Color.magenta);
else if("cyan".equals(s))
setForeground(Color.cyan);
else if("pink".equals(s))
setForeground(Color.pink);
else if("orange".equals(s))
setForeground(Color.orange);
repaint();
}
public void paint(Graphics g) {
if (spot !=null)
g.fillOval(spot.x - 2, spot.y - 2, 4, 4);
}
}