Guide to Object-oriented Programming With Java (University at Buffalo Version)
Chapter 4: Java Language Structures
In addition to the previously mentioned Java structures (projects, packages, classes, and comments), Java's other structures include: identifiers, keywords, variables, and methods. Most Java programmings use camelCase to name their variables, identifiers, and methods. For example, a variable to store the first name would be: firstName
.
Classes
As previously mentioned, a class is a "container" for code. Each Java program can contain only one (1) class
method. The name of the class must begin with an Uppercase letter. The name of your .java
file should be the same as the name of your class. For example, the file HelloWorld
would have a public class HelloWorld { }
statement. All code in a class in enclosed in braces: { }
. A class can have different access modes Valid Access modifiers are:
Identifiers
An identifier is a sequence of one or more characters. The first character must be a valid first character (letter
, $
, _
). Each subsequent character in the sequence must be a valid nonfirst character (letter
, digit
, $
, _
).
Keywords
Variables
In Java variables are devices that are used to store data, such as a number, an array, an object, or a string of character data. Java is considered as a strongly typed programming language so all variables should be declared as a type before they can be used. Variables follow the same naming conventions as other Java structures except variable start with a lowercase letter.
Methods
A method is a similiar to functions in C++ or PHP.
Let's get started with a variables/methods program!