This chapter contains examples that demonstrate the basic syntax of Java; it is meant to be used in conjunction with Chapter 2 of Java in a Nutshell. If you have substantial programming experience with C or C++, you should find the material in this chapter straightforward. If you are coming to Java from another language, however, you may need to study the examples here more carefully.
The most important step in learning a new programming language is
mastering the basic control statements of the language. With Java, this
means learning the if/else
branching
statement and the while
and for
looping statements. Learning to program
well is like learning to do word problems in high-school algebra class:
you have to translate the problem from an abstract description into the
concrete language of algebra (or, in this case, the language of Java).
Once you learn to think in if
,
while
, and for
statements, other Java statements, such as
break
, continue
, switch
, and try/catch/finally
, should be easy to pick up.
Note that although Java is an object-oriented language, we won’t discuss
objects until Chapter 2.
So, with that as an introduction, and with mastery of basic syntax as our goal, let’s jump right in and start writing Java programs.
Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.