Java Skeleton Program
// ClassNames should be in "camel" beinging with Uppercase
class ClassName
{
// Variable definitions look like this:
// variableNames should be in "camel" beinging with lowercase
scope returnType variableName;
variableName = aValue;
// or
private returnType variableName = aValue;
// Constructors definitions look like this:
ClassName anObject = new ClassName();
// Method definitions look like this:
// methodNames should be in "camel" beinging with lowercase
scope returnType methodName( parameterList )
{
// Java statements
return returnValue;
}
// Accessor (get) Method look like this:
public returnType getMethod()
{
return returnValue;
}
// Mutator (set) Method look like this:
public void setMethod( returnType newValue )
{
variableName = newValue;
}
}
class ClassTester
{
public static void main ( String[] args )
{
ClassName anObject = new ClassName();
anObject.methodName();
}
}
Separation into sections is done for convenience; it is not a rule of the language.
A simple class might have just a few variables and be defined in just a few lines of code.
A large, complicated class might take thousands of lines of code for its definition.
The scope can be public, protected, or private.
The returnType is the type of value that the method hands back to the caller of the method.
Return types can be primitive data types, the String class, a user-defined Class, an array of data or void.
Your methods can return values just as methods from library classes.
The return statement is used by a method to hand back a value to the caller.
If you want a method that does something, but does not hand a value back to the caller,
use a return type of void and do not use a return value with the return statement.
The return statement can be omitted; the method will automatically return to the caller after it executes.
Even if there is no parameter list for a method, an empty pair of parentheses ( ) is required.
The name of the method, along with its list of parameter datatypes, is the method's signature.
It is convenient to have a separate "testing" class that serves no other purpose than to contain the main() method.
The main method is where the No testing class objects will be constructed when the program runs.
(However, main() will usually construct objects of other classes as it runs.)
class NameInputReader
{
public static void main(String[] args)
// entry point of the application
{
System.out.print("String" + or variable value);
// no carriage return, concatinates with next line
System.out.println("String" + or variable value);
// carriage return at end of line
InputStreamReader inStream = new InputStreamReader(System.in);
// instantiates an instance of the input reader Class
BufferedReader stdin = new BufferedReader( inStream );
// instantiates an instance of the buffer reader Class
** BufferedReader stdin = new BufferedReader ( new InputStreamReader(System.in));
//works the same as both statements above (use this one or the other two)
String inData;
// creates a variable as a String Class without a value, yet
System.out.println("Enter your input data:");
// prompts user to enter data
inData = stdin.readLine();
// reads input data/value and assigns to variable
System.out.println("You entered: " + inData );
// displays the input just entered
}
}
See Java Links for more info, Object & Classes , Data Types , Operators , Conditionals , Definitions , Keywords , File Structure , Code Examples , Class Skeleton , Java Notes




