How To Install JDK 15 and Notepad (On Windows) and Get Started With Java Programming
How To Install JDK 15 and Notepad (On Windows) and Get Started With Java Programming
Notepad++ (Windows)
and Get Started with
Java Programming
Object Oriented Programming EE- 57
This article is based on the Oracle JDK (@ https://www.oracle.com/java/) (due to legacy), which
is free for personal and development use but no longer free for commercial use.
JDK Versions
1. JDK Alpha and Beta (1995): Sun Microsystem announced Java in September 23, 1995.
2. JDK 1.0 (January 1996): Originally called Oak (named after the oak tree outside James Gosling's
office). Renamed to Java 1 in JDK 1.0.2.
3. JDK 1.1 (February 1997): Introduced AWT event model, inner class, JavaBean, JDBC, and RMI.
4. J2SE 1.2 (JDK 1.2) (December 1998): Re-branded as "Java 2" and renamed JDK to J2SE (Java 2
Standard Edition). Also released J2EE (Java 2 Enterprise Edition) and J2ME (Java 2 Micro Edition).
Included JFC (Java Foundation Classes - Swing, Accessibility API, Java 2D, Pluggable Look & Feel,
and Drag & Drop). Also introduced Collection Framework and JIT compiler.
5. J2SE 1.3 (JDK 1.3) (May 2000): Introduced Hotspot JVM.
6. J2SE 1.4 (JDK 1.4) (February 2002): Introduced assert statement, non-blocking IO (nio),
logging API, image IO, Java webstart, regular expression (regex) support.
7. J2SE 5.0 (JDK 5) (September 2004): Officially called 5.0 instead of 1.5 (by dropping the 1.).
Introduced generics, autoboxing/unboxing, annotation, enum, varargs, for-each loop, static
import. See "JDK 5 New Features".
8. Java SE 6 (JDK 6) (December 2006): Renamed J2SE to Java SE (Java Platform Standard Edition).
No new language features. See "JDK 6 New Features".
9. Java SE 7 (JDK 7) (July 2011): First version after Oracle purchased Sun Microsystem - aslo called
OracleJDK. Introduced Strings in switch statement, Binary integer literals, allowing underscores
in numeric literals, improved type inference for generic instance creation (or diamond operator
<>), Catching multiple exception types and rethrowing exceptions with improved type checking.
See "JDK 7 New Features".
10. Java SE 8 LTS (JDK 8) (March 2014): Included support for Lambda expressions, default and static
methods in interfaces, improved collection, and JavaScript runtime. Also integrated JavaFX
graphics subsystem. See "JDK 8 New Features".
11. Java SE 9 (JDK 9) (September 21, 2017): Introduced modularization of the JDK ( module) under
project Jigsaw, the Java Shell (jshell), and more. See "JDK 9 New Features".
12. Java SE 10 (18.3) (JDK 10) (March 2018): Introduced var for type inference local variable (similar
to JavaScript). Introduced time-based release versioning with two releases each year, in March
and September, denoted as YY.M. Removed native-header generation tool javah. See "JDK 10
New Features".
13. Java SE 11 LTS (18.9) (JDK 11) (September 2018): Extended var to lambda expression.
Standardize HTTP client in java.net.http. Support TLS 1.3. Clean up the JDK and the
installation package (removed JavaFX, JavaEE, CORBA modules, deprecated Nashorn JavaScript
engine). OracleJDK is no longer free for commercial use, but OpenJDK is still free. See "JDK 11
New Features".
14. Java SE 12 (19.3) (JDK 12) (March 2019): Switch Expression (preview). See "JDK 12 New
Features".
15. Java SE 13 (19.9) (JDK 13) (September 2019): Switch Expression (preview), Multi-line Text Block
(preview). See "JDK 13 New Features".
16. Java SE 14 (20.3) (JDK 14) (March 2020): Records (preview)
17. Java SE 15 LTS (20.9) (JDK 15) (September 2020):
"JDK" or "JRE"?
JRE (Java Runtime), which include a Java Virtual Machine and core libraries, is needed for
running Java programs. JDK (Java Development Kit), which includes JRE plus the development
tools (such as compiler and debugger), is need for writing as well as running Java programs. In
other words, JRE is a subset of JDK. Since you are supposed to write Java Programs instead of
merely running Java programs, you should install JDK, which includes JRE.
I recommend that you install only the latest JDK. Although you can install multiple versions of
JDK/JRE concurrently, it is messy.
If you have previously installed older version(s) of JDK/JRE, un-install ALL of them. Goto
"Control Panel" ⇒ (optional) "Programs" ⇒ "Programs and Features" ⇒ Un-install ALL
programs begin with "Java", such as "Java SE Development Kit ...", "Java SE Runtime ...", "Java
X Update ...", and etc.
Run the downloaded installer. Accept the defaults and follow the screen instructions to complete
the installation. By default, JDK is installed in directory "C:\Program Files\Java\jdk-
15.0.{x}", where {x} denotes the update number.
Launch "File Explorer". Navigate to "C:\Program Files\Java" to inspect the directories. Take
note of your JDK Installed Directory jdk-15.0.{x}, in particular, the update number {x}
which you will need in the next step.
I shall refer to the JDK Installed Directory as <JAVA_HOME>, hereafter, in this article
(corresponding to environment variable %JAVA_HOME% in Windows or $JAVA_HOME in
Unix/macOS).
Step 3: (SKIP for JDK 15) Include JDK's "bin" Directory in the PATH
Windows' Command Prompt (CMD) searches the current directory and the directories listed in the
PATH environment variable for executable programs.
JDK's programs (such as Java compiler "javac.exe" and Java runtime "java.exe") reside in
the sub-directory "bin" of the JDK installed directory. JDK's "bin" needs to be added into the
PATH.
Prior to JDK 15, you need to explicitly add JDK's "bin" into the PATH. Starting from JDK 15, the
installation process adds the directory "C:\Program Files\Common
Files\Oracle\Java\javapath" to the PATH. The "javapath" directory is a link to
"javapath_target_xxxxxx", which contains a copy of the following JDK programs:
Link is used so that you can keep multiple copies (versions) of JDK.
1. Launch "Control Panel" ⇒ (Optional) "System and Security" ⇒ "System" ⇒ Click "Advanced
system settings" on the left pane.
2. Switch to "Advanced" tab ⇒ Click "Environment Variables" button.
3. Under "System Variables" (the bottom pane), scroll down to select variable "Path" ⇒ Click
"Edit...".
4. For Newer Windows 10:
You shall see a TABLE listing all the existing PATH entries (if not, goto next step). Click "New" ⇒
Click "Browse" and navigate to your JDK's "bin" directory, i.e., "c:\Program
Files\Java\jdk-15.0.{x}\bin", where {x} is your installation update number ⇒ Select
"Move Up" to move this entry all the way to the TOP.
5. For Older Windows 10 (Time to change your computer!):
(CAUTION: Read this paragraph 3 times before doing this step! Don't push "Apply" or "OK"
until you are 101% sure. There is no UNDO!!!)
(To be SAFE, copy the content of the "Variable value" to Notepad before changing it!!!)
In "Variable value" field, APPEND "c:\Program Files\Java\jdk-15.0.{x}\bin" (where
{x} is your installation update number) IN FRONT of all the existing directories, followed by a
semi-colon (;) to separate the JDK's bin directory from the rest of the existing directories. DO
NOT DELETE any existing entries; otherwise, some existing applications may not run.
You need to re-started CMD for the new environment settings to take effect.
1. (Skip for JDK 15) Issue "path" command to list the contents of the PATH environment variable.
Check to make sure that your JDK's "bin" is listed in the PATH.
path
PATH=c:\Program Files\Java\jdk-15.0.{x}\bin;other entries...
2. Issue the following commands to verify that JDK/JRE are properly installed and display their
version:
3. Launch a programming text editor (such as TextPad, NotePad++, Sublime Text, Atom). Begin
with a new file and enter the following source code. Save the file as " Hello.java", under your
work directory (e.g., d:\myProject).
/*
* First Java program to say Hello
*/
public class Hello { // Save as "Hello.java" under "d:\myProject"
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
d:
D:\xxx>
3. Set the Current Working Directory to the directory that you saved your source file via the cd
(Change Directory) command. For example, suppose that your source file is saved in directory
"myProject".
cd \myProject
D:\myProject>
4. Issue a dir (List Directory) command to confirm that your source file is present in the current
directory.
dir
......
xx-xxx-xx xx:xx PM 277 Hello.java
......
5. Invoke the JDK compiler "javac" to compile the source code " Hello.java".
javac Hello.java
// If error message appears, correct your source code and re-compile
The compilation is successful if the command prompt returns. Otherwise, error messages would
be shown. Correct the errors in your source file and re-compile. Check "Common JDK Installation
Errors", if you encounter problem compiling your program.
6. The output of the compilation is a Java class called " Hello.class". Issue a dir (List Directory)
command again to check for the output.
dir
......
xx-xxx-xx xx:xx PM 416 Hello.class
xx-xxx-xx xx:xx PM 277 Hello.java
......
java Hello
Hello, world!
Everything that can possibly go wrong will go wrong: Read "JDK Installation Common Errors".
When software goes wrong, the MOST IMPORTANT thing to do is to FIND the ERROR
MESSAGE, which can give you clues of what went wrong. If things were running fine until the
lightning strikes, ask yourself what have you CHANGED!
Stack Trace. Most of the times, the error message consists of tens of lines of so-called stack
trace of method invocation. That is, method A called method B, which called method C, and so
on, until method Z encountered an error and threw an Exception or an Error. It is important to:
1. Get to the first line of the error message to read the description, and
2. Look for the line number of YOUR PROGEAM that triggered the error.
For example, this error message (stack trace) has 40 over lines:
The text editor that we will be using in the Class for creating our Java
programs is called Notepad++ and is freely available for the Windows
operating system. Freely available at http://notepad-plus-plus.org .This document
describes how to install and configure Notepad++ using the settings to run java.
Short-‐cut keys
Define the function and the corresponding short-cut keys for running Java
programs:
Then choose Save... and,using the name "Run Java", save this script (see
below):
Press OK
Now select "Run Java" from under the "Associated script:"menu, and click
the “Add/Modify" button.
You should see the "Run Java" script added in the "Menu
items" box as shown below:
JAVA
Note that you may first have to remove Ctrl 1 shortcut from one of the commands
in the Main menu list of commands (the list on the left most menu).
19 Object Oriented Programming | EE-57
20
Double-‐click the "Run Java" script name to bring up the "Shortcut" box. In this
box, you can enter the desired short cut for the "Run Java" script. Select CTRL+1 as
shown below:
RUN JAVA
and then click the "OK" button and close the window.
In Java, every application begins with a class name, and that class must
match the filename.
Let's create our first Java file, called Main.java, which can be done in any
text editor (like Notepad).
The file should contain a "Hello World" message, which is written with the
following code:
You should now be able to use the short-‐cut keys(or you can select them from
the "Macro" menu) to run your program:
RUN JAVA
SUCCESS
TORUBLESHOOTING NOTEPAD+++
Sometimes things don't work as planned. Two things which may not work
when you install Notepad++ are
1. Short-‐cut keys. Please note that the script for running a Java program is:
cd "$(CURRENT_DIRECTORY)"
Open this folder and you will find your java and javac executable:
Note that sometimes the executable starts with lower case 'j') If the path to your
java.exe or javac.exe is different to the one shown in these notes, then change
the script accordingly:
cd "$(CURRENT_DIRECTORY)"
C:\WHATEVER_YOUR_PATH\bin\javac "$(FILE_NAME)"
2. NppExec Plug-in. Please note that the script for running a Java program is: