Getting Started with Java

Source: Internet
Author: User

Java source code needs to be compiled to execute, and execution requires the Java Runtime Environment, but the advantage is that as long as there is a running environment, you can execute on any platform, just compile once, so versatility is good.

The following is an example of a windos system.

Environment preparation

The Java environment is divided into two types, JDK (Java Development Kit) and JRE (Java Runtime Environment). The JRE is small and provides only the operating environment. If you do development requires JDK (official website download), after downloading the JDK installed.

Project creation and code writing

Create a new directory anywhere and save the project. Java has the concept of a package, the package is a bit similar to the directory, is to be large in the project, convenient multi-file management. Create a new subdirectory in test, create a new subdirectory first in test, and then create a new Java source program file, named First.java (note case), with Notepad, and enter the code:

1  Package Test.first; 2 3  Public class First {4   5    Public Static void Main (string[] args) {6     SYSTEM.OUT.PRINTLN ("Java test"); 7   }89 }

Once you have saved the file, you can test it.

Compiling and running

Open Start-run, enter CMD, open the command handler, and switch to the project directory you just created.

First compile the Java source program, enter:

"D:\Program Files\java\jdk1. 8. 0_91\bin\javac "Test\first\first.java

Bin\javac Front is the JDK's installation directory, adapted to your own installation directory.

If there is no hint, the compilation is successful, look at the project directory in the \test\first will be more than a first.class, this is compiled generated Java program.

The way to run this is to enter:

"D:\Program Files\java\jdk1. 8. 0_91\bin\java "Test.first.First

Here Test.first is the package name, the Java Runtime Environment will go to the corresponding directory to find the class file.

If normal, the console will output Java test.

Getting Started with Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.