Java 简明教程

Java Tutorial

Java Tutorial

Java tutorial 为努力学习 Java 编程的初学者到高级程序员编写。我们提供了许多实际例子来解释概念,步骤简单易懂。本教程由 Tutorials Point 经验丰富的 Java 程序员编写并审阅,并尽最大努力使其对学生和 Java 开发人员有用。

This Java tutorial has been written for beginners to advanced programmers who are striving to learn Java Programming. We have provided numerious practical examples to explain the concepts in simple and easy steps. This tutorial has been prepared and reviewed by experienced Java Programmers at Tutorials Point and best effort has been put to make it useful for the students and Java developers.

完成本教程后,您会发现自己在 Java 编程方面的专业知识达到中等水平,从那里您可以提升自己到下一个水平。

After completing this tutorial, you will find yourself at a moderate level of expertise in Java Programming, from where you can elevate yourself to the next levels.

What is Java?

Java 是一种流行的高级 object-oriented programming 语言,最初由 Sun Microsystems 开发,并于 1995 年发布。目前,Java 归 Oracle 所有,超过 30 亿台设备运行 Java。Java 可以在各种平台上运行,如 Windows 、Mac OS 和不同版本的 UNIX 。如今,Java 正被用于开发众多类型的软件应用程序,包括桌面应用程序、移动应用程序、网络应用程序、游戏等等。

Java is a popular high-level, object-oriented programming language, which was originally developed by Sun Microsystems and released in 1995. Currently, Java is owned by Oracle and more than 3 billion devices run Java. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. Today Java is being used to develop numerous types of software applications including Desktop Apps, Mobile apps, Web apps, Games, and much more.

在本教程中,您将学习有关 Java 的所有知识,从基础知识到高级概念,如概述、历史、安装、基本输入/输出、条件和控制语句、数组、类、继承、方法重载和重写、异常处理等等。

In this tutorial, you will learn everything about Java starting from basics to advanced concepts such as overview, history, installations, basic input/output, conditional & control statements, arrays, classes, inheritances, method overloading & overriding, exceptional handling, exception handling, and many more.

Java First Example

Java 中的第一个示例是 print "Hello, World!" 到屏幕上。让我们快速查看 Java 编程示例中的第一个示例:

The first example in Java is to print "Hello, World!" on the screen. Let’s have a quick look at the first examples in Java programming example.:

public class MyFirstJavaProgram {

   /* This is my first java program.
    * This will print 'Hello, World!' as the output
    */

   public static void main(String []args) {
      System.out.println("Hello, World!"); // prints Hello, World!
   }
}

Online Java Compiler

我们的 Java 编程教程提供了各种示例来解释这些概念。要在您的浏览器中自己编译和执行给定的 Java 编程示例,我们提供了 Online Java Compiler 。您几乎可以直接在您的浏览器中编辑和执行所有示例,而无需设置您的开发环境。

Our Java programming tutorial provides various examples to explain the concepts. To compile and execute the given Java programming examples in your browser itself, we have provided Online Java Compiler. You can Edit and Execute almost all the examples directly from your browser without the need to set up your development environment.

尝试单击 图标以运行以下 Java 代码,使用 Java 编程打印传统的“Hello, World!”。

Try to click the icon to run the following Java code to print conventional "Hello, World!" using Java Programming.

下面的代码框允许您更改代码的值。所以,请尝试更改 println() 中的值并再次运行它以验证结果。

Below code box allows you to change the value of the code. So, please try to change the value inside println() and run it again to verify the result.

public class MyFirstJavaProgram {

   /* This is my first java program.
    * This will print 'Hello, World!' as the output
    */

   public static void main(String []args) {
      System.out.println("Hello, World!"); // prints Hello, World!
   }
}

Java Features

Java 是一种功能丰富的语言。Java 随着每次更新而不断发展,并且每六个月会发布更新。以下是一些 Java 语言的主要特性 -

Java is a feature-rich language. Java is evolving continuously with every update and updates are coming after every six months. Following are some of the main features of Java language -

  1. Object Oriented: Java is a pure object-oriented language and everything in Java is an object. Java supports OOPS principles like Inheritance, Encapsulation, Polymorphism, Classes , and so on. Java itself can be extended as well being based on an object model.

  2. Platform Independent: Java code is platform independent. A Java code is not compiled into machine-specific code, it is compiled into a platform-neutral byte code. This byte code is executed by JVM which runs the code on the underlying platform. This capability makes Java a Write Once Run Anywhere language.

  3. Easy To Learn: Java inherits features from C, and C and developers can easily learn Java if they know any of the C or C language. Even for someone new to computer languages, java is very easy to learn from scratch.

  4. Secure: Java is secure by architecture. A developer is not required to directly interact with underlying memory or Operating System. Java provides automatic garbage collection so developers are not required to worry about memory leaks, management, etc.

  5. Architectural-Neutral: Java byte code can be executed on any kind of processor. JRE automatically handles the code execution on different types of processors.

  6. Portable - A Java code written on a windows machine can be executed without any code change on MacOS and vice versa. There is no need to make any operating system-specific code changes.

  7. Robust - Java is a very robust language with very strong compile-time error checks, strict type checking, and runtime exception handling.

  8. Multithreading - Java provides inbuilt support for multiprocessing and multithreading. Java provides thread handling, monitors, deadlock handling, racing conditions, etc.

  9. High Performance - Java although being interpreted, still is very performant. JIT (Just In Time) compiler helps in improving performance.

  10. Distributed - Java is designed for distributed systems and is the most popular language for developing internet-based applications as the internet is a distributed environment.

Java Applications

由于 Java 支持面向对象特性并且是与平台无关的,因此广泛用于多个领域。以下列出 Java 的一部分使用领域——

Since Java supports object-oriented features and is platform-independent, it is extensively used in various fields. Listed below are a few areas where Java is used -

  1. Enterprise solutions

  2. Game development

  3. Secured web development

  4. Embedded systems

  5. Mobile application development

  6. Big Data Applications, and many more.

Java Platforms (Editions)

Java 平台分为四种 Java 版本,即:

Platforms of Java are divided into four Java editions, which are −

  1. Java SE (Java Standard Edition): It is a standard edition that is used to develop and deploy portable code for desktop and server environments.

  2. Java EE (Java Enterprise Edition): It is an enterprise edition that is used to develop web applications.

  3. Java ME (Java Micro Edition): J2ME is used to develop mobile applications, it is a Micro edition of Java.

  4. JavaFx: It is used to develop light-weighted user interface for rich internet applications.

Java Jobs & Opportunities

Java 的需求十分高,所有大型公司都在招募 Java 程序员来开发其桌面、Web 和移动应用。

Java is very high in demand and all the major companies are recruiting Java Programmers to develop their Desktop, Web and Mobile applications.

现如今,一位拥有 3-5 年经验的 Java 程序员每年的薪资要求大约是 120,000 美元,并且这是美国需求最高的编程语言。不过,根据工作地点不同,薪资也会有所差异。以下列出使用 Java 的优秀公司,它们需要优秀的 Java 程序员:

Today a Java Programmer with 3-5 years of experience is asking for around $120,000 annual package and this is the most demanding programming language in America. Though it can vary depending on the location of the Job. Following are the great companies who are using Java and they need good Java Programmers:

  1. Google

  2. Microsoft

  3. Facebook

  4. IBM

  5. Amazon

  6. Netflix

  7. Pinterest

  8. Uber

  9. JetBrains

  10. Many more…​

因此,你可以成为上述任何一家大公司的潜在员工。我们开发了十分优秀的 Java 学习资料,这将帮助你备战 Java 相关技术面试和资格认证考试。因此,使用这份简单且有效的教程,你可以随时随地在自己的进度下开始学习 Java。

So, you could be the next potential employee for any of these major companies. We have developed a great learning material for Java which will help you prepare for the technical interviews and certification exams based on Java. So, start learning Java using this simple and effective tutorial from anywhere and anytime absolutely at your pace.

Why to Learn Java?

对于学生和在职专业人士来说,Java 是必须学习的编程语言,可帮助他们成为优秀的软件工程师,尤其是在从事软件开发领域工作时。如果你能够开展一项关于最佳编程语言的调查,Java 一定位列其中。

Java is a MUST to learn programming language for students and working professionals to become a great Software Engineer specially when they are working in Software Development Domain. If you will conduct a servey about the best programming language around, Java is sure to come up.

Java 是一款相对容易学习的编程语言,因此如果你正打算学习一门编程语言,那么 Java 可能就是你的不二之选。另外,还有大量 Java 工具让开发人员和初学者很容易上手。Java 还有其他许多优点,使其成为任何程序员的首要选择:

Java is fairly easy programming language to learn, so if you are starting to learn any programming language then Java could be your great choice. There’s also plenty of Java tools that make it easy for developers and beginners to use. There are many other good reasons which makes Java as the first choice of any programmer:

  1. Java is Open Source which means its available free of cost.

  2. Java is simple and so easy to learn

  3. Java is much in demand and ensures high salary

  4. Java has a large vibrant community

  5. Java has powerful development tools

  6. Java is platform independent

Who should Learn Java

本 Java 教程旨在帮助学生和想要利用 Java 技术(如银行系统、支持系统、信息系统、网站、移动应用程序、个人博客等)开发应用程序的专业人员。我们建议按照左侧菜单中列出的顺序学习本教程。

This Java tutorial will help both students as well as working professionals who want to develop applications using Java technologies like banking systems, support systems, information systems, web websites, mobile apps, personal blogs, etc. We recommend reading this tutorial, in the sequence listed in the left-side menu.

如今,Java 作为最庞大的编程语言之一,已经成为参与软件应用程序开发流程的每个人(包括软件开发者、软件设计师、项目经理等)必须学习的一门语言。

Today, Java is one of the most demanding programming languages and so it has become an essential language to learn for anyone involved in the software application development process including Software Developers, Software Designers, Project Managers, etc.

Prerequisites to Learn Java

虽然我们已经尽力以简单易行的方式呈现核心 Java 概念,但在开始学习 Java 之前,我们假设读者已经对任何编程环境都有合理的了解,并且了解基本概念,如变量、命令、语法等。

Though we have tried our best to present the Core Java concepts in a simple and easy way, still before you start learning Java, it is assumed that the readers have a reasonable exposure to any programming environment and knowledge of basic concepts such as variables, commands, syntax, etc.

Learn Java by Examples

本教程提供了一组 Java 示例。请练习这些示例以更好地学习 Java 概念: Java Examples

This tutorial provides a set of Java examples. Practice these examples to learn the Java concepts better: Java Examples

Getting Started with Java Tutorial

通过理解基础知识和环境设置开始学习 Java,然后按照本教程中提供的章节进行学习:我们从 overview of Java 开始学习。

Get started with Java by understanding its basics, environment setup, and then follow the chapters provided in this tutorial: Let’s start learning with an overview of Java.

Java Online Quizzes

本 Java 教程帮助您准备技术面试和认证考试。我们提供了各种测验和作业,以检查您的学习水平。所提供的测验具有多项选择类型的题目及其带简要说明的答案。

This Java tutorial helps you prepare for technical interviews and certification exams. We have provided various quizzes and assignments to check your learning level. Given quizzes have multiple choice type of questions and their answers with short explanation.

以下是样本测验,请尝试回答任何给定的答案:

Following is a sample quiz, try to attempt any of the given answers:

开始您的在线测验 Start Java Quiz

Start your online quiz Start Java Quiz.

Java Certification

获得 Java 认证,以提升您的技能和职业生涯 Get certified

Get certified in Java to boost your skills and career Get certified

Frequently Asked Questions about Java Tutorial

对于 Java 编程教程,有一些重要的常见问题 (FAQ),本部分将列出它们及其简要答案 - −

There are some important frequently asked questions (FAQs) about Java Programming tutorial, this section lists them down along with their answers briefly - −

1. What are the 4 important concepts in Java?

2. What are the benefits of Java?

3. How much time will it take to learn Java?

5. What are the advantages of Java over Python?

6. How do I start learning Java?

7. What are Java Technologies for Web Applications?

8. Which is the best place to learn Java?