Java Reference
In-Depth Information
continued
show them. By default, neither the Eclipse console nor the Windows console
offers support for this (showing Unicode code characters in GUI applications,
however, will work). On Linux—another operating system—the console does
support Unicode character output.
This all being said, I'm sure you will agree that character encodings,
Internationalization, and Unicode is a complex affair. In fact, this is not a
problem with Java itself. Java actually provides very solid Unicode support
compared to most other programming languages. This problem plagues all
aspects of computing, programming, and software engineering. Computers
in the 80s did not deal with languages other than English and thus supported
only a very small, basic set of characters, the effects of which still have an
impact on programming languages today. As such, I will keep things simple
throughout this topic and work with basic Western characters only.
The class' body is surrounded by curly brackets, { and } . Within this body, you define the variables
(the data) and the methods (the behaviors) of the class. Variable definitions start with a variable
type, followed by one or more variable names, followed by a semicolon (used at the end of each
statement in Java). Here are some examples:
int id;
String firstName, lastName;
double discountPercentage;
Observe the use of the comma ( , ) as a shorthand to define variables of the same type. That is, you
could also write String firstName, lastName; as:
String firstName;
String lastName;
Recall the naming convention of writing variable names in lowerCamelCase , whereby each word
in the variable name is capitalized, except for the first one, which starts with a lowercase letter.
This convention helps to distinguish variables from class names. Note that this convention is not as
widely adhered to as CamelCase for class names. That is, you might find code that uses snake_case
(using underscores) as well.
You will learn about variable definitions in a little more detail later. For now, you'll continue look-
ing into the basic class definition, and seeing how you extend it to add method definitions:
class CLASSNAME {
// VARIABLE DEFINITIONS
// METHOD DEFINITIONS
}
The following Try It Out shows you how to add some simple methods to the Student and Course
classes.
Search WWH ::




Custom Search