Let's do a quick rehash of what you must remember about the basic syntax of Java.
Firstly, Java is case sensitive. To a computer, t is not T.
If the variable you cent (TreeCount) is really named treeCount, the program won't work.
// These are completely different variables !
int treeCount = 15;
int TreeCount = 25;
This can frustate a human, by the computer doesn't care so watch out.
For all class Names, the first letter should be in uppercase .
If several words are used to form the name of the class, then each word's first letter should be in uppercase.
For examples, we can have a Tree class :
public class Tree{
// Tree class
public void showMsg (){
System.out.println ("Tree Here");
}
}
You can create an instance of this class.
Remember that Variables are typically lowercase, while classes are uppercase.
Therefore, using the same name for Both class and instance variables actually helps us differentiate.
public static void main (String[] args) {
Tree tree = new Tree();
tree showMsg ();
}
All Method Names should start with a lowercase letter.
If several words are used to form the name of the method, then each words after, the first word should have the first letter as uppercase.
For example, the following method takes in a variable and does not some math.
public int addTwoNumbers (int firstNumber, int secondNumber){
int sum = firstNumber + secondNumber;
return sum;
}
The program Files Name should exactly match the class name. When saving the files, you should save it using the class name.
public int add2Numbers (int firstNumber, int secondNumber)
{int sum = firstNumber + secondNumber;
return sum;}
getclass( )
can be used to find out what class the method belongs to.
The file can be saved as file as Number.java (.java is the file extension and Number is the name of the class used).
What is variables in java ?
ReplyDelete