Getting Started with Java - An Overview of the Java Language

1. Basic overview of Java language

1.1 What is a computer programming language

    How do people communicate with each other? Our parents taught us to speak since we were young. Through long-term edification and self-study, we have learned Mandarin and learned to express our needs. Parents will try their best to satisfy us when they receive our signals or hear our requests.

    Similarly, a computer programming language is a language for communication between us and a computer. It is a computer language that follows certain rules and grammar, and we can control the computer through this language .

    When introducing the basic knowledge of computers, we introduced the hierarchical concept of computer systems, and programming languages ​​will eventually be converted into machine languages ​​that computers can directly interpret.

    Up to now, there are hundreds of programming languages, and they have mainly gone through three stages: machine language, assembly language, and high-level language.

    The first generation language (1946-1953) - machine language : it is an instruction built into the computer circuit, consisting of 0 and 1, which is the data that can be directly interpreted by the CPU. Since the machine language is directly operated on the computer hardware, it is very efficient. These machine languages ​​are generally only understood by professionals;

    The second-generation language (1954-1964)-assembly language : In order to solve the complex and difficult-to-read machine language, there is assembly language, which is a low-level language close to machine language . Assembly instructions are easy-to-remember writing formats for machine instructions. Mnemonics are used to replace the opcodes of machine instructions, and address symbols (Symbol) or labels (Label) are used to replace the addresses of instructions or operands. This greatly improves the memory and recognition of the language. However, assembly language still has a strong machine thinking, and programmers still have to remember many assembly instructions.

    With the development of computers, people's demand for the portability of computer programs is also increasing. Therefore, there is an urgent need for a computer language that does not depend on a specific model. It is hoped that programs written in this language can run on various platforms, so the third-generation language was born, also called high-level language. The development of high-level language is divided into two stages. The former stage belongs to structured language or process-oriented language, and the latter stage belongs to object-oriented language .

    The third-generation language (before the 1980s)-process-oriented high-level language : process-oriented is a process-centered programming idea, which is to analyze the steps required to solve the problem, and then execute the algorithm according to the steps. The essence of procedural language programs is to calculate repeatedly and step by step, and it starts from the perspective of computer execution. Procedural-oriented languages ​​are not suitable for designing complex algorithms.

    Process-oriented high-level languages ​​include: FORTRAN (1956), ALGOL (1958), GOBOL (1959), PASCAL (1968), C (1972) and so on.

1) FORTRAN (1956)

    The full name of FORTRAN is FORmula TRANslation (Formula Transformation), which was proposed in 1954 and officially used in 1956. It was developed by IBM for its 704 computer.

2) ALGOL (1958)

    The full name of ALGOL is ALGOrithmic Language (algorithmic language). It is a process-oriented programming language with nested structure. It introduces the concepts of local variables and recursion for the first time.

3) GOBOL (1959)

    The full name of GOBOL is Common Business-Oriented Language (Common Business-Oriented Language), which is mainly used in the field of business management (data processing).

4) PASCAL (1968)

    PASCAL came to commemorate Blaise Pascal, a famous French philosopher and mathematician in the 17th century. It was designed and founded by Professor Niklaus Wirth of Switzerland in the late 1960s. Pascal is the earliest structured programming language with rich data types and concise and flexible operation statements.

5) C (1972)

    The C language is the most classic process-oriented language developed by Dennis M.Ritchie of AT&T Bell Laboratories to overcome the limitations of the B language (Ken Thompson of Bell Laboratories in the United States, based on the BCPL language and designing a language that is very simple and close to hardware) relying on machines and no data types.

    The third-generation language (after the 1980s)-object-oriented high-level language : Object-Oriented Programming (OOP) is a programming language model built around objects, rather than using actions or functions to represent data and logic. Object-oriented thinking starts from the human point of view, that is, everything is an object.

    There are two most important and basic concepts in object-oriented programming, that is: class and object. Objects are composed of attributes and behaviors, and a variety of similar attributes and behaviors can be classified. All objects can be described by classes, but the reverse is not true. Not all classes are used to describe objects. If there is not enough information in a class to describe a specific object, then such a class is abstract .

    Object-oriented high-level languages ​​include: Smalltalk (1972), C++ (1983), Python (1991), Java (1995), C# (2001), Go (2009), etc.

1) Smalltalk (1972)

    Smalltalk is recognized as the second object-oriented programming language in history, and the first true integrated development environment (IDE) language. Object-oriented The two concepts of class and object first appeared in the Simula programming language.

2) C++ (1983)

    In 1997, Benjani Stroustrupp was at Bell Labs, mainly improving C. Until 1983, it was officially named C++, but it was not until 1998 that the International Standards Organization (ISO) issued the first version of the C++ standard.

3) Python (1991)

    In 1989, in order to pass the Christmas holiday, Guido began to write a compiler/interpreter for the Python language. In 1991, the first Python compiler (also an interpreter) was born. It is implemented in C language and can call C library (.so file).

4) Java (1995)

    Java is a programming language developed by James Gosling of SUN and his team in 1991. It was originally named Oak (an oak tree), until 1995, SUN officially changed its name to Java.

5) C# (2001)

    The full name of C# is C sharp. In 1998, the Delphi language designer Hejlsberg led the Microsoft development team, built on the .Net Framework environment, and followed and developed a language developed by the basic idea of ​​C++. It was officially released in 2001.

6) Go (2009)

    Go, also known as Golang, was designed and developed by Rob Pike, Google's chief software engineer, in collaboration with Robert Griesemer (Java HotSpot compiler and V8 engine participant of Google browser JavaScript) and Ken Thompson (B language and C language designer), and a language that was open sourced in November 2009.

1.1.1. Definition of Java programming language

Official English definition:

The Java™ Programming Language is a general-purpose, concurrent, strongly typed, class-based object-oriented language. It is normally compiled to the bytecode instruction set and binary format defined in the Java Virtual Machine Specification.

   The Java™ programming language is a general-purpose, concurrent, strongly-typed, class-based, object-oriented language. It is usually compiled to a bytecode instruction set and binary format as defined in the Java Virtual Machine Specification.

1.2, Java language development history

years event
year 1991 In order to be able to develop applications on consumer electronics (PDAs, set-top boxes, mobile phones, etc.), the research team of SUN Corporation in the United States was able to develop applications on consumer electronics products (PDAs, set-top boxes, mobile phones, etc.), but the most popular programming languages ​​at that time were C and C++. Because C++ was too large and complex, it was a bit difficult to apply it to consumer electronics products. Finally, the team led by Sun (James Gosling) developed a platform-independent new language called Oak based on C++. Oak was named after an oak tree outside Gosling's office James Gosling.
the year 1995 In January 1995, Oak was renamed Java, because Oak is a registered trademark of a graphics card manufacturer, and Java is the English name of the island of "Java (Note: Java's transliteration)" in Indonesia, which is famous for its rich coffee. That's why Java's official trademark is a strong cup of coffee.
1996 The JDK1.0 version was released in early 1996. This version includes two parts: the operating environment (ie Java Runtime Environment, JRE) and the development environment (ie Java Development Kit, IDK). The operating environment includes five parts: core API (Java core class library), integration API, user interface API, publishing technology, and Java virtual machine (Java Virtual Machine, JVM); the development environment includes a compiler for compiling Java programs (Javac command)
1998 On December 4, 1998, jdk ushered in a milestone version 1.2. Along with JDK1.2, JSP/SERVLET, EJB and other specifications were released, and Java was divided into three versions: J2EE, J2SE and J2ME. Java SE: (Java Platform, Standard Edition) provides the most basic environment for creating and running Java programs. It is the core and foundation of Java technology. You can focus on learning: collection classes, file operations, I/O streams, threads, serialization, and GUI form programming. Java EE: (Java Platform, Enterprise Edition) provides a development and operating environment for server-based distributed enterprise applications. You can focus on learning frameworks such as jsp, servlet, jdbc, ejb, and ssh. J2ME (Java Platform, Java2 Micro Edition): Provides a development and runtime environment for embedded applications. Such as mobile phone programs and PDA programs.
Year 1999 On April 27, 1994, the HotSpot virtual machine was released;
2000-2002 In 2000, JDK1.3 was released; in 2002, JDK1.4 was released, which is a relatively mature version in the history of JDK. This version adds support for regular expressions, new XML parser, exception chain, NIO and log API.
year 2004 On September 30, 2004, jdk1.5 was released. In this version, the ease of use of Java syntax has been greatly improved, so SUN changed JDK1.5 to JDK5.0. This version adds functions such as automatic boxing and unboxing, enumeration, variable parameters (Varargs), generics (Generic), and For-Each loops.
year 2006 On November 3, 2006, jdk6.0 was released; this version uses JAXB2 to realize the mapping between objects and XML, and JDBC is upgraded to JDBC4.0, Compiler API, and general Annotations support. In 2009, Oracle (oracle) acquired SUN.
year 2011 On July 28, 2011, djk7.0 was released; this version introduced new features such as binary integers, switch statements supporting strings, multiple exception captures, and try statements that automatically close resources;
Year 2014 On March 18, 2014, jdk8.0 was released; this version added new interface default methods, introduced new Lambda expressions, functional interfaces, stream operations of collections, and improvements in IO\NIO;
2017 On September 22, 2017, jdk9.0 was released;
2018 On March 20, 2018, jdk10 was released; on September 25 of the same year, jdk11 was released;
2019 On March 19, 2019, jdk12 was released; on September 17 of the same year, jdk13 was released;
2020 On March 17, 2020, jdk14 was released; on September 15 of the same year, jdk15 was released;
2021 On March 16, 2021, jdk12 was released; on September 14 of the same year, jdk17 was released;
2022 On March 22, 2022, jdk18 was released; on September 20 of the same year, jdk19 was released;

1.3. Features of the Java language

    As a comprehensive language, Java is one of the best object-oriented languages, which is one of the best object-oriented languages. It not only absorbs various advantages of C++ language, but also abandons concepts such as pointers that are difficult to understand in C++. Java has the characteristics of simplicity, object-oriented, cross-platform (portability), reliability, security, dynamics, and support for multi-threading;

  • simplicity

    The Java language inherits the advantages of the C++ language, abandons the incomprehensible pointers in C++, and uses interfaces to replace multiple inheritance. Multiple inheritance and pointers will make the program more complicated; at the same time, Java also designs an automatic garbage collection mechanism to make memory management easier; Java also provides a wealth of class libraries, API documents, and third-party tool libraries;

  • object-oriented

    Object-oriented is the foundation of the Java language, with objects as the basic unit, including properties and methods. The state of an object is expressed by attributes, and the behavior of an object is expressed by methods. Java gives full play to its object-oriented features. It advocates that "everything is an object". All objects are described by classes, and properties and methods cannot be described separately outside of classes.

  • Cross-platform (portability)

    Computer high-level programming languages ​​can be divided into compiled languages ​​and interpreted languages ​​according to the way their programs are executed.

    Compiled type: Use a special compiler to translate the query code into machine instructions that the computer can recognize for a specific operating system at one time. Both C and C++ are compiled languages.

    Interpretation type: use a special interpreter to interpret the source program code one by one into platform-specific machine instructions, and interpret an execution statement, similar to simultaneous translation. ASP and PHP are interpreted languages.

    And Java is known as "Write once, run anywhere" (write once, run everywhere), which is also the slogan used by SUN to demonstrate the cross-platform characteristics of the Java programming language .

    In order to improve the efficiency of compiled languages, the just-in-time compilation technology was developed. As early as 1996, the JDK1.0 version had a just-in-time (JIT) compiler. This technology combines the advantages of compiled languages ​​​​and interpreted languages. Java is the representative product of this technology.

    Java is a compiled and interpreted language. First, a general-purpose java compiler is used to compile the java source program into a platform-independent bytecode file (.calss file), and then the JVM (Java Virtual Machine) interprets and executes the bytecode file one by one (interpreted as local machine code) .

  • reliability

    Java is a strongly typed language that checks program errors during compilation and runtime, and provides an exception handling mechanism to make Java more reliable.

  • safety

    The Java program code has to pass the bytecode verification, and the pointer and memory release operations of the C++ language are discarded, and an automatic garbage collection mechanism is provided, which effectively prevents the user from illegally operating on the memory.

Java strictly abides by the object-oriented specification, encapsulates the details of data implementation, and only exposes the interface to users.

  • dynamic

    Java implements cross-platform, which is divided into compilation period and runtime. Java provides a reflection mechanism, so that we can obtain runtime information, dynamically adjust or load the required class information.

  • Support multithreading

    The Java language supports the simultaneous execution of multiple threads, and provides a synchronization mechanism between multiple threads to ensure that different threads can share data correctly, which greatly improves the execution efficiency of the program.

2. Download and install JDK

2.1. Download JDK

1) Enter the official website

    Enter the JDK official website Oracle | Cloud Applications and Cloud Platform , select Products->Java, and then select Download Java in the upper right corner. If you download the latest version, this page is fine.

2) Find and type the version that needs to be downloaded

    Here we need to download JDK8, select Java archive (Java archive)

3) Select version

    Find Java8, here are two: one is Java SE8 (8u211 and later) - Java SE8u211 and later versions, and the other is Java SE8 (8u202 and earlier) - Java SE8u202 and previous versions.

    Here choose Java SE8(8u211 and later) .

    Then click in to see the specific version. After entering, we found that one version provides Java SE Development Kit 8u341 (jdk) and Java SE Runtime Environment 8u341 (jre) for multiple systems. Here we download jdk.

Note: If you are not logged in, you will be redirected to the login page, and you need to register an Oracle account.

2.2. Install JDK

1) The default installation location of JDK is C:\Program Files, of course you can also choose other drive letters for installation.

 

2) Then you will be asked to install a jre

When installing jdk in the first step, the jdk directory actually contains a jre. Here you need to select a jre directory and install two sets of jre. The second jre is for public users, while the jre in jdk is for developers.

2.3, the relationship between jre and jdk

    Regarding the relationship between jre and jdk, we use an official picture to show :

Note: The official JDK8 API document download address is Java Development Kit 8 Documentation

2.3.1, what is JRE

    JRE is the abbreviation of Java Runtime Environment in English, that is, the Java runtime environment, which provides the minimum requirements for executing Java applications. It is mainly composed of java virtual machine (JVM), java platform core classes and several supporting files. 

Official English explanation:

The JRE provides the libraries, Java virtual machine, and other components necessary for you to run applets and applications written in the Java programming language. This runtime environment can be redistributed with applications to make them free-standing.

The JRE provides the libraries, Java Virtual Machine, and other components needed to run applets and applications written in the Java programming language. This runtime environment can be redistributed with the application, making it self-contained.

2.3.1.1, the composition of JRE

1) Deployment-deployment technology

2) User Interface Libraries-User Interface Library

Swing (graphical user interface) java2d (2D graphics and imaging) AWT (Abstract Window Toolkit) Accessibility (Accessible Java applications and assistive technologies)
Drag and Drop Input Method Image I/O Print Service
Sound Java FX (new interface library introduced after JDK 7 high version)

3) Integration Libraries-integration library

IDL (Interface Definition Language) JDBC (Java Database Connectivity) JNDI (Java Naming and Directory Interface) RMI (Remote Method Invocation)
RMI-IIOP (Internet Inter-ORB Protocol Remote Method Invocation) Scripting

4) Other Base Libraries- other basic libraries

Beans (JAVA reusable components) Security (Security API) Serialization Extension Mechanism
JMX (Java Management Extensions) XML JAXP (Java for XML processing) Networking Override Mechanism
JNI (Java Native Interface) Date and Time Input/Output Internationalization

5) lang and util Base Library-lang and util base library

lang and util Math Collections Ref Objects
Regular Expression Logging Management Instrumentation()
Concurrency Utilities Reflection Versioning Preferences API (Preferences API)
JAR (Java Archive) Zip (compressed)

6) Java HotSpot Client and Server VM-Java HosSpot client and server virtual machine

What is a virtual machine VM?

A virtual machine (Virtual Machine) is a virtual computer. It is a piece of software used to execute a series of virtual computer instructions. In general, virtual machines can be divided into system virtual machines and program virtual machines.

System virtual machine: It is a complete simulation (simulation) of physical computer hardware, providing a software platform that can run a complete operating system, for example: VMware is a system virtual machine.

   Program virtual machine: A virtual machine designed to execute computer programs. For example, the Java virtual machine we are going to learn here belongs to the program virtual machine.

    不同的操作系统它们的指令集都有差异,而通过JVM(Java虚拟机)在操作系统上制定一套数据结构和操作指令,JVM负责装载字节码到内存中,并把它翻译为对应平台的机器指令,以实现供硬件和操作系统的独立性。 

    JVM也有多种实现,比如:Oracle的JVM、IBM的JVM等,其中使用最广泛的还是Oracle的HotSpot JVM。

为什么叫HotSpot虚拟机?   

    HotSpot翻译过来是“热点”,正是因为它内部实现了热点代码探测功能,通过执行计数器找出使用频率较高的代码,然后通过JIT(即时编译)将这部分代码直接翻译为机器码,并保存下来,以提高执行效率。

Java平台标准版提供了Java虚拟机(VM)的两种实现:

  • Java HotSpot Client VM

    客户端VM是通常用于客户端应用程序的平台的实现。对客户机VM进行了调整,以减少启动时间和内存占用。在启动应用程序时,可以使用-client命令行选项调用它。 

  • Java HotSpot Server VM

    服务器虚拟机是一种为最大程序执行速度而设计的实现,以牺牲启动时间和内存为代价。在启动应用程序时,可以使用-server命令行选项调用它。 

简单的说:JRE = JVM+Java Library(Java标准类库)

2.3.2、什么是JDK

    JDK,是英文Java Development Kit的缩写,即Java开发工具包,是用于开发Java应用程序和Applet程序的开发环境。 

官方英文解释:

The JDK includes the JRE plus command-line development tools such as compilers and debuggers that are necessary or useful for developing applets and applications.

  JDK包括JRE和命令行开发工具,如编译器和调试器,这些工具对于开发小程序和应用程序是必要的或有用的。

2.3.2.1、JDK的组成

1)Tools & Tool APIs-工具和工具API

名称 描述
java 运行编译后的Java程序
javac 编译器,用于将Java源程序转成字节码
javadoc 文档生成器
jar 打包工具
javap Java反汇编器
jdeps Java类依赖分析器
Scripting 可用于运行与Java平台交互的脚本
Security 设置安全策略
Monitoring 监视JVM性能统计信息
JConsole 用于监视Java虚拟机的JMX兼容图形工具
VisaualVM 可视化界面,用于查看Java应用程序在Java虚拟机(JVM)上运行时的详细信息,以及对这些应用程序进行故障诊断和分析。
JMC JDK任务控制(JMC)是一套用于管理、监视、分析和排除Java应用程序故障的高级工具。JMC能够对代码性能、内存和延迟等方面进行高效和详细的数据分析,而不会引入通常与分析和监视工具相关的性能开销。
JFR JFR的全称为Java Flight Recorder,用来记录Java应用程序在运行时的数据信息和各种发生的事件。
JPDA 平台调试器架构
JVM TI JVM工具接口,提供了一种检查状态和控制在Java虚拟机(JVM)中运行的应用程序执行的方法
IDL 是一种分布式对象技术,可用来在Java语言中定义、实现和访问CORBA对象。
RMI 远程方法调用
Java DB 这是一个纯 Java 实现、开源的数据库管理系统
Deployment 用于在web上部署java应用程序和小程序的实用程序
Internationalization 创建可本地化的应用程序
Web Services Java Web服务工具
Troubleshooting 可用于特定的故障排除任务

上面一些Tools可以在JDK的bin目录下找到,并且还有一些其他的工具:

 

    比如:Javah.exe可调用java过程的c过程,JDK8中已经被javac -h取代,并且在JDK10中移除了Javah.exe。

    简单的说:JDK = JRE+Development Tool(Java 开发工具)

注:如果只需要运行java程序/Applet程序(是一种特殊的java程序,本身不能单独运行,需要嵌入在html中,借助浏览器/appletviewer解释执行),下载安装jre环境即可。如果要自行开发,需要下载jdk,djk中附带有jre环境

   JDK目录下的src.zip文件:是java提供的API类的源代码压缩文件。

3、JDK环境变量设置

3.1、什么是环境变量

    在学习dos命令的时候,我们打开截图工具:snippingtool,使用win+R,再输入snippingtool即可,但并非所有可执行程序都能通过这种方式打开。

    我们看到Snippingtool.exe在C:\windows\System32目录下,而QQ在C:\Program Files (x86)\Tencent\QQ\Bin\QQScLauncher.exe目录下。 他们有什么区别吗?我们看下环境变量:  

    C:\windows\System32,在系统环境变量中,当我们使用命令行运行一个命令的时候,操作系统会自动搜索当前目录以及PATH变量中的路径。  

    DOS命令分为内部命令和外部命令,内部命令是集成在COMMAND.COM中的,是计算机启动后就常驻内存的命令,在任何命令下都可以使用的;而外部命令是一个可以单独执行的文件,外部命令需要保证命令文件在当前目录中,如果我们同样希望在任何命令下可以执行一个外部命令,我们就可以把这个路径加到环境变量中。

    环境变量:是为执行计算机指令提供的一个环境,一个让系统自动检索的路径。

3.2、环境变量设置

    前面我们安装好了jdk,并且介绍了什么是环境变量,为了方便我们开发及使用JDK-Tools,我们给他设置一下环境变量。

1)步骤一

    在系统变量里点击新建,变量名填写JAVA_HOME,变量值填写JDK的安装路径,比如:“C:\Program Files\Java\jdk1.8.0_341”了

2)步骤二

    在系统变量里点击新建变量名填写CLASSPATH,变量值填写“.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME\lib\tools.jar ”。注意不要忘记前面的点和中间的分号。

 

注:在window中“ .”指的是当前路径,linux中也是,也就是说从当前目录开始查找class文件(CLASSPATH:告诉jvm要使用或者执行的class放在什么路径上)。

dt.jar是关于运行环境的类库,主要是swing包

tools.jar是关于一些工具类的类库

   rt.jar包含了jdk的基础类库

3)步骤三

    在系统变量里找到Path变量,这是系统自带的,不用新建。后加上“;%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin”。注意前面的分号。

 

注:%JAVA_HOME% 即取JAVA_HOME=....的这个值,不写就是JAVA_HOME字符串了。设置了Path,可以在任何路径下都可以识别java/javac命令

4)步骤四

    当我们在cmd中运行java和javac目录都正常时,我们的环境变量就配置完成了。

java -version 查看Java运行环境的版本;

javac -version 查看Java程序编译的版本;

4、第一个java程序

4.1、java和javac命令简介

4.1.1、java-运行java程序命令工具

【命令功能:】 java命令启动java应用程序。它通过启动Java运行时环境(JRE)、加载指定的类并调用该类的main()方法来执行java程序。

【命令格式:】 java [-options] classname [args...]  用于执行java类
          或 java [-options] -jar jarfile [args...]  用于执行jar文件

【常用选项:】
    -server       选择 "server" VM,默认 VM 是 server.
    -cp           <目录和 zip/jar 文件的类搜索路径>
    -classpath    <目录和 zip/jar 文件的类搜索路径>用 ; 分隔的目录,JAR档案和ZIP档案列表,用于搜索类文件。
    -verbose:[class|gc|jni] 启用详细输出
    -version      输出产品版本并退出
    -showversion  输出产品版本并继续
    -esa | -enablesystemassertions  启用系统断言
    -dsa | -disablesystemassertions 禁用系统断言
    -javaagent:<jarpath>[=<选项>] 加载 Java 编程语言代理, 请参阅 java.lang.instrument
    -splash:<imagepath> 使用指定的图像显示启动屏幕

当然还有很多非标准选项、运行时选项、JIT编译选项等等:
    -Xmnsize  设置JVM年轻代堆的初始大小和最大大小
    -Xmssize  设置JVM堆的最小大小和初始大小
    -Xmxsize  设置JVM最大允许分配的堆内存大小

【使用技巧:javaw命令与java相同,只是javaw没有关联的控制台窗口。如果不希望出现命令提示窗口,请使用javaw。然而,如果启动失败,javaw启动器将显示一个包含错误信息的对话框。】

4.1.2、javac-编译命令工具

【命令功能:】 Java编程语言编译器,读取用Java编程语言编写的源文件,并将它们编译成字节码文件。

【命令格式:】javac <options> <source files>

【常用选项:】
  -g                         生成所有调试信息
  -g:none                    不生成任何调试信息
  -g:{lines,vars,source}     只生成某些调试信息
  -nowarn                    不生成任何警告
  -verbose                   输出有关编译器正在执行的操作的消息
  -deprecation               输出使用已过时的 API 的源位置
  -classpath <路径>            指定查找用户类文件和注释处理程序的位置
  -cp <路径>                   指定查找用户类文件和注释处理程序的位置
  -sourcepath <路径>           指定查找输入源文件的位置
  -bootclasspath <路径>        覆盖引导类文件的位置
  -extdirs <目录>              覆盖所安装扩展的位置
  -endorseddirs <目录>         覆盖签名的标准路径的位置
  -proc:{none,only}          控制是否执行注释处理和/或编译。
  -processor <class1>[,<class2>,<class3>...] 要运行的注释处理程序的名称; 绕过默认的
搜索进程
  -processorpath <路径>        指定查找注释处理程序的位置
  -parameters                生成元数据以用于方法参数的反射
  -d <目录>                    指定放置生成的类文件的位置
  -s <目录>                    指定放置生成的源文件的位置
  -h <目录>                    指定放置生成的本机标头文件的位置
  -implicit:{none,class}     指定是否为隐式引用文件生成类文件
  -encoding <编码>             指定源文件使用的字符编码
  -source <发行版>              提供与指定发行版的源兼容性
  -target <发行版>              生成特定 VM 版本的类文件
  -profile <配置文件>            请确保使用的 API 在指定的配置文件中可用
  -version                   版本信息
  -help                      输出标准选项的提要
  -X                         输出非标准选项的提要
  -J<标记>                     直接将 <标记> 传递给运行时系统
  -Werror                    出现警告时终止编译
  @<filename> read options and filename from file

4.2. The first java program - output hello world

1) Test.java

    First, create a new Test.java file in the D:\testJava directory, and write in the file:

public class Test{
 
    public static void main(String[] args){
 
       System.out.println("hello world!");
 
    }
 
}

    Test is a class, a java program, consisting of one or more classes. A program has only one main() main entry method.

2) java class with package name

package com.cn;

public class TestPackage{
 
    public static void main(String[] args){
 
       System.out.println("hello world!");
 
    }
 
}

Guess you like

Origin blog.csdn.net/xiaoxianer321/article/details/127914161