Many of my trainings use Java one way or another, either as a programming language for developing automatic tests, or as a virtual machine for running Java applications - testing tools, development environments, and even the GotoWebinar video conferencing client requires Java.
Therefore, I decided to describe the procedure for installing Java for the Windows operating system and then setting up the system, because, unfortunately, just “starting the installer and always clicking the Next button” is not enough.
3. What to install, JRE or JDK?
Java Runtime Environment, or JRE is a virtual machine that allows you to run applications written in the Java programming language.
Java development kit, or JDK is a set of tools for developing programs in the Java programming language (compiler, archiver, documentation generator, and others). JRE, of course, is also part of the JDK distribution.
The rule is very simple: if you are going to write something in the Java programming language, then you need the JDK. And if you only run ready-made programs - then JRE is enough.
5. Setting environment variables
Unfortunately, the Java installer does not configure the environment variables, so you will have to do this manually after installation.
First, you need to set the JAVA_HOME variable, which should point to the directory where Java is installed. Many programs use this variable to determine where Java is located.
Secondly, you need to add the path to the% JAVA_HOME% bin directory to the PATH variable. This variable tells the operating system a list of directories in which to look for executable files, and so that Java can be launched from the console, the PATH variable must be correctly configured.
To set environment variables, you first need to open the computer’s properties, either using the Win-Pause keyboard shortcut or through the Start menu:
Then you need to select “Advanced system parameters”, in the dialog that opens, go to the “Advanced” tab and click the “Environment variables” button, after which the dialog for setting environment variables will appear.
If you already have a JAVA_HOME environment variable - you need to edit it; if not, create a new one. As the value, you need to specify the path to the directory where Java is installed, that is, for example c: Program Files Java jdk1.8.0_25 , if you installed JDK, or c: Program Files Java jre1.8.0_25 if you installed only JRE.
After you set the value of the JAVA_HOME variable, you need to edit the value of the PATH variable by adding the path to the directory where the Java executables are located, that is% JAVA_HOME% bin
And save all this by closing all open dialogs in the reverse order with the OK buttons.
Please note that if you install JDK, then the version number is indicated in the name of the directory, therefore later, when you decide to install a newer version, do not forget to change the value of the JAVA_HOME environment variable.
After you have changed the environment variables, the new values will be valid only for new programs that are started, already running programs will not know that the environment variables have changed. Therefore, if, for example, you tried to start Java from the console and did not succeed due to incorrect settings of the PATH variable, you will have to restart the console after you change the value of the variable.
6. Removing unnecessary files
Launch the console (cmd) and execute the where java command in it.
As a result, you should see the path to the java.exe executable file, which the operating system should successfully detect in the place where you installed Java. If the file was not found, then the PATH variable is incorrectly configured and you need to return to the previous paragraph.
However, sometimes it happens and vice versa, there are "extra" executable files:
This happens due to the fact that the Java installer, instead of setting environment variables correctly, tries to put executable files in the C: Windows system32 directory
This is not very good - the system directory is clogged, there may be a mismatch in Java versions (different versions in different directories). Therefore, you must delete the executable files java.exe, javaw.exe and javaws.exe from the C: Windows system32 directory if they are found there.
That's all, now you can use Java. Just do not forget that after installing the new version you will need to update the JAVA_HOME environment variable!
Author: Alexey Barantsev
If you liked this article, you can share it on social networks (buttons below), and then return to the main page of the blog and read my other articles.
Well, if you do not agree with something or want to supplement something - leave a comment below, maybe this will serve as a reason for writing a new interesting article.
Install Java Development Kit
- Go to the Oracle website and download the JDK for your platform.
- After downloading, extract the resulting archive and run the extracted application.
- During the installation, select the “Development Tool” option and click “Next”.
- After some time, the installation will complete.
So you have installed the Java Development Kit, but that is not all. You must configure it for your system.
Windows JDK setup
- Go to the folder% ProgramFiles% Java \% version of the jdk% bin you installed, click on the properties of any file in this folder and copy the path to it.
- Go to the properties of your computer, open the "Advanced" tab, click "Environment Variables ...". In the window that opens, create a new variable, name it Path, paste the path you copied earlier into its value.
- Now the most important thing. Open a command prompt and type javac to verify that the JRE is installed and configured. If you get a list of arguments to the javac command, then congratulations, you have successfully installed and configured everything you need to use Java!
After installing the JDK and JRE it will not hurt to install one of the IDEs on the computer.
First, let's figure out what is IDE.
IDE (Integrated Development Environment) is a set of software tools used by programmers to develop software. The IDE makes it easy to write, run, debug, and test code.
For writing complex programs, it is advisable to use an IDE. We will consider the most popular.
Yes, and in a notebook you can write code! For development, you only need to install the JDK and specify the path to it. Write code in notepad, compile using the command line. However, for the development of complex programs, this is not the best option due to the lack of any additional features present in advanced IDEs.
NetBeans is the choice of professional Java developers. It has unique features and tools that will allow you to make your program cross-platform, and the code readable. NetBeans not only supports Java, but also other programming languages for desktop and web development. It is completely free, you can download it from the official site. Here are just a few of its features:
- code formatting,
- installation of third-party libraries,
- simple graphical interface
- and many many others…
Eclipse, like Netbeans, is one of the most popular IDEs. It provides an impressive intuitive interface and a productive development environment that allows you to comfortably develop Java applications. Eclipse can be downloaded for free from the official site. Benefits:
- the ability to format the code as you like,
- support for breaking code into modules,
- ease of use of the same code in different projects,
- viewing the contents of libraries,
- convenient interface.
IntelliJ IDEA is a well-known IDE for Java, written, oddly enough, in Java. It is equipped with unique tools and allows you to navigate the program without problems. Finding bugs and debugging code has never been so easy as with IntelliJ IDEA.
JCreator is the advanced and fastest Java IDE written in C ++.