A First Java Program

    We start by writing what is called a Java applet. This is a form of a Java program that can be embedded in a HTML document and accessed from the web. An example HTML document that calls our example applet is shown below:

			<HTML>
			<HEAD>
			<TITLE>Demo Applet</TITLE>
			</HEAD>
			
			<BODY>
			<H1>Demo Applet</H1>
			<P>My favorite class is 6.837</P>
			<HR>
			<CENTER>
			<APPLET code="Demo.class" width=200 height = 200>
			</APPLET>
			</CENTER>
			<HR>
			</BODY>
			</HTML>
	
    The highlighted lines add the Java code to our document. Notice the .class extension. All Java source code files should end with a .java extension. The source is here.
Lecture 2 Slide 13 6.837 Fall '98

We will start by writing what is called a Java applet. This is a form of a Java program that can be imbedded in a HTML document and accessed from the web. An example HTML document that calls the example applet is shown below:

Demo.htm

The highlighted lines add the Java code to our document. Notice the .class extension. All Java source code files should end with a .java extension. When a Java program is compiled one or more .class files are generated. Unlike, C and C++ the number of .class files generated by a compile depends on how many objects are defined in the source file. You can get a copy of this HTML file if you like. You might have to change the extension to .html.