📜 ⬆️ ⬇️

We learn Java. First cup

What yes how


I decided to support the MaxElc and DarwinTenk initiative, and start slowly talking about Java. The text will be served "cups" because one of the symbols of Java is a cup of coffee. I will write most of it myself, occasionally glancing at Wikipedia and the official language site java.sun.com (section / docs).
Further in the text it is worth separating the concepts “Java as a language” and “Java as a platform”.

Short story


As a language, Java was planned to be compiled into bytecode, which would then be launched in the interpreter, but later the interpreter was replaced by Just-In-Time compiler.
The syntax of the language was actually taken from C ++ and is somewhat simplified. Over time, there appeared some specific elements, which will be discussed later.
Versions of the language of everything are exactly 6 - 1, 1.1, 1.2, 1.3, 1.4, 1.5 (it is 5.0) and 1.6 (6.0). Seventh is expected to 2010 like. Relevant to this day are 5 and 6 versions.
Unfortunately, I cannot tell the full history of the language, therefore, behind the names and founders of the founders and developers, I ask you to go to Wikipedia .

Architecture


As a platform, Java is a typical set of libraries and exists in 3 guises designed for different purposes: J2ME, J2SE, J2EE. This, respectively, mobile, standard and enterprise.
In addition to the basic language, they include:


So, we have available a set of libraries and a compiler that creates bytecode. We run the resulting joy in the ... Java-machine!
The java machine is a standard Java runtime environment (JRE). The main implementation is the Hot Spot from Sun, but apart from it, HP, Oracle, IBM, Novell have their own implementations; In addition, there are dozens of lesser known implementations. In addition, if you get your old Nokia or Siemens M45, then look them in the face - the car is looking at you. Java machine Wired into the phone, yes; It is she who will launch Java games when you ask. Of course, the weight of the Java machine sewn into the phone is a couple of orders of magnitude less than the weight of it on the server — obviously, their capabilities are not comparable.
In theory, different Java machines should execute the same code in the same way. The tests that Java machines must pass before they are published are responsible for this.
')

Let's taste it?


Let's write a small Java application. We take a blondie and ...
class HelloWorld {
public static void main( String [] args){
System. out .println( "Hello world!" );
}
}

* This source code was highlighted with Source Code Highlighter .

So what have we done here. First we declared a class, HelloWorld. The sly java feature - the file where the class code lies should be called the class name and have the extension .java. A class compiled into a bytecode will have the extension .class. This will help you easily find your classes. You will learn more about how classes work and what a package (set of classes) is in the next cup :)
Further, we declared the static method main - this is the entry point to the program, the presence of this method means that the class can be used to start the program.
As parameters we are given an array of strings - we don’t need to use them yet, ignore them.
Finally, the System class (it is visible everywhere; why, I will tell you later) we got the static out object, which is the output stream and wrote the string “Hello World” to it. Everything.

To try to run all this on your own, you need to install a Java machine. For example, the standard from Sun. I warn you - it weighs a lot. In addition, from there you need to download the JDK, developer kit. It contains the tools you need, including the compiler. Also. You can download the development environment - for example, NetBeans, Eclipse, IntelliJ IDEA. However, I would not advise doing this - often for learning a language from scratch, an optimal tool is a backlit notebook, for example, Notepad ++ .

It looks like this to me:
~$ vim HelloWorld.java
~$ javac HelloWorld.java
~$ java HelloWorld
Hello world!
~$


The text is written in pens in gedit.

Source: https://habr.com/ru/post/49411/


All Articles