Interactive Java with Java 9’s JShell
Published by Pearson
A hands-on introduction to one of Java’s most significant new learning, discovery and developer-productivity-enhancement features since its inception 20+ years ago.
JShell is one of Java’s most significant new learning, discovery and developer-productivity-enhancement features since its inception 20+ years ago. The Java community—by far the largest programming-language community in the world—has grown to more than 10 million developers. But along the way, not much has been done to improve the learning and discovery processes for new and experienced developers. That changes dramatically in Java 9 with the introduction of JShell—Java’s REPL (read-evaluate-print loop).
What is JShell?
What’s the magic? It’s simple. JShell provides a fast and friendly environment that enables you to interactively explore, discover and experiment with Java language features and its extensive libraries.
JShell’s read-eval-print-loop (REPL) replaces the tedious cycle of editing, compiling and executing in traditional Java development. Rather than complete programs, you write JShell commands and Java code snippets. When you enter a snippet, JShell immediately reads it, evaluates it and prints the results that help you see the effects of your code. Then it loops to perform this process again for the next snippet. In this hands-on course, you’ll work through scores of examples and exercises, and see how JShell and its instant feedback keep your attention, enhance your productivity and speed the learning and software-development processes. JShell is especially valuable for rapidly prototyping small code segments.
Code Comes Alive
Paul Deitel’s books, videos and training courses emphasize the value of live code, focusing on complete, working programs. JShell brings this right down to the individual snippet level. Your code literally comes alive as you enter each snippet. Of course, you’ll still make occasional errors. JShell reports compilation errors to you on a snippet-by-snippet basis and logic errors can immediately become apparent.
Kinds of Snippets
Snippets can be expressions, individual statements, multi-line statements and larger entities, like methods and classes. JShell supports all but a few Java features, but there are some differences designed to facilitate JShell’s explore-discover-and-experiment capabilities. In JShell, expressions and statements do not need to be in methods, methods do not need to be in classes, and you do not need a main. Eliminating this infrastructure saves you considerable time.
Discovery with Auto-Completion
The course includes a detailed treatment of auto-completion—a key discovery feature that speeds the coding process. After you type a portion of a name (a class name, method name, variable name, etc.) and press the Tab key, JShell completes the name for you or provides a list of all possible names that begin with what you’ve typed so far. You can then easily display method parameters and even the documentation that describes those methods.
Rapid Prototyping
Professional developers will commonly use JShell for rapid prototyping. Once you develop and test a small chunk of code, you can paste it into your larger project.
What you’ll learn and how you can apply it
- See how using JShell can enhance the learning and software-development processes by enabling you to interactively explore, discover and experiment with Java language and API features.
- Start a JShell session.
- Execute code snippets.
- Declare variables explicitly.
- Evaluate expressions.
- Edit existing code snippets.
- Declare and use a class.
- Save snippets to a file.
- Open a file of JShell snippets and evaluate them.
- Auto-complete code and JShell commands.
- Display method parameters and overloads.
- Discover features and explore the Java API documentation in JShell.
- Declare and use methods.
- Forward reference a method that has not yet been declared.
- See how JShell wraps exceptions.
- Use types from packages and modules in JShell sessions.
- Control JShell’s feedback level.
- Solve dozens of JShell exercises and review their answers.
- See a list of additional JShell resources.
- And more.
This live event is for you because...
- You’re a Java developer interested in this major new Java 9 discovery and productivity-enhancement tool.
- You want to see how JShell’s fast and friendly read-eval-print-loop (REPL) environment enables you to quickly explore, discover and experiment with Java language features and its extensive libraries.
- You’re an instructor teaching Java and are interested in JShell’s interactive Java capabilities for use in your courses.
- You’re a new Java developer interested in enhancing your Java 9 learning process.
- You’re a Java 8 developer not planning to use Java 9 immediately, but would like to use JShell for exploration, discovery and experimentation with Java 8 features, such as lambdas and streams
Prerequisites
- Familiarity with Java concepts as presented in Chapters 1-12 and 17 of the Deitel professional book Java 9 for Programmers or Lessons 1-11 and 17 of the Deitel video product Java 8 Fundamentals LiveLessons (each of which is available on SafariBooksOnline.com)
- Before taking this course, you must install the latest JDK 9 Developer Preview and the course’s source-code examples.
- Download the latest JDK 9 for Windows, macOS or Linux: http://jdk.java.net/9/
- Download the source-code for this course (details to follow)
Code Examples Coming Soon.
We also provide Getting Started videos discussing these downloads and the installation steps for Windows and macOS at http://www.deitel.com/books/Java9FP. These videos contain Paul Deitel’s contact information. Also feel free to contact Paul after the course with continuing questions.
Schedule
The time frames are only estimates and may vary according to how the class is progressing.
Section 1: Introduction
Section 2: Installing JDK 9
Section 3: Introduction to JShell
3.1 Starting a JShell Session
3.2 Executing Statements
3.3 Declaring Variables Explicitly
3.4 Listing and Executing Prior Snippets
3.5 Evaluating Expressions and Declaring Variables Implicitly
3.6 Using Implicitly Declared Variables
3.7 Viewing a Variable’s Value
3.8 Resetting a JShell Session
3.9 Writing Multiline Statements
3.10 Editing Code Snippets
3.11 Exiting JShell
Section 4: Command-Line Input in JShell
Section 5: Declaring and Using Classes 5.1 Creating a Class in JShell
5.2 Explicitly Declaring Reference-Type Variables
5.3 Creating Objects
5.4 Manipulating Objects
5.5 Creating a Meaningful Variable Name for an Expression
5.6 Saving and Opening Code-Snippet Files
Section 6: Discovery with JShell Auto-Completion
6.1 Auto-Completing Identifiers
6.2 Auto-Completing JShell Commands
Section 7: Exploring a Class’s Members and Viewing Documentation
7.1 Listing Class Math’s static Members
7.2 Viewing a Method’s Parameters
7.3 Viewing a Method’s Documentation
7.4 Viewing a public Field’s Documentation
7.5 Viewing a Class’s Documentation
7.6 Viewing Method Overloads
7.7 Exploring Members of a Specific Object
Section 8: Declaring Methods 8.1 Forward Referencing an Undeclared Method—Declaring Method displayCubes
8.2 Declaring a Previously Undeclared Method Named cube
8.3 Testing cube and Replacing Its Declaration
8.4 Testing Updated Method cube and Method displayCubes
**Section 9: Exceptions **
**Section 10: Importing Classes and Adding Packages to the CLASSPATH **
**Section 11: Using an External Editor **
Section 12: Summary of JShell Commands 12.1 Getting Help in JShell
12.2 /edit Command: Additional Features
12.3 /reload Command
12.4 /drop Command
12.5 Feedback Modes
12.6 Other JShell Features Configurable with /set
**Section 13: Keyboard Shortcuts for Snippet Editing **
**Section 14: How JShell Reinterprets Java for Interactive Use **
Your Instructor
Paul J. Deitel
Paul J. Deitel, CEO and Chief Technical Officer of Deitel & Associates, Inc., is a graduate of MIT with over 44 years of experience in computing. He holds the Java Certified Programmer and Java Certified Developer designations and is an Oracle Java Champion. He is one of the world’s most experienced programming-languages trainers, having taught professional courses to software developers since 1992. His video courses on platforms like O’Reilly Online Learning have garnered millions of views, with his Java Fundamentals LiveLessons, Python Fundamentals LiveLessons and C# Fundamentals LiveLessons each ranking #1 at various times among thousands of video products. He has delivered hundreds of programming courses to academic, industry, government and military clients of Deitel & Associates, Inc. internationally, including UCLA, SLB (formerly Schlumberger), IBM, Siemens, Sun Microsystems (now Oracle), Dell, Fidelity, NASA at the Kennedy Space Center, the National Severe Storm Laboratory, White Sands Missile Range, Rogue Wave Software, Boeing, Cisco, Puma, iRobot and many more. He and his co-author, Dr. Harvey M. Deitel, are among the world’s best-selling programming-language textbook/professional book/video/interactive multimedia authors.