// CIS 757/790 PROF. AUCIELLO
// (pstan.java)
// ["33 Step Program to Understanding '"Hello World!'"]
// Standard Java Program Template for Prof. A's students.
// pstan.java (check that "pstan" follows the word "class" below.
// This is the standard benchmark for Java.
// Keep this copy handy for reference.
// Use it to check the syntax of other Java programs.
// Run it when necessary to ensure the compilers are working.
// This is the standard template for Java Programs (not Applets)
/* Topics:
1. Printing a literal string.
(using System.out.println)
2. 'public'
3. Difference between Programs and Applets.
4. Inputting a String.
5. (console.Readstring)
*/
/* Hello World, the first Java application */
import corejava.*;
// must have the following statements
// in AUTOEXEC.BAT:
// set classpath=c:\jdk1.1.2\lib;.;c:\CoreJavaBook
// link to corejava library.
// this gives the JAVA compiler (javac.exe) access to the
// Java Dev Kit and a library of stored functions (CoreJavaBook)
// note the syntax is corejava.* (wildcard extension)
class pstan // same name as DOS filename
// "class" is a template for multiple
// objects with same features.
{ public static void main (String args[])
// "public" means available to other
// programs in same workspace.
// "void" does not return a result
// (more explanation needed)
// main = main method (procedure)
// args[] is an array of String type
// (used for command line parameters)
// (more to come)
{ String yourName; // variable yourName is defined
// as a String.
yourName = Console.readString("Please enter your name.");
// says "read string from KB console
// store in yourName.
System.out.println("Hello World! -- from " + yourName);
// uses system-output (printer)
// to print "Hello ..." plus the
// name you entered.
}
}
// notice that { "Brackets" are paired.
/*
// class names program
// what does string args means?
// System.out.println = prints a literal string
// 'public' = available to other Java programs
// after it has been loaded.
/* ---------------------------------------------------
Enabling Objectives:
.01 When this document is displayed as an HTML file,
then click file--save-as d:\name.txt (d = drive name
save-as 'txt' file, print it out.
1. "//" creates a comment.
2. the "slash asterisk" (look above) starts a block comment that
ends with an "asterisk slash" (bottom).
3. why can I not use an "astrisk slash" here in the text?
4. Java is installed from a CD-ROM Disk into C:\jdk1.1.2
5. Note that a directory name can contain "."s
6. Note that a directory called "CoreJavaBook" was also created.
7. Here is the directory of my "C:\" drive"
Volume in drive C is C-541MB
Volume Serial Number is 093E-0AD5
Directory of C:\
WINDOWS [DIR] 03-22-99 3:20a WINDOWS
COREJA~1 [DIR] 03-28-99 12:47a CoreJavaBook
WINZIP [DIR] 03-28-99 1:07a WinZip
JDK11~1 2 [DIR] 03-28-99 1:02a jdk1.1.2
0 file(s) 0 bytes
1 dir(s) 283,230,208 bytes free
Identify the CoreJavaBook Folder (subdirectory).
............ jdk1.1.2 subdirectory.
8. Note case-sensistivity of CoreJavaBook (all names in Win 95).
9. Note "short DOS Names" on left, long names on right.
(Note use of "tilde" (~) to show truncation of names).
10. Establish that the CoreJavaBook (contains programs) and
the Java Development Kit were created by the Install Program.
10.1 Note the lines added to AUTOEXEC.BAT by the INSTALL progam:
rem Begins AUTOEXEC.BAT
d:\SOLOMON\GUARD.COM
PROMPT $p$g
PATH C:\WINDOWS;C:\WINDOWS\COMMAND;C:\DOS;.;c:\jdk1.1.2\bin
SET TEMP=C:\DOS
set classpath=c:\jdk1.1.2\lib;.;c:\CoreJavaBook
10.2 What does "PATH" do?
10.3 What does "set classpath" do?
11. Key in the following programs (you may add comments):
// CIS 757/790 YOUR NAME
// Hello Java!, the first Java application
import corejava.*;
class pstan // (same name as DOS filename.)
{ public static void main (String args[])
{ String yourName;
yourName = Console.readString("Please enter your name.");
System.out.println("Hello Java! -- from " + yourName);
}
}
11.1 You must save this program with the extension ".java"
-- 4 letters, lower-case!
The DOS EDIT Program allows 4-letter extensions.
12. Note brackets " { } " are paired.
13. Note EXTREME CASE-SENSITIVITY!
14. Think if "yourName" and "YourName" as a string variable
are the same to Java.
15. Identify the commented lines. (2 types)
16. What do you think import corejava.* does?
17. What will be the name of the "class" (object code) after compilation?
18. "public, static, void, main, String args []" are keywords
that define the class named "pstan" (more later).
19. Change Directories -- CD CoreJavaBook
(Only in this directory can the package "corejava" be accessed.
-- will be investigated.)
20. Understand that "javac" is the name of the compiler.
21. type: javac c:\pstan.java (note path name)
21.1 Identify the syntax and options for javac:
C:\CoreJavaBook>javac
use: javac [-g][-O][-debug][-depend][-nowarn][-verbose]
[-classpath path][-nowrite][-deprecation][-d dir]
[-J] file.java...
22. If there are compile-time errors, fix them. (Note line numbers)
23. Note 2 or 3 second pause while program compiles.
24. Take a DIR of the folder where pstan.class was created and
verify its existence:
24.1 Note that "pstan.class" was created in the same directory as
the source file (c:\).
25. java compiles pstan.java into a meta-file (java.class)
Here is a look at java.class: [called DUMP]
Êþº¾-4!%()*+,0 '.#/
23()Ljava/lang/String;()V&
(Ljava/lang/String;)Ljava/lang/String;
,(Ljava/lang/String;)Ljava/lang /StringBuffer;
(Ljava/lang/String;)V ([Ljava/lang/String;)V
Code ConstantValue Exceptions
Hello World! -- from LineNumberTable
Ljava/io/PrintStream; LocalVariables
Please enter your name.
SourceFile
append corejava/Console
java/io/PrintStream java/lang/
Object java/lang/StringBuffer java/lang/System
main out println pstan
pstan.java readString toString
-=¸L²»Y·+¶¶¶±"14
25.1 An object-file is an executable binary file.
This is a "meta-object-file" = comprised on binary and ASCII
characters -- that requires an Interpreter (java) to run:
25.2 Circle the elements of the source-code embedded in the
class file.
25.3 Understand the reason for the symbols.
26. Identify 'java" as the name of the "interpreter"
27. Identify the syntax and options for java:
C:\CoreJavaBook>java
usage: java [-options] class
where options include:
-help print out this message
-version print out the build version
-v -verbose turn on verbose mode
-debug enable remote JAVA debugging
-noasyncgc don't allow asynchronous garbage collection
-verbosegc print a message when garbage collection occurs
-noclassgc disable class garbage collection
-ss set the maximum native stack size for any thread
-oss set the maximum Java stack size for any thread
-ms set the initial Java heap size
-mx set the maximum Java heap size
-classpath
list directories in which to look for classes
-prof[:] output profiling data to .\java.prof or .\
-verify verify all classes when read in
-verifyremote verify classes read in over the network [default]
-noverify do not verify any class
28. Type java pstan (pstan = name of class & internal-class-name)
29. The execution should look like:
C:\CoreJavaBook>java pstan
Please enter your name. Yvette Did It!
Hello World! -- from Yvette Did It!
30. Next, create a document that looks like this:
-----------------------------------------------------------------------
// CIS 757/790 Yvette Hannah PROF. AUCIELLO
Source-code: pstan.java
import corejava.*;
class pstan
{ public static void main (String args[])
{ String yourName;
yourName = Console.readString("Please enter your name.");
System.out.println("Hello World! -- from " + yourName);
}
}
Execution:
C:\CoreJavaBook>java pstan
Please enter your name. Yvette Did It!
Hello World! -- from Yvette Did It!
-------------------------------------------------------------------
31. Print this out. Put in HW Notebook.
32. Improve this program, and generate a lot of questions
(especially questions on javac and java options),
as we apply Continous Quality Improvement and Innovation
(CQII) to this process.
33. Why is this put into HTML; what does [pre] do?
- end
*/