Section 1.7 Review of Basic Java
In this section, we will review the programming language Java and also provide some more detailed examples of the ideas from the previous section. If you are new to Java or find that you need more information about any of the topics presented, we recommend that you consult a resource such as
“The Java™ Tutorials”. For detailed information on the many
classes that Java provides, see
the Java API documentation. Our goal here is to acquaint you with the language and also reinforce some of the concepts that will be central to later chapters.
Java is an object-oriented programming language. It has a powerful set of built-in data types and control constructs. Although Java is a compiled language, a program named
jshell allows you to try out Java statements interactively without having to write a complete program. When you run
jshell, it displays
jshell> as its prompt and then evaluates the Java constructs you provide. For example,
jshell> System.out.println("Algorithms and Data Structures")
Algorithms and Data Structures
jshell> 12 * 144;
$1 ==> 1728
The first two lines show the prompt, the
System.out.println function (which prints out its argument, followed by a newline), the result, and the next prompt.
The next prompt evaluates an expression; the
$1 is a temporary variable created by
jshell to hold the calculated value. If we were to evaluate another expression, it would be assigned to
$2, and so on.
You have attempted
of
activities on this page.