How to run a java file on a computer. Running applications from a script


One of the favorite questions of beginning programmers in Java (and not only in Java)
Let's start with compiling and running.
Firstly, Java applications cannot do without a virtual machine; for you to have one, roughly speaking, you need to install the JDK (Java Development Kit), you can download it directly from the Oracle website, .
Let's look at the environment variables that we have.
This is done like this: right click mouse to "My Computer" -> "Properties" -> "Advanced" -> "Environment Variables".
The PATH variable must contain the path to the JDK executable files, where java.exe (virtual machine, which executes byte code compiled by the javac.exe utility) and javac.exe(compiler, translates files with java extension into byte code, files with class extension)
So let's start by organizing the folders.
For example, for a console game about a grandmother, we create a Game folder.
Next we need to create a folder in it classes And src.
IN src we will store files java.
IN classes compiled class files.

Let's use the example from the article.
In folder src create a folder babgame.
Each package package- this is a folder, and babgame We have a package, don't forget.
It is recommended to name packages after domain names, because The package name is unique. For example, if we have a package su.clan.pr0gram, then you will need to create three subfolders, first su, then clan and at the end pr0gram, and it already contains the files of our program.
We create a file with the java extension in babgame and write the program code there, save it, exit babgame, then from src, we will get to Game.
Writing a script for the console - compile.cmd

Javac -classpath ./classes -d ./classes -s ./src src/babgame/Main.java -encoding Cp1251
pause


pause can be removed, this is a delay in case the compiler generates errors.
javac- as you probably already understood, this is a compiler; it accepts a couple of dozen parameters, a couple of which we used.
-classpath ./classes- indicate in which folder we have classes
-d ./classes- indicate in which folder the class files will be generated
-s ./src- indicate the folder with the sources (in principle, you don’t have to write)
src/babgame/Main.java- the file itself is in the src folder (for me it’s called Main.java)
By the way, don’t forget, the name of the class described in a file with the java extension must match the name of the file (without extension) (in some systems even the case of writing, lower or upper, depends)
-encoding Cp1251- specifies in which encoding the file should be read from source code programs. (it is assumed that the source is written for Windows)

The compiled file will be placed in the folder classes.
We write the following script:
run.cmd

Java -Dfile.encoding=Cp866 -classpath ./classes Main


java- runs our class file.
-Dfile.encoding=Cp866- indicates in which encoding the output should be produced.
Since our console outputs to Cp866 by default, we’ll do that.
-classpath ./classes- indicate the folder where we store classes.
Main- the name of the class where we have the main() method, without which, as we know, the program will not start.

We create these two scripts in the directory Game, let me remind you again.
Well, that's all, you can play until the morning!

If the browser plays videos without problems, the sites are full of online applications and delight with various convenient functions- Means, Java plugin turned on and working fine. Java is used by most websites, so if they incorrect operation there is a need to figure out how to enable support for this technology.

For Google Chrome: enter in address bar browser command "about:plugins". In the list of plugins, find Java and check its status. If “Enable” is displayed, click on it. When the plugin is enabled, the message “Disable” appears on the screen. So that you don't have to confirm in the future. enabling Java, check the box next to “Always allowed”. You may encounter a situation where Java is not installed at all. Then you can follow the link and check it by clicking on the corresponding line. If the service detects the absence of a Java plugin, you will be prompted to download and install it. After successful installation, a request to enable Java will appear in the browser window, or you will need to enable it in the manner described above. For Mozilla FireFox: Call up the browser menu (top right of the screen) and go to the “Add-ons” section. In the window that opens, go to the “Plugins” tab and find the Java (TM) Platform programs already installed in the list. Set the parameter value Java works"Always turn on." If Java is not in the list of plugins, you must first install it using the link. For Opera: since this browser already has built-in Java components, it is enabled simultaneously along with all plugins. To do this, in the “Settings” menu, find the “Websites” tab, then activate the “Launch automatically” item in the “Plugins” section. For Internet Explorer: in the browser menu item, which can be opened by clicking on the gear icon on the right top corner screen or by pressing Alt+X, select “Internet Options”. Then find the “Security” tab and click on the “Other” button. An impressive list of parameters will appear, among which you need to find the item “Run script Java applications" and turn it on. For Yandex Browser: enabling Java is performed almost identically to this process in Chrome. Write "browser://plugins" in the address bar and press "Enter". A window with a list will open installed plugins. If the Java plugin is disabled, the Enable command will be active and the font will be light. After enabling, check the box next to “Always allow” and close the settings window.

Now you know not only how to enable Java support in your browser. If problems arise with other plugins, the algorithm of actions will be the same. Please note that Java and JavaScript are not the same thing, and support for the latter is enabled in a completely different way.

Language Java programming is rapidly gaining popularity due to its simplicity and functionality. Many mobile and computer applications written in this language. It is worth noting that applications for Android devices are written in Java.

Download Java is available on the official website completely for free. However, there may be a problem with the program version. First of all, you have to choose between 32-bit And 64-bit version. If the computer allows it, then of course it’s better to stop at 64, it’s not so strict restrictions on memory usage.

Then you need to decide - install Java Development Kit (JDK) or Java Runtime Environment (JRE). Everything is extremely simple and clear if you translate the abbreviation. JDK is a development kit. It is used to create programs in this language.

JRE It only allows you to launch applications. By the way, it is included in the JDK.

Installing the package

Installation is no different from other applications. For example, let's take the package installation JDK.

Environment Variable Settings

Unfortunately, the installer does not include all necessary settings, That's why variable environment must be configured manually.

First of all, you will need to indicate variablejava_ home, which contains the path to the folder where Java is installed. This variable use many programs to watch location Java.

Then you need to put it into a variable path register the location %JAVA_HOME%\bin. She's using operating system to see a list of folders where you can find the executable file. She also used to run Java from the console.

First you need to go to computer properties. Anyone can do this in a convenient way, for example call context menu My computer and click Properties, or press the combination Win+Pause.

Now let's open Extra options systems, and in the next window go to the bookmark Additionally. Here we go to Environment Variables(button below).

If the system variables are already entered Java_ home then you need it edit. If it doesn’t exist, then we create a new one. Here we will need set path To Java installed. Eg c:\Program Files\Java\jdk\ or any other where the installation was carried out.

Now you need to make changes to the variable Path. Here we indicate the path to the folder where it is located executable files, For example %JAVA_HOME%\bin.

Now close all windows by pressing OK, saving the changes.

It is worth noting that for the JDK, the installation folder contains numbers– package version. Therefore, every time you update, you need to change the directory in JAVA_ HOME, otherwise the program simply won’t start.

Removing unnecessary files

Now it remains clean system from unnecessary files. To do this we launch command line (cmd). Then we use the command where java. The console should display the Java installation path. If directory not found– this means the path variable is filled incorrectly. However It happens that the system finds several executable files.

This is due to the fact that installer tries incorrectly tune Environment Variables. Those. tries to install them into a folder system32 .

This is bad because... system directory gets clogged and you can expect the program to not work correctly. In this case, follow the path indicated in the console and delete all files: java.exe, javaws.exe and javaw.exe. If some of these files are not found, then delete only those located in the folder.

You can run applications of any format on your computer. Nowadays, programs and games on Android are very common; they can be launched through special emulators.


Java games and programs were once very popular, and some people still use them.

A Java emulator on your computer helps you run any application without a mobile device.

Why might this be needed? For example, if you are talking about an application and want to take screenshots, you can run it through an emulator and show people the capabilities (many people still use Java-enabled phones).

How to run Java on a computer?

Many high-quality emulators have been developed, each of them copes with its main purpose, but we recommend. It's free to use and easy to find online. What functions does this software have?

  • supports 3D graphics;
  • allows you to zoom in and out of the screen;
  • You can record video through it;
  • window size changes;
  • there is a virtual keyboard;
  • you can connect to the Internet;
  • any types of applications are supported;
  • SMS sending is tracked.

The program has many other functions and settings that will definitely be useful to you. When you install the emulator, immediately go to the settings. First of all, select the device that will be emulated, and also set the window size:

After that, go to the second settings tab “KeyMap”. Here you can set the control keys:

Install them at your own discretion, because everyone has their own ideas about convenience. It is better not to touch the remaining settings items. Close the window and go through the main menu to launch.

If the Russian version is used, then everything is simple, but if the English version is used, then select Midlet and then Load jar. All that remains is to specify the path to the JAVA file:







2024 gtavrl.ru.