JAVA
Programming
I
JAVA
Environment
*a JAVA
program consists of one
or more classes
*each class has a name and is
saved in a separate file with
the same name as the class and
the suffix .java
*every JAVA
application contains
a subprogram called main
*there can also be other subprograms which
are generally referred to as methods
*it is convention is to have class names
begin with an upper case letter, and
object and method names begin with a
lower case letter
JAVA
Template
// The "X" class.
import [Link].*;
import [Link];
public class X
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console();
// Place your program here. 'c' is the output console
} // main method
} // X class
Comments
*there are two sorts of comments in JAVA
/* This is a comment. It does not end here...
but keeps on going until it reaches a */
// This is also a comment which ends at the end of the line
*every program should have a header with the
following information
//name:
//date:
//description:
*include comments throughout the program to indicate
what is happening
Example Programs
1. [Link]("Hello world!");
output: Hello world!
2. [Link]("a");
[Link]("b");
output: ab
3. [Link]("a");
[Link]("b");
output: a
b
4. [Link]();
output:
[nothing]
Example Programs
4. [Link](1 + 2);
output: 3
5. [Link](1 + 2 + " is three");
output: 3 is three
6. [Link](1/3);
output: 0
7. [Link](1.0/3.0);
output: 0.3333333333333333
[16 fractional digits]
8. [Link]([Link](2));
output: 1.4142135623730951
[16 fractional digits]