首頁  >  文章  >  Java  >  Java 簡介:針對初學者

Java 簡介:針對初學者

Mary-Kate Olsen
Mary-Kate Olsen原創
2024-10-05 06:13:02261瀏覽

Introduction to Java

What is Java?

Java is a versatile, object-oriented programming language first released by Sun Microsystems in 1995. It's designed to be platform-independent, following the principle of "Write Once, Run Anywhere" (WORA). This means that Java code can run on any device or operating system that has a Java Virtual Machine (JVM) installed, without needing to be recompiled.

Introduction to Java: for Beginners

History
In June 1991, a small team of engineers at Sun Microsystems led by James Gosling (along with Mike Sheridan and Patrick Naughton) started a project called Green. This is to develop a programming language for small electronic devices such as television, setup-box, etc.

Introduction to Java: for Beginners

In 1993, the HTTP protocol and Mosaic browser arrived which made them to develop the language for the internet.

In 1995, they developed a browser named Webrunner which is capable of showing HTML content mixed with applets. Sun Microsystems officially announced Java at the SunWorld conference and Netscape agreed to include Java support in their popular Netscape Navigator browser.

In 2009, Sun Microsystems was bought by Oracle. It was initially named 'OAK' after an oak tree that stood outside his office. Then, it was renamed to 'JAVA' as the 'OAK' trademark was already used by Oak Technology.

Key features of Java include:

  1. Object-oriented: Java is built around the concept of "objects" that contain data and code.
  2. Platform independence: Java code can run on any platform with a JVM.
  3. Security: Java has built-in security features and a robust security framework.
  4. Multi-threaded: Java supports concurrent programming, allowing multiple threads to run simultaneously.
  5. Large standard library: Java comes with a comprehensive set of standard libraries and APIs.

Java is widely used for developing enterprise-level applications, Android mobile apps, web applications, and more.

Setting up Java Environment

To start programming in Java, you need to set up your development environment. Here's a step-by-step guide:

  1. Download and install the Java Development Kit (JDK):

    • Visit the official [Oracle website](https://www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html or adopt the OpenJDK website.
    • Download the appropriate JDK version for your operating system.
    • Follow the installation instructions provided.
  2. Set up environment variables:

    • Add the Java bin directory to your system's PATH variable.
    • Create a JAVA_HOME environment variable pointing to your JDK installation directory.
  3. Install an Integrated Development Environment (IDE):

    • While not strictly necessary, an IDE can greatly enhance your Java development experience.
    • Popular choices include IntelliJ IDEA, Eclipse, VScode, and NetBeans.
    • Download and install your preferred IDE.
  4. Verify your installation:

    • Open a command prompt or terminal.
    • Type java -version and press Enter. You should see information about your installed Java version.
    • Type javac -version to check if the Java compiler is correctly installed.

Your First Java Program

Let's create a simple "Hello, World!" program to ensure your Java environment is set up correctly and to introduce you to basic Java syntax.

  1. Open your text editor or IDE.

  2. Create a new file and name it HelloWorld.java.

  3. Enter the following code:


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


  1. Save the file.

  2. Open a command prompt or terminal, navigate to the directory containing your HelloWorld.java file.

  3. Compile the program by typing:


javac HelloWorld.java


This will create a HelloWorld.class file.

  1. Run the program by typing:

java HelloWorld


You should see the output: Hello, World!

Congratulations! You've just written and run your first Java program.
Let's break down the code:

  • public class HelloWorld: This declares a public class named HelloWorld. In Java, the class name must match the filename.

  • public static void main(String[] args): This is the main method, the entry point of any Java program.

  • System.out.println("Hello, World!");:此行列印文字「Hello, World!」到控制台。

隨著我們繼續學習 Java,在下一篇文章中,我們將討論 Java 語法基礎知識。我們將探索更複雜的概念,如變數、資料類型、控制結構、物件導向程式設計等等。

我很想聽聽您使用 Java 的經驗!
您最想了解 Java 的哪個方面,為什麼?

如果您發現本文有幫助,請考慮關注以獲取更多 Java 內容。非常感謝您的讚和評論 - 它們幫助我了解您最感興趣的主題,使我能夠根據您的需求自訂未來的內容。

您在設定 Java 環境時遇到任何問題嗎?在下面的評論中分享您的經驗,讓我們一起解決問題!
請繼續關注我們的下一篇有關 Java 語法基礎知識的文章。快樂編碼!

以上是Java 簡介:針對初學者的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn