Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Java 11 Cookbook

You're reading from   Java 11 Cookbook A definitive guide to learning the key concepts of modern application development

Arrow left icon
Product type Paperback
Published in Sep 2018
Publisher
ISBN-13 9781789132359
Length 802 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Mohamed Sanaulla Mohamed Sanaulla
Author Profile Icon Mohamed Sanaulla
Mohamed Sanaulla
Nick Samoylov Nick Samoylov
Author Profile Icon Nick Samoylov
Nick Samoylov
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Installation and a Sneak Peek into Java 11 FREE CHAPTER 2. Fast Track to OOP - Classes and Interfaces 3. Modular Programming 4. Going Functional 5. Streams and Pipelines 6. Database Programming 7. Concurrent and Multithreaded Programming 8. Better Management of the OS Process 9. RESTful Web Services Using Spring Boot 10. Networking 11. Memory Management and Debugging 12. The Read-Evaluate-Print Loop (REPL) Using JShell 13. Working with New Date and Time APIs 14. Testing 15. The New Way of Coding with Java 10 and Java 11 16. GUI Programming Using JavaFX 17. Other Books You May Enjoy

Installing JDK 18.9 on Windows and setting up the PATH variable

In this recipe, we will look at installing JDK on Windows and how to set up the PATH variable to be able to access the Java executables (such as javac, java, and jar) from anywhere within the command shell.

How to do it...

  1. Visit http://jdk.java.net/11/ and accept the early-adopter license agreement, which looks like this:
  1. After accepting the license, you will get a grid of the available JDK bundles based on the OS and architecture (32/64-bit). Click to download the relevant JDK executable (.exe) for your Windows platform.
  2. Run the JDK executable (.exe) and follow the onscreen instructions to install JDK on your system.
  3. If you have chosen all the defaults during the installation, you will find JDK installed in C:/Program Files/Java for 64 bit and C:/Program Files (x86)/Java for 32 bit.

Now that we have finished installing JDK, let's see how we can set the PATH variable.

The tools provided with JDK, namely javac, java, jconsole, and jlink, are available in the bin directory of your JDK installation. There are two ways you could run these tools from the Command Prompt:

  1. Navigate to the directory where the tools are installed and run them, as follows:
      cd "C:\Program Files\Java\jdk-11\bin"
      javac -version
  1. Export the path to the directory so that the tools are available from any directory in the command prompt. To achieve this, we have to add the path to the JDK tools in the PATH environment variable. The command prompt will search for the relevant tool in all the locations declared in the PATH environment variable.

Let's see how you can add the JDK bin directory to the PATH variable:

  1. Right-click on My Computer and then click on Properties. You will see your system information. Search for Advanced system settings and click on it to get a window, as shown in the following screenshot:
  1. Click on Environment Variables to view the variables defined in your system. You will see that there are quite a few environment variables already defined, as shown in the following screenshot (the variables will differ across systems; in the following screenshot, there are a few predefined variables and a few variables added by me):

The variables defined under System variables are available across all the users of the system, and those defined under User variables for <user name> are available only to the specific user.

  1. A new variable, with the name JAVA_HOME, and its value as the location of the JDK 9 installation. For example, it would be C:\Program Files\Java\jdk-11 (for 64 bit) or C:\Program Files (x86)\Java\jdk-11 (for 32 bit):
  1. Update the PATH environment variable with the location of the bin directory of your JDK installation (defined in the JAVA_HOME environment variable). If you already see the PATH variable defined in the list, then you need to select that variable and click on Edit. If the PATH variable is not seen, click on New.
  2. Any of the actions in the previous step will give you a popup, as shown in the following screenshot (on Windows 10):

The following screenshot shows the other Windows versions:

  1. You can either click on New in the first screenshot and insert the %JAVA_HOME%\bin value, or you can append the value against the Variable value field by adding ; %JAVA_HOME%\bin. The semicolon (;) in Windows is used to separate multiple values for a given variable name.
  2. After setting the values, open the command prompt and run javac -version. You should be able to see javac 11-ea as the output. If you don't see it, it means that the bin directory of your JDK installation has not been correctly added to the PATH variable.
You have been reading a chapter from
Java 11 Cookbook - Second Edition
Published in: Sep 2018
Publisher:
ISBN-13: 9781789132359
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image