Useful Tips

Send request


Many of my trainings use Java one way or another, either as a programming language for developing autotests, 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.

Step 2: Install JDK from file

There should not be any difficulties here either - I did not see a fundamental difference between versions 1.4, 1.5, 1.6 and 1.7. We launch the downloaded file and after some waiting you will see a start screen for installation. Click "Next."

On the next screen you will be offered a directory for installation. I like installing in a non-default directory more. (it is highlighted in red). Click the "Change ..." button.

In the window that appears, set the directory "C: Java jdk1.7.0_03". After that, I strongly advise you to select this path and save it to the clipboard (a little later we will use it). Then click "OK."

After that, you can see the installed directory in the window. Press the “Next” button again.

After a while, the JDK installation will almost end, but you will also have to install the JRE (Java Runtime Environment). You will immediately see this in the form that should appear. There is no need to change the directory - feel free to click “Next”.

For a while you will see a screen that says that 3 billion devices use Java.

Finally, you will see that the installation is finished.

In version 1.7, another step appeared - the choice of installing JavaFX 2.0. You will have a screen for selecting a directory (I did not really like how it is implemented). But in general, you can just click the "Next" button. Because I have a bad attitude to diretoria with a space, then I chose my option.

Step 3: Set environment variables - JAVA_HOME and PATH

On this installation is almost complete. All that remains to be done is one more step - to register the path to the JDK files in the operating system paths. This will allow us to run the main files from the command line - a convenient moment. And we will also set the JAVA_HOME variable - it’s true that we will not come in handy soon, but we will do it right now. I think most of you know how to do this. But let's do it all together. I am using Windows 7.0 - so I will demonstrate on it. In the "Start" menu, find the item "Computer" and right-click on it. In the menu that appears, select the "Properties" item. A window will appear

We select the item "Advanced system parameters" (I highlighted this item). We will receive a window in which it is necessary to select the item "Environment variables".

In the window that appears, you need to create one variable - "JAVA_HOME". And edit the "Path" variable. To do this, click the "Create" button.

The option to set the variable "JAVA_HOME" is shown in the figure. This is where the line that I suggested you remember when installing the JDK is useful.

To set the “Path” variable, you probably don’t need to create it - it usually already exists. So you need to find it in the list and click the "Change" button. But be careful - first of all, you need to enter a line by pre-setting "," at the end of the list of all paths. And secondly - you need to add the line " bin" after. An example is shown in the figure.

And again - BE CAREFUL when editing PATH - it contains important information. Do not completely erase it and leave only your line. It is necessary after the semicolon to ADD the line to the directory with the JDK (+ line " bin"). Those. if you have JDK installed in the directory C: Java jdk1.7, then in PATH you need to add (via ",") the line C: Java jdk1.7 bin.
Now we have taken all the necessary steps to install the JDK - it's time to start writing a simple program. Main steps

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 the JDK, the version number is indicated in the name of the directory, so 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.

Download the JDK (Java Development Kit)

We go to the company website Oracle and download the installation file from here

On the download page, select your version of Java (Android Studio requires version 7 or 8) and click download JDK:

In the table Java SE Development Kit we agree with the terms by selecting Accept License Agreement and download the package for your OS:

For example, for Windows you should select a file jdk-XuXXX-windows-x64.exe for 64-bit (Windows x64) or jdk-XuXXX-windows-i586.exe for 32-bit (Windows x86). The capacity of the system, for example, in Windows 7 can be found as follows: click "Start", right-click "Computer", select "Properties".

Installing the JDK (Java Development Kit)

To install Java, you must have administrator rights (restart the computer if you need to log in with a different account). Check if Java is installed on the computer (Item “Add or Remove Programs in the Windows Control Panel”) and, if so, delete it. Run the installer jdk-XuXX-windows-x64.exe. After starting the installer, the installation windows will be displayed on the screen, it is better not to change anything in them, continue the installation by clicking the Next button. In the last window, click Close.

Add the JAVA_HOME system variable

So that it is possible to compile and execute programs, it remains to register the paths to the Java compiler in the Windows environment variables and restart the computer. To do this, launch the Windows Control Panel and select the "System" item, and in the window that appears on the left - the "Advanced system settings" item. The "System Properties" window opens, in which we click the "Environment Variables" button.

In the window that appears, you need to create a system variable - “JAVA_HOME”. To do this, click the "Create" button. In the field “Variable name” we write “JAVA_HOME”, and in “Variable value” you need to add the path to the installed JDK, namely the path to its bin subdirectory where the compiler file is located. If you did not change anything when installing the JDK, then the path will be like this: "C: Program Files Java jdkVersion Number". The pictures below show an example for Java 7.

In system variables, you need to add the path to the installed JDK

Now you need to edit the “Path” variable. It is necessary to find it in the list and click the “Change” button. Be careful - here you just need to add our path in the "Variable value" field C: Program Files Java jdk1.7.0_79 bin (for the current version of java 8, respectively, jdk1.8.0_121 bin ) by pre-setting “,"At the end of an existing meaning, without deleting anything! An example is shown in the figure.

After making these changes, for the computer to take effect, the computer must be restarted.

After that, you can verify the correct installation of the JDK. To do this, in Windows, click "Start" and enter the command cmd in the “Find programs and files” field, or call up the input window with the Windows + R key combination and enter cmd.

In the console that opens, type java -version and press Enter

In the console that opens, type java -version and press Enter. If you see the java version, and not the error message, everything is fine.

6. Removing excess 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.