Sullivan Market

a web based full-circle development system



My Java Tutorials - Java Basics

Java Basics:
    Here is some example code.... Copy and paste it to your page if you wish to use it.

CLASSES:
The primary definition is a grouping of "variables" and "methods". The name of this class
must be the same as the name of the file. In the example below, Pet (line 1) is a class.

OBJECTES: An instance variable that describes an attribute of and instance
of a class instead of the class itself. Below (line 14) we create a Pet named dog.

VARIABLES: Variables are a place where information can be stored while a program
is running. The value can be changed at any point in the program - hence the name.
There are three types of variables in Java: instance variables, class variables, and local
variables Below (line 2 & 3) we have the variables animalType and animalColor.

METHODS: A grouping of java code with a name, list of 0 to n variables in, and zero or
one variables out. Below (line 8) getPetColor is a method.

For Example...


//Pet.java:

1 class Pet {
2 private String animalType = "feline";
3 private String PetColor;
4 Pet(String colorIn)
5 {
6 PetColor = colorIn;
7 }
8 public String getPetsColor()
9 {
10 return PetColor;
11 }
12
13 public static void Main (String[] argsIn) {
14 Pet dog = new Pet("calico");
15 }
16 }

Back To Java Tutorials

©2012 SullivanMarket.com