Java Reference
In-Depth Information
Java Beans
A Java bean is a reusable software component that can be visually manipulated in a builder tool.
These tools allow beans to be customized by setting their properties and specifying how they react
to events.
Java language structure
This section provides a brief overview of the Java language structure. Many of the concepts
addressed will then be further elaborated on in subsequent chapters. Let's consider the following
running example of a Java program calculating BMI to illustrate the discussion.
public class BMICalculator {
// declare variables
double weight;
double height;
double BMI;
public BMICalculator(double w, double h) {
weight = w;
height = h;
}
public double calculateBMI() {
return weight / (height * height);
}
// This is our main method.
public static void main(String[] args) {
BMICalculator calculator = new BMICalculator(60, 1.70);
double bmi = calculator.calculateBMI();
// print BMI to screen
System.out.println("Your BMI is " + bmi + ".");
}
}
Before you start discussing this example in more detail, let's quickly note a few things. First, note
that Java is a form-free language and does not require special indentation. Any statement can start
at any place of indentation. Also, extra whitespace, tabs, and new lines are ignored by the compiler.
The program can thus be formatted in many ways. To improve the readability of your code, it is
highly recommended that you use a consistent formatting style. This topic always formats the code
according to convention. This makes it easy to read and also helps you get used to a standard for-
matting style.
The program contains several statements, each ending with a semicolon ( ; ). A statement performs
a specific action and can span multiple lines. The bytecode corresponding to this program was
 
Search WWH ::




Custom Search