1.3-The writing and running process of a typical Java program

Source: Internet
Author: User

Java language Application scope

Desktop application Programming

Web Client Programming

Web Server Programming

Mobile phone programming

Robot programming

The first Java program

Java Development Environment Building

Download: Download j2sdk (Java 2 software development Kit)

from http://java.sun.com

Install: Run the executable (as with normal software installation, click Next to Ok! )

environment variable configuration:

environment variable (that is, provide a path information for the relevant command, tell him where to find the relevant file information):
Set up:

Add the system environment variable java_home, set to the JDK installation path:

Modify the System environment variable path, append% java_home%\bin to the front , and separate it with the original path. Add again: ".;". This is meant to indicate the current directory.

Note: (%java_home%\bin)


classpath Problem: If you use jdk1.5 above you do not need to configure this environment variable! The JRE automatically searches for class files and associated jar files under the current path

Test installation: Run the cmd input command: java–version: The following results are tested.

Writing a program in a text editor: A typical Java program's writing and running process

Edit stage: (Programmer edits code and saves on disk)

public class welcome{

public static void Main (string[] args) {

System.out.println ("Hello java!");

}

};

Save As: Welcome.java

The compile phase. (compiler creates a class bytecode file)

Enter the directory where the Java files are located, execute the command:Java WELCOME.JAV

Generate class file

Execution: What happened after "Java Welcome". is the 3-5 stage.

Loading phase: The program must first be put into memory before execution. The process is that there is a class loader that transfers one or more class file contents to memory. Java Welcome Activates the Java Interpreter (JVM), and the JVM calls the class loader to load the information in Welcome.class.

Code validation: The JVM Invoke Code Checker verifies that the loaded code is legitimate and does not break the Java security constraints.

Because Java code is propagated in the network environment, strict security constraints must be ensured in order to avoid destroying users ' files and systems.

Run phase: The computer executes this program byte by bit under the control of the CPU.

First Program Common error

The following error occurred:' Java ' is not an internal or external command, nor is it a running program or batch file.

Set path

Compile Javac Test.java, clearly see the file, why can't find it? HelloWorld.java.txt

Show Extension! (detailed list/show all files/title bar Address bar full path)

Nosuchmethoderror:main

Solution: This line of code is wrong to determine if it is: public static void Main (string[] args)

Summary and promotion of the first Java program

Java is case sensitive and the program cannot run if there is a case-spelling error.

The keyword public is referred to as the access modifier (access modifier), which is used by other parts of the control program to access the code.

The keyword class indicates that all content in a Java program is contained in a class, and Java is a purely object-oriented language.

There can be at most one public class declaration in a source file, with no limit to the number of other classes, if the source file contains a public class, the source filename must be the same as the class name of public that is defined in it, with "Java" as the extension.

A source file can have more than one class

Properly compiled source files, you will get the corresponding bytecode files, the compiler generates a separate bytecode file for each class, and the bytecode file is automatically named as the class name and with "class" as the extension.

The Main method is the entry method for the Java application, which has a fixed writing format:

public static void Main (string[] args) {...}

In Java, the code for any method must start with "{" and End With "}", with curly braces dividing the parts of the program, so the curly brace style is unrestricted because the compiler ignores spaces .

Java Each statement must end with a semicolon , and the carriage return is not the end flag of the statement, so a statement can span multiple lines.


Editing style

Attention Indent!

Programming in pairs!

Common Java Development tools

Text Editor

UltraEdit

EditPlus

notepad++

Integrated development Environment (IDE)

JBuilder (http://www.borland.com)

Eclipse (http://www.eclipse.org) * * * *

NetBeans (http://java.sun.com)

WSAD (http://www.ibm.com)

Common DOS commands

CD into a directory

Cd..

Dir

Up and down keys: Find the command you've knocked over

TAB key: Auto-completion command



This article is from the "12931675" blog, please be sure to keep this source http://12941675.blog.51cto.com/12931675/1928880

1.3-The writing and running process of a typical Java program

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.