返回介绍

Java language

发布于 2025-02-22 22:20:05 字数 7204 浏览 0 评论 0 收藏 0

In this part of the Java tutorial, we will introduce the Java programming language.

Goal

The goal of this tutorial is to get you started with the Java programming language. The tutorial covers the core of the Java language. This tutorial uses command line compilers to build applications.

Java

Java is a high-level, general-purpose, object-oriented programming language. The main design goals of the language were robustness, portability, high performance and security. Java is a multithreaded and distributed programming language. It can be used to create console applications, GUI applications, web applications, both on PCs or embedded systems.

Java is a programming language created by Sun Microsystems in 1991. The first publicly available version of Java was released in 1995. Today, the language is developed by Oracle corporation.

Java excels in creating portable mobile applications, programming various appliances and in creating enterprise applications.

Popularity

There are currently several widely used programming languages. Java belongs to the most popular languages today. Several surveys put it into the top three languages in the world.

Java platforms

Java has four programming platforms:

  • Java Platform, Standard Edition (Java SE)
  • Java Platform, Enterprise Edition (Java EE)
  • Java Platform, Micro Edition (Java ME)
  • JavaFX

All Java platforms consist of a Java Virtual Machine (JVM) and an application programming interface (API). The Java Virtual Machine is a program, for a particular hardware and software platform that runs Java applications. An API is a collection of software components that we can use to create other software components or applications.

Java SE is used for developing desktop applications. Java SE's API provides the core functionality of the Java programming language. It consists of a virtual machine, development tools, deployment technologies, and other class libraries and toolkits used in Java applications. Java EE is built on top of the Java SE platform. The Java EE platform provides an API and runtime environment for developing and running web applications and large-scale, multi-tiered, scalable, reliable, and secure enterprise applications. Java ME is a subset of the Java SE. It provides an API and a small-footprint virtual machine for running Java applications on small devices, like mobile phones. JavaFX is a platform for creating rich Internet applications using a lightweight user-interface API.

In our tutorial, we use the Java SE platform to create simple console applications.

JDK

Strictly speaking, Java SE is a platform specification. Java Platform, Standard Edition Development Kit (JDK) is an official implementation of the Java SE by Oracle. There are also other implementations. For example free and open source OpenJDK or IBM's J9.

$ ls jdk1.7.0_02/
bin    db     jre  LICENSE  README.html  src.zip
COPYRIGHT  include  lib  man    release    THIRDPARTYLICENSEREADME.txt

After we download and unpack the Oracles's JDK, we can see the contents of the JDK in the our jdk1.7.0_02 directory. The development tools are located in the bin subdirectory. The Java javac compiler and the java application launcher are located in this subdirectory. The jre subdirectory contains the JVM, class libraries and other files that help execute Java programs. The lib subdirectory has some additional class libraries and support files. The db subdirectory contains the Java DB, which is the Oracle's distribution of the Apache Derby database. In the include subdirectory we can find header files that support native-code programming. The src.zip file contains source files for all classes that make up the Java core API.

JVM

Java virtual machine (JVM) is a program that can execute Java bytecode. The JVM is included in the JDK. Java source code is written in files with the .java extension. The javac Java compiler will compile the Java source code into the Java bytecode; the compiled files have the .class extension. This bytecode is executed by JVM. The java tool is a launcher for Java applications. Oracle's JVM is called HotSpot. HotSpot is a Java virtual machine for desktops and servers. It has advanced techniques such as just-in-time compilation and adaptive optimization designed to improve performance.

Compiling a simple program

In order to develop Java applications, we need to download a JDK. Oracle's official JDK can be downloaded from this dowload page .

$ mkdir -p com/zetcode

Inside the current working directory, we create a com/zetcode subdirectory. Java source files are organized in modules called packages. The packages must match the directory structure.

$ touch com/zetcode/SimpleExample.java

A SimpleExample.java source file is created in the com/zetcode subdirectory. Java source files have a .java extension.

package com.zetcode;

public class SimpleExample {

  public static void main(String[] args) {

    System.out.println("This is simple Java example.");
  }
}

This is a source code for a simple Java example. This example prints a message to the console.

package com.zetcode; 

The package name must correspond to the directory structure in which the source file is located.

public class SimpleExample { 

The public class name is required to match the file name.

$ javac com/zetcode/SimpleExample.java 

Using the javac compiler, we compile the source code.

$ ls com/zetcode/
SimpleExample.class  SimpleExample.java

The compiler generetes a Java bytecode, which is executed by the Java Virtual Machine. The bytecode has a .class extension.

$ java com.zetcode.SimpleExample 
This is simple Java example.

With the java application launcher, we execute the program. It starts a Java runtime environment, loading a specified class, and invoking that class's main method. The .class extension is excluded; it is assumed. The program name is a fully qualified name of the program — com.zetcode.SimpleExample . It includes the name of the program and its package.

Sources

The following sources were used to create this tutorial:

In this part of the Java tutorial, we have introduced the Java language.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文