The java programs work on millions of devices: laptops, tablets, phones, under Windows, Linux, Solaris or iOS.
A java platform contains the virtual machine (JVM), a compiler and a set of libraries for application development. Java is available in 2 versions:
- Java Runtime Environment (JRE) - which contains the virtual machine in which the programs run.
- JDK (Java Development Kit), which besides the virtual machine also contains the compiler and other tools for creating and executing programs and applications.
Schematically, the two java distributions are represented below:
After downloading the JDK installation file, we will start installing it:
Press the Next button to continue the installation:
Follow the instructions and end by clicking the Close button.
Dupa instalare, directorul jdk va avea urmatoarea structura:
The bin directory contains the compiler (javac.exe) and the execution program (java.exe).
If we want to compile or run programs or applications from any directory, without writing the entire directory path in the command, we need to set the PATH environment variable.
If we do not set the PATH variable, we'll need to specify for each command the complete path to our file, for example:
C:\Program Files\Java\jdk10.0.2\bin\javac Hello.java
Open Computer Properties (right click on the computer icon). The window opens:
Click Advanced system settings:
Then click on Environment Variables:
Go to the User variables section and click New. A small window opens. In this window, enter "Java_Home" for the variable name and the address of the JDK directory (path to it) for the value of the variable (for example: "C:\Program Files\Java\jdk-10.2.0\bin").
Then OK in all open windows.
To check if everything is OK, open the command prompt, type "java" and enter Enter. There will be something like this in the command prompt:
We write the program in the Notepad editor and save the file as "Hello.java".
To compile the program, we use the javac command. We open Command Prompt and type:
Following compilation, the compiled "Hello.class" file is generated. Now we will run this file using the "java" command as follows:
It is noticed that following the execution of the program, the text was displayed: "Hello!".
If we do not want to set the PATH variable, we can install Textpad or Eclipse, which are free applications.
After installing the Textpad editor, we write the Hello.java program:
To compile the program, select: Tools -> External Tools -> Compile Java:
Will result the compiled file: "Hello.class". To run the program, select: Tools -> External Tools -> Run Java Application:
The program runs and the result is shown in the following figure:
A more advanced professional program for programming in several languages, including Java, is Eclipse.
A Java package organizes Java classes into namespaces. A package can contain the following kinds of types: classes, interfaces, enumerations and annotation types.
Core package in Java:
java.lang - basic language functionality and fundamental types
java.util - collection data structure classes
java.io - file operations
java.math - multiprecision arithmetics
java.nio - the Non-blocking I/O framework for Java
java.net - networking operations, sockets, DNS lookups
java.security - key generation, encryption and decryption
java.sql - Java Database Connectivity (JDBC) to access databases
java.awt - basic hierarchy of packages for native GUI components
java.text - provides classes and interfaces for handling text, dates, numbers, and messages in a manner independent of natural languages
java.rmi - provides the RMI package
java.time - the main API for dates, times, instants, and durations
java.beans - the java.beans package contains classes and interfaces related to JavaBeans components
To use a package's classes inside a Java source file, it is convenient to import the classes from the package with an import declaration:
Visit my websites:https://www.jwebsaints.com