Chapter 3. Your First Java Programs
As we discussed in Chapter 1, Java is traditionally understood as a language that is class-oriented and has a distinct compile-interpret-JIT execution model. However, recent developments have extended and generalized this model in ways that are particularly helpful to newcomers to the Java world.
So, in this chapter we will discuss these new technologies and see how they create a new, and much easier, path to writing your first programs in Java. Let’s start by meeting JShell, which is an interactive shell for Java, somewhat similar to the read-evaluate-print loop (REPL) seen in languages like Python, Scala, or Lisp.1
Introduction to JShell
JShell is intended for instruction and exploratory use and, due to the nature of the Java language, is not expected to be as much use to the experienced programmer as similar shells in other languages. In particular, it is not expected that Java will become an REPL-driven language. Instead, it provides a capability to use JShell for a different style of programming, one that complements the traditional use case but also provides new perspectives, especially for working with a new API.
It is very easy to use JShell to explore simple language features, for instance:
-
Primitive data types
-
Simple numeric operations
-
String manipulation basics
-
Object types
-
Definition of new classes
-
Creation of new objects
-
Calling of methods on objects
However, in the examples in this section, we’re not going to explain ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access