Programs for Java programming and education. Download the program without registration and SMS - Programming - Java How to install the java programming environment

Java is an object-oriented programming language created by James Gosling in 1995, which means expressing variables as objects with fields (which are attributes that describe an object) and methods (actions an object can do). Java is a language that allows you to write programs that can run under any Java virtual machine. Since this is a programming language that is quite voluminous in terms of the number of words, it is quite easy to understand and learn even for beginners. This tutorial provides an introduction to Java programming.

Steps

Writing the first Java program

    To start writing Java programs, first of all, install the development environment. Many programmers use an integrated development environment (eng. Integrated development environment- IDE) such as Eclipse or Netbeans, but you can create a program without it.

    Any program like Notepad will suffice for Java programming. Some programmers prefer to use text editors based on vim and emacs. There is also a fairly good text editor that can be installed on both Windows and Linux (Mac, Ubuntu, and so on) - Sublime Text. We will use it in this review.

    Make sure you have the Java Java Development Kit installed. You will need it to compile your program.

    • If your computer is running the Windows operating system and the variable environment is not working correctly, it may throw a javac error. Read for more detailed installation information to avoid this error.

    Hello world program

    1. To begin with, we will create a program that will display the inscription Hello World. Create a new file in a text editor and save it as "HelloWorld.java". "HelloWorld" is the name of the class, which must match the name of the file, this is important.

      Set the class and main method. The main public static void main(String args) method will be applied each time the program starts and will be set in every subsequent Java program.

      public class HelloWorld ( public static void main (String args ) ( ) )

      Enter the line of code "Hello World."

      System. out . println("Hello World.");

      • Consider the components of this line of code:
        • System refers to the system with instructions to perform certain actions.
        • Out tells the system that we are going to enter some data.
        • Println input string - tells the system to print the value to the screen.
        • The parentheses around ("Hello World") indicate that the System.out.println() method takes this value as a parameter.
      • Take note of a few rules to follow when programming in the Java language:
        • You need to put a semicolon at the end of each line of code.
        • Java is case sensitive, so writing method values, variables, and the class name must be case-sensitive.
        • Blocks of code that refer to a particular method are separated by curly braces.
    2. Connect everything together. Your Hello World program should end up looking like this:

      public class HelloWorld ( public static void main (String args ) ( System . out . println ("Hello World." ); ) )

    3. Save the file and open a command prompt or terminal to compile the program. Go to the folder where you saved the HelloWorld.java file and type in Javac (java language optimization compiler) HelloWorld.java. This way you let the compiler know that you want to convert the file. If errors pop up in the process, the compiler will notify you of what you did wrong. Ideally, you should not have any notifications from the compiler at all during the file conversion process. After compiling, look in the folder where the HelloWorld.java file was saved - the HelloWorld.class file should appear there. It will be used to run the Java virtual machine.
    4. Run the program. We have finally reached this point! At the command prompt or terminal, type in java HelloWorld. The virtual machine will understand in this way that you want to run the HelloWorld class. HelloWorld should appear in the console.
    5. Congratulations, you have created your first Java program.

    Input and Output

    1. Now we need to extend our Hello World program to accept user input. In our program, we printed a string that is visible to the user, but in interactive programs, users enter data in applications. Our task is to extend the program so that it prompts the user for a name and then greets him by name.
    2. Import the Scanner class. Java has built-in libraries that we have access to, but we need to import them. One such library is java.util, which contains the Scanner object we need for user input. In order to import this class, we need to add the following line to the source code.

      Import java.util.Scanner;

      • This tells the program that we want to use the Scanner object that exists in the java.util package.
      • If we want to access all the objects in the java.util. library, we just need to import java.util.* at the beginning of the code.
    3. You need to introduce a new variable in the method for the Scanner object. Java is an object-oriented programming language that operates on variables through objects. A scanner is an example of an object that has fields and methods. In order to use the Scanner class, we need to create a new Scanner object with which we can fill in the fields. To do this, we write the following:

      Scanner userInputScanner = new Scanner(System.in);

      • userInputScanner is the name of the scanner object we just set up. Note that the name is written in "humped case". This is the convention for naming variables in Java.
      • We use the new operator to create a new object instance. In our case, we created a new instance of the Scanner object by specifying new Scanner(System.in) in the code.
      • The Scanner object picks up a parameter that tells the object what to scan. In this case, System.in is the parameter. System.in tells the program to scan the user's input.
    4. The next step is to make it clear to the user that they need to enter data in the console. This can be done with the System.out.print or System.out.println command.

      System.out.print("What"s your name?");

    5. Have the Scanner object pick up the next line the user enters and store it as a variable. Scanner should always collect data entered by the user. The following line of code will instruct the Scanner object to recognize the user-written name and store it as a variable:

      String userInputName = userInputScanner.nextLine();

      • In Java, confirmation of the use of an object method is given by the parameters objectName.methodName(parameters) . The userInputScanner.nextLine() line of code calls the Scanner object using the name given to it, and then we call the nextLine() method, which cannot be given parameters.
      • Note that we are storing the next line in another object, a String. It is denoted in the userInputName code
    6. Print a greeting for the user. After we have stored their name, we can print a greeting for this user. Remember the line System.out.println("Hello World."); which we used in the main class file? All code we write should be located above this line. Now we can change this line to display the following text:

      System.out.println("Hello " + userInputName + "!");

      • You must enter "hello", a username, and an exclamation mark with the code line "Hello " + userInputName + "!" . This is called string concatenation.
      • We have three strings: hello, ", userInputName, and "!". Strings in Java are immutable and cannot be edited. So by concatenating them, we have created a new string that contains the greeting.
      • We then use this new line as a parameter to System.out.println .

Having established 7 nominations, we will subjectively determine the best of the best:

Best Free IDE: NetBeans

NetBeans is a powerful open source development environment focused on web, mobile and desktop applications. Works with Linux, Windows, MacOS and even Oracle Solaris.

Although NetBeans is multilingual, it is considered Java-centric in the development environment. It works great with JPA, JSP, Struts, Spring, and the Hibernate library.

Best Commercial IDE: IntelliJ IDEA

In truth, IntelliJ IDEA is distributed in two versions, one of which is completely free - Free Community Edition. Moreover, for a novice developer, this package is enough with his head. In particular, the Android Studio IDE, which will be discussed a little later, is based on this version.

In the paid version, you get support for the Spring frameworks (Spring MVC framework, Spring Security, Spring Boot, Spring Integration, etc.), Node.js, Angular React, Grails, the ability to use additional languages ​​(javascript, typescript, coffeescript) and interact with almost seven popular servers (Tomcat, TomEE, GlassFish, JBoss, WildFly, Weblogic, WebSphere, Geronimo, Virgo, etc.).

Most popular IDE: Eclipse

It is almost impossible to give an exact figure, but almost any Java developer with more than 2 years of experience has come across this IDE. Eclipse managed to become the winner in this category thanks to a large community, a ton of useful information and countless plugins. As with previous instances, Eclipse supports several languages, but is perceived as a Java adherent.

The most versatile IDE: JDeveloper

Another product from Oracle with a lot of benefits, including version control support and Oracle cloud service, it is packed with SQL Developer, PL / SQL query processor, WebLogic Server, editors for HTML, CSS, JavaScript, JSF, JSP, WSDL and a lot more all sorts of benefits.

Best for Android: Android Studio

It would be strange if some other IDE became the winner in this nomination. In addition to all the features that the original IntelliJ IDEA IDE gives you, Android Studio includes many add-ons from Google, both purely visual (layouts, formats, GPU profiler) and functional (JUnit 4 and Firebase Test Lab for testing and debugging, system Gradle builds, Instant Run).

Best Learning IDE: DrJava

This is exactly the conclusion of a development team called JavaPLT, representing Rice University. It is not surprising, given that DrJava is their brainchild. However, jokes aside, it is worth recognizing that DrJava is really perfect for beginners, because this IDE does not even aim to compete with the above. Its main advantage is extremely fast setup and transition to direct coding. As competitors, you can consider BlueJ, JGrasp and Greenfoot on similar terms.

Most Promising IDE: MyEclipse

The welcome inscription on the download page says “The best Java EE IDE enhanced for the full stack developer”. Well, this is very immodest, not at all supported by facts, but in truth - not far from the truth. In essence, MyEclipse is Eclipse, where everything is initially "screwed", "finished" and a little more extended. The developer is offered several versions, two main ones - standard and professional. Standard is just Eclipse in a new shell, and Professional contains a mobile web simulator, an image editor, a UML editor, templates, add-ons - in general, everything that will make creating a product much easier.

And what do you use?

As you know, Java is one of the most popular programming languages ​​in the world and knowing it will greatly increase your value as a programmer. So, you have decided to start writing in this language. You will need to install the JDK in order to write and run Java programs. JDK is a set of software developed by Oracle that contains a compiler (javac), a runtime environment (Java Runtime Environment), a standard language library, examples and documentation. After reading this article, you will learn how to install and configure the JDK on your system, what is a development environment, and what IDE options are there for Java. You will also write your first Java program.

Installing the Java Development Kit

  1. Go to the Oracle website and download the JDK for your platform.
  2. After downloading, extract the resulting archive and run the extracted application.
  3. During the installation process, select the "Development Tool" option and click "Next".
  4. After a while, the installation will complete.

So you've installed the Java Development Kit, but that's not all. You need to configure it for your system.

Setting up the JDK using Windows as an example

  1. 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.
  2. 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 previously copied path into its value.
  3. Now the most important thing. Open a command prompt and type javac to make sure 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 does not hurt to install one of the IDEs on your computer.

Installing the IDE

To begin with, let's figure out what is IDE.

IDE(Integrated Development Environment) is a set of software tools used by programmers to develop software. An IDE makes it easy to write, run, debug, and test code.

To write complex programs, it is advisable to use an IDE. We will consider the most popular.

Notebook

Yes, you can write code in notepad! For development, you just need to install the JDK and specify the path to it. Write the code in notepad, compile using the command line. However, for developing complex programs, this is not the best option due to the lack of any additional features that are present in advanced IDEs.

NetBeans

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 readable code. NetBeans supports not only Java, but also other programming languages ​​for desktop and web development. It is completely free, you can download it from the official website. Here are just a few of its features:

  • code formatting;
  • installation of third-party libraries;
  • simple graphical interface;
  • and many many others…

Eclipse

Eclipse, like Netbeans, is one of the more popular IDEs. It provides an impressive, intuitive interface and a productive development environment that allows you to comfortably develop applications in Java. You can download Eclipse for free from the official website. Advantages:

  • the ability to format the code the way you want;
  • support for splitting code into modules;
  • ease of use of the same code in different projects;
  • drag and drop (drag-and-drop);
  • viewing the contents of libraries;
  • user-friendly interface.

IntelliJ IDEA

IntelliJ IDEA is a well-known IDE for Java written, oddly enough, in Java. Equipped with unique tools and allows you to easily navigate the program. Finding bugs and debugging code has never been easier than with IntelliJ IDEA.

JCreator

JCreator is an advanced and fastest Java IDE written in C++.

Writing our first program

So, you have installed and configured JDK, JRE and IDE for Java. What's the next step? Of course, write a program to finally make sure that everything works and you are ready to learn the language. You will learn the basic structure of Java code and create your first program! It is worth noting that before learning Java, you should familiarize yourself with at least the simplest principles of object-oriented programming.

The structure of a Java program can be represented as follows:

Java program structure

The source code file contains several classes - these are parts of the program that have certain functions. It is good practice to split a program into several source code files, each with its own purpose. Classes contain methods - actions that objects of this class can perform. The method contains commands with which you can get the desired result.

Before you start creating a program, you need to create a project, and in it a file that will contain your code. Consider creating a project on the Eclipse IDE, but the process is not much different in other IDEs. Select “File” at the top, then hover over “New”, select “Java Project” from the menu that opens. In the window that appears, enter the name of the project and other settings you need (if you are not sure what to do, you can just leave everything as it is) and click "Next". Done, you have created a project! It remains only to create a class in it in which you will write your first program. Right-click on your project (it should appear on the right) and select New → Class. Give the new class a name (in this example it is first) and click Finish.

Let's start writing your first program. By tradition, this is a program that displays "Hello, world!".

Public class first( public static void main(String args) ( System.out.println("Hello, world!"); ) )

Let's take a look at what we wrote:

  • public is an access modifier that determines from which part of the program our class can be used. In your example, public is all code;
  • class is a keyword indicating that you are declaring a class and nothing else;
  • first is the name of your class. Parentheses define the beginning and end of the class code;
  • public static void main(String args) - declaration of a public static method (that is, which can be called without creating an object of the class). The method in the example returns nothing and takes an array of strings as arguments. The only command in this method prints the message "Hello, world!" to the console. Note that instead of println, you can write print , the only difference is that in the case of println, the line break character will be additionally displayed.

Okay, you've written your first program. Now it needs to be launched. To do this, simply click the white arrow in the green circle on the top panel (when you hover over it, “Run” should be highlighted). After clicking at the bottom, a console will open in which you will see the message “Hello, world”! Congratulations, you have written your first Java program and are ready to dive into the fascinating world of this language!

Java is a technology for the full functioning of applications and software components. Modern developers rarely do without Java when creating games. It is for this reason that users are encouraged to install and receive regular updates to the Java Runtime Environment (JRE).

The Java programming language allows you to write software for working in browsers, develop various server applications for online forums, online stores, online surveys.

With Java, you can process HTML forms and create services and services that are optimally tailored to the user by combining different modules.

In addition, if Java is not installed on your computer (for example, you didn’t have time to download it for free), then a number of applications, games and websites simply won’t start on your PC, since it is this software that ensures their speed and reliability.

Java features:

  • automatic memory management
  • creating multithreaded applications
  • database access, generics support
  • verbose exception handling
  • simultaneous execution of several programs
  • wide range of I/O filtering tools
  • classes for making HTTP requests and processing responses
  • simple tools for building network applications
  • standard collections: array, list, stack, etc.

Software components written in Java are translated into bytecode, which, in turn, is executed by the so-called Java virtual machine - a program that acts as an interpreter. The advantage of this algorithm is independence from the operating system and hardware. Therefore, the same java application can work equally well on different devices.

And although it is widely believed among programmers that software in Java is slower and takes up more memory than, say, created using the C language, when it comes to web development, a number of advantages put the software we are considering in the leader's place. This language is used not only on billions of PCs, but also on smartphones, various communicators and even on TVs. Java is especially popular among online game developers. And the gamers themselves will not be able to access all the settings, for example, if you do not download Java for Minecraft.

It is important that you always have the latest version of Java installed - you can download it for free for Windows 7, 8, 10, Vista, XP from this page or on the official website. Thus, you will take care of the efficient and safe operation of Java applications.

You also have the opportunity to download Java for 64-bit browsers with the Windows 64 bit operating system.

You can download the installation package on the Oracle website at the link:

Install Java.

In order to install Java on your computer, run the downloaded file, after which the installation process will begin (Figure 1.2).

Click Next.

The default installation will take place in the directory C:\Program Files\Java\jdk1.x.x_xx (instead of x's version number), if desired, the directory can be changed by clicking on the Change button (Figure 1.3).

Follow the instructions of the installation wizard and in a few minutes the installation will be completed.

At the end of the installation, the program will prompt you to go to technical documentation and manuals for Java, for which you will need to click the Next Steps button. This will open the Java documentation page http://docs.oracle.com/javase/ in your browser, which is very helpful to learn.

Setting environment variables.

In the next step, you need to set the paths to the executable files, namely, set the PATH, CLASSPATH and JAVA_HOME system variables.

To do this, open Control Panel -> System, you are taking Additional system settings. In the window that appears, click the button Environment Variables.

In the window that opens, in the block System variables check if the variable exists PATH, if the variable does not exist, then it must be created by clicking on the button Create, if the PATH variable already exists, then you need it Change(Fig. 1.4).

In the next window, the PATH variable should be set to Variable value is the path to the directory where Java was installed (Fig. 1.5).

If the PATH variable has already been assigned other values, then the new value is added separated by a semicolon ";" at the very end of the line.

You also need to create a variable CLASSPATH if it hasn't already been created. As its value, you must specify ".;" (Fig. 1.6).

This is how a variable is created/changed JAVA_HOME. The value of this variable is the path to the directory where Java was installed (as for PAHT), but without the bin subdirectory. For example:

Value in PATH: C:\Program Files\Java\jdk1.7.0_25\bin

Value in JAVA_HOME: C:\Program Files\Java\jdk1.7.0_25

After the variables have been set, Java installation is now complete!

Checking the installation.

To check if the installation was successful, open a command prompt. To do this, in the Windows Start menu in the search bar, type cmd and press Enter. After that, a command window will open in which you need to enter the following command.

After that, if information about the installed version of java is displayed, then the installation was successful.

Frequent problems:

  • "java" is not an internal or external command, operable program, or batch file.

Check if the path in PATH is correct. Try to avoid spaces in the name of the folder where you install the JDK. If you think that the path is written correctly, then you should make sure that the javac.exe file is present in the directory that is registered in the PATH line, and that it was the JDK, and not the JDE, that was installed,

  • is not a win 32 app

Occurs as a result of installing a version of Java that does not match the bitness of the system (for example, when installing a 64-bit version of Java on a 32-bit operating system).

  • Error calling to check JAVA_HOME

Check that this variable stores the path to the installed JAVA (without bin)