Thursday, January 24, 2001 - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Thursday, January 24, 2001

Description:

Washburn University. Department of Computer Information Sciences. CM245 C. Schmidt ... public static void main(String[] args) throws IOException ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 11
Provided by: lindaj158
Category:

less

Transcript and Presenter's Notes

Title: Thursday, January 24, 2001


1
CM245 Lecture 2
CM245 - Contemporary Programming Methods Lecture 2
Thursday, January 24, 2001 Cecil P.
Schmidt Department of Computer Information
Sciences Washburn University Topeka, KS.
66621 zzschmid_at_washburn.edu
2
Presentation Outline
  • Files and Directores
  • Building a java program
  • Applets versus applications

3
Files and Directories
  • Java source file ltfilename.javagt
  • Java object file ltfilename.classgt
  • Typical data file ltfilename.datagt
  • Directory contains a set of (related) files

4
How Do You Build a Java Program
  • Text Editor with Java Development Kit (JDK)
  • Integrated Development Environments (IDE)
  • VisualAge Java
  • Visual J
  • JBuilder
  • An IDE is great for large applications, screen
    painting and debugging. Its best to learn
    without one first.
  • We are not using an IDE for this class. We are
    using the text editor option.

5
Applets vs. Applications (Review)
  • Applets are invoked as part of a Web page
  • Applets cannot run alone. The must run with the
    aid of a browser.
  • Applications are free standing programs
  • Applications require the main method
  • example Hello.java

6
Hello.java Application
  • /
  • File Name Hello.java
  • Author Cecil Schmidt
  • Date Written 06/06/2001
  • Description This program is used to
    illustrate a simple stand alone version
  • of a Java program.
  • /
  • import java.io. //We are importing a library of
    classes to do I/O.
  • //The class name "Hello" must be the same name as
    the file name on disk
  • //except that the file name must end in ".java".
    For example, the physical
  • //file name of this program is "Hello.java" and
    the class name is "Hello".
  • public class Hello
  • //The main method is required in all stand
    alone programs.
  • public static void main(String args) throws
    IOException
  • System.out.println("Hello CM245 Class!")
  • //System is an object you get for "free". It
    allows you to

7
Edit-Compile-Execute Process
  • Edit build a .java file using either an IDE or
    an editor
  • Compile converts .java to .class (byte code)
  • Execute run the .class file with the JVM

8
Creating and running an applet
  • HelloApplet.java
  • Using the appletviewer utility
  • Setting your display variable
  • Moving the file to your web site after testing

9
HelloApplet.java
  • /
  • File Name HelloApplet.java
  • Author Cecil Schmidt
  • Date Written 06/07/2001
  • Description
  • This program is used to illustrate a simple
    applet.
  • /
  • import java.awt. //Abstract Windowing Toolkit
  • import java.applet.Applet
  • public class HelloApplet extends Applet
  • //The paint method is required in all
    applets.
  • public void paint(Graphics g)
  • //draw text on graphic obect.
  • g.drawString("Hello CM245 Class!", 50, 50)

10
HelloApplet.html
  • lthtmlgt
  • ltheadgt
  • lttitlegtHello Appletlt/titlegt
  • lt/headgt
  • ltbodygt
  • ltapplet codeHelloApplet.class width300
    height200gt
  • lt/appletgt
  • lt/bodygt
  • lt/htmlgt
Write a Comment
User Comments (0)
About PowerShow.com