Skip to main content
Logo image

Problem Solving with Algorithms and Data Structures using Java: The Interactive Edition

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” 1 . For detailed information on the many classes that Java provides, see the Java API documentation 2 . Our goal here is to acquaint you with the language and also reinforce some of the concepts that will be central to later chapters.

Note 1.7.1. Java Note.

Java is a big language, and we can cover only some of its important parts in the next few pages. In the rest of the book, when there’s a Java construct that we haven’t covered yet, we’ll put it in a “Java Note” like this one.
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.