[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]
[CS152 2005S]
[CS152 2005F]
Back to An Introduction to Unix. On to An Introduction to Java (2).
Held: Friday, January 27, 2006
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.
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.
.bash_profile to put
/opt/jdk1.5.0/bin at the front of your PATH
.bashrc to add the following aliase
alias eclipse="/home/rebelsky/Eclipse/eclipse/eclipse"
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]
[CS152 2005S]
[CS152 2005F]
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 Tue May 9 08:31:26 2006.
The source to the document was last modified on Thu Jan 12 14:58:06 2006.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2006S/Outlines/outline.04.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby