[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[On Teaching and Learning]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.5 API]
[Espresso]
[TAO of Java]
[CS152 2004F]
Back to An Introduction to Unix. On to An Introduction to Java (2).
Held: Friday, January 28, 2005
Summary: Today we begin our exploration of Java with a simple program.
Related Pages:
Assignments
Notes:
Overview:
packages.
new, the name of the class, and any parameters the constructor for the class needs.
mainclass) contains a method called
main which one uses to start the program.
packages.
package command.
rebelsky.csc152.2005s.introjava.
edu.grinnell.cs.rebelsky.cs152.2005S.introjava
foo.bar.baz should be in a directory called baz, which is a subdirectory of bar, which is a subdirectory of foo.
foo, in this example) gets specified elsewhere.
.java file into something the computer better understands, called a .class file.
/opt/jdk1.5.0/bin/javac ClassName.java
main method.
/opt/jdk1.5.0/bin/java package.StartingClass
package rebelsky.introjava;
public class First
{
public static void main(String[] args)
throws Exception
{
java.io.PrintWriter pen;
pen = new java.io.PrintWriter(System.out, true);
java.lang.String greeting;
greeting = "Hello";
pen.println(greeting);
} // main(String[])
} // class First
Let's deconstruct this program
package rebelsky.introjava;
rebelsky.introjava. Note the semicolon at the end of the line.
public class First
First that is available to others.
public static void main(String[] args) throws Exception
main method.
main.
(String[] args)
void
static
public
throws exception
java.io.PrintWriter pen;
pen, which refers to objects of class java.io.PrintWriter.
pen = new java.io.PrintWriter(System.out, true);
java.io.PrintWriter which prints to the normal output location (the screen)
pen to refer to that object.
java.lang.String greeting;
greeting, which refers to objects of class java.lang.String
greeting = "Hello";
greeting refer to the string Hello.
pen.println(greeting);
Back to An Introduction to Unix. On to An Introduction to Java (2).
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[On Teaching and Learning]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.5 API]
[Espresso]
[TAO of Java]
[CS152 2004F]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Wed May 11 10:55:44 2005.
The source to the document was last modified on Mon Jan 24 10:17:06 2005.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2005S/Outlines/outline.04.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby