Schweitzer Fachinformationen
Wenn es um professionelles Wissen geht, ist Schweitzer Fachinformationen wegweisend. Kunden aus Recht und Beratung sowie Unternehmen, öffentliche Verwaltungen und Bibliotheken erhalten komplette Lösungen zum Beschaffen, Verwalten und Nutzen von digitalen und gedruckten Medien.
Welcome to the world of learning Java. In this first lesson, we will set up everything needed to write Java programs. We will then write our first program together called "Hello, World!"
It is important to know that, by itself, Java code doesn't do anything. It is just text. To make it useful, we need to install the Java Development Kit (JDK). The JDK contains the compiler and other tools needed to create executable Java programs. After the JDK is installed, we will check the configuration by creating, compiling, and running the obligatory "Hello, World!" program.
By the end of this lesson, you will be able to:
Before we get into downloading and installing the Java tools and writing our first program, let's first take a look at the bigger picture: the Java universe, if you will. A little history will help to make sense of where Java is today.
The development of the Java language was led by James Gosling at Sun Microsystems. The initial development started in the early 1990s, and the language was originally called Oak. The first official release of Java was in 1996. Now, in Internet time, 1996 seems like, I don't know, a million years ago. And it seems that Java has this reputation for being an old and creaky language because there are all these newer and cooler languages out there-you know, like Ruby and Python and JavaScript.
But wait-the first version of Ruby was also released in 1995 and the first version of Python was started in 1989, so they aren't really newer languages. JavaScript was called LiveScript when it came on to the scene in 1995. Maybe Java isn't an old language after all.
Java was originally a closed source project, meaning that developers had to purchase a license to use it, and the code that runs Java was accessible only to Sun Microsystems developers. In 2006, however, Sun decided to make the project open source under a newly defined General Public License (GPL). In short, Sun decided to let any developer use Java to write software programs for any purpose at no cost. In addition, the GPL allows developers to access the code that runs Java to tweak it for their own purposes.
In 2010, Oracle bought Sun Microsystems and took over stewardship of Java. Oracle continues to maintain, distribute, and support Java and its related tools, including the JDK and the JVM.
The Java Development Kit is a software package that contains tools that allow developers, like you, to write new Java programs. These tools include things like the Java compiler, which converts the code you write into bytecode that the Java Virtual Machine can read, as well as the JVM itself and tools that allow you to package your creations to distribute to other users.
We will be downloading and installing the JDK later in this lesson.
There are two basic versions of the JDK, both maintained and distributed by Oracle: OpenJDK and Oracle JDK. OpenJDK is the open source reference implementation of the JDK. This means that it is the standard from which all other JDK implementations are derived. OpenJDK is released under the GPL v2 license and is completely open to the community. It contains the core code that makes Java work.
The Oracle JDK is based on OpenJDK, but it is a commercial implementation released under the Oracle Binary Code License Agreement.
The two versions have nearly identical code, but the Oracle JDK has a few more classes (some closed source) and some additional bug fixes. Businesses generally use the Oracle JDK because it tends to be a bit more stable; however, most Oracle JDK versions are distributed under a relatively restricted license. You can download the software for free, but you are only allowed to use the free version for personal, noncommercial projects. The free Oracle JDK license excludes the ability to create software that you want to sell or distribute for others to use. Many businesses choose to pay for commercial-use licenses because Oracle Java JDK includes support features not included in the open source versions.
We include instructions in the following sections to install OpenJDK for use in this course. You are welcome to use Oracle JDK instead, if you prefer. We use the open source OpenJDK here because it is completely free for any purpose you want to use it for, including creating and selling your own software packages. While Oracle does allow developers to use its Java JDK at no cost for personal projects, the free license does not allow commercial use. Many businesses choose to purchase licenses for Oracle's Java JDK to take advantage of the additional support that Oracle provides with the commercial version. However, because the JDK is very much behind the scenes when developing software using Java, you are not likely to notice much difference between the two.
One of the problems with writing software today is that we normally want our programs to be compatible with as many different types of computers as possible. What good is a killer app if it will run on only one brand of smartphone? What about a custom enterprise application that will run only on a Windows machine, even though many employees may use Apple computers? This is where Java has an advantage over other coding languages.
The Java Virtual Machine (JVM) is a software layer between the Java code and the machine running the software. A virtual machine (VM) is essentially a piece of software that acts like a computer, and it performs many of the same input/process/output operations that a physical computer does.
Essentially, the JVM (which is included in the JDK) acts as a translator between the compiled Java code and the machine's bytecode. This means that our program will run on any computer that the JVM recognizes, so we can write one app that will work on many different devices, rather than writing multiple versions of the same app for different platforms. The result is that we can write once and run anywhere, a process Sun Microsystems named WORA to promote the use of Java.
As a Java developer, you may also hear about the Java Runtime Environment (JRE). Through Java version 8, anyone who wanted to run a Java application on their computer had to first install a compatible JRE, which included the JVM required to run compiled software but did not include the tools used to develop software.
Starting with Java 9, however, the JDK includes a packaging process that creates an executable package that does not require a separate JRE on the end user's computer. This streamlines the distribution process a bit, making it even easier to write once and run anywhere when we use Java.
Java 8 is still widely used in many enterprises, however, so it's not impossible that you will run across the need to have a JRE installed to run software written in Java.
You will need to install the JDK for this book because it has the tools needed to develop Java applications. As mentioned, the JDK also contains the Java runtime, which is the component that allows us to run the Java programs that we (and others) write. You might have a Java runtime already installed on your system because Java is widely used to write software.
When we install the JDK, it will simply replace any existing JDK.
For this course, we will use OpenJDK, which you can also use for any project in the future. The following instruction sets can be used to check your current installed version of a JDK and to install OpenJDK if you do not already have it. The following sections cover
We recommend installing the most recent long-term support (LTS) version of OpenJDK, which was version 11 at the time of this writing. While you will see newer versions (such as 14), you should choose an LTS version because it will be more stable than newer versions that are still in development. Each version is based on a previous version, however, so you don't want to choose a version that comes before 11-there may be newer features we use in this course that are not available in older versions.
Additionally, while we provide added guidance here for installing a JDK on Microsoft Windows and macOS, you can also install it on other operating systems including various versions of Linux and AIX. The installation would be similar to what is shown here, including starting at the same website.
At the end of the day, the JDK is being used to compile and run our Java programs.
The following instructions walk you through checking for an existing copy of the JDK on Microsoft Windows 10. You'll then install and verify an installation of OpenJDK. If you are using macOS, skip ahead to the next section.
Dateiformat: ePUBKopierschutz: Adobe-DRM (Digital Rights Management)
Systemvoraussetzungen:
Das Dateiformat ePUB ist sehr gut für Romane und Sachbücher geeignet – also für „fließenden” Text ohne komplexes Layout. Bei E-Readern oder Smartphones passt sich der Zeilen- und Seitenumbruch automatisch den kleinen Displays an. Mit Adobe-DRM wird hier ein „harter” Kopierschutz verwendet. Wenn die notwendigen Voraussetzungen nicht vorliegen, können Sie das E-Book leider nicht öffnen. Daher müssen Sie bereits vor dem Download Ihre Lese-Hardware vorbereiten.Bitte beachten Sie: Wir empfehlen Ihnen unbedingt nach Installation der Lese-Software diese mit Ihrer persönlichen Adobe-ID zu autorisieren!
Weitere Informationen finden Sie in unserer E-Book Hilfe.