Java Learning Note 2--hello World

Source: Internet
Author: User

I'm done with the Bi Xiangdong podcast. Teacher's Java Basics Tutorial--Phase One: Java Development Prelude

1, Java development process ——————————————— is not recommended to first write code with Eclipse, because its function automatically generated, not conducive to the search for the programming feel
After you open Notepad and finish writing the program, modify the. java extension.
Then compile the Java file using the command Javac in the DOS console


Java is embodied in the form of a class, which means that the code written has a beginning and an end.
For example, programs start with classes (class)

Now write down the following code in Notepad:

 class Demo//(category name)// curly braces for range

Save As 123.java

Javac 123.java generate run program from source program Demo.class (run program that can run as long as there is a virtual machine)
Java Demo.class run the Run program

At this point, the reason is that the above program does not have a separate operating environment, now write a complete HelloWorld

class demo{        publicstaticvoid// main function, in order to ensure the independent operation of the class, is the entry of the program        {System.out.println ("Hello World");}        }            

The above procedures should pay attention to three points:
1. The first letter of String must be capitalized
2. The first letter of the System must be capitalized
3, each line to be played; semicolon
4. Must have and have only one main function
Syntax Specification:
1, the class name should have the meaning, the class name usually has the word composition, the word first letter general capitalization, the multiple words composes the class name, each word's first letter also must capitalize
2. The class name and Java file name must be the same when you add public to it

Dos window input set classpath= means empty classpath configuration
When the virtual machine starts, the environment variable classpath is then the current directory; path is the opposite.

When there is no semicolon in the classpath, the Java virtual machine is only looking for the classpath, and the semicolon will find classpath to find the current directory.
Therefore, in order to prevent the operation of the file name and the result is different from the expectation, do not add semicolons at the end when configuring Classpath

Set Classpath=.;c:\;b:\ Here. Represents the current path

There can be multiple classes in a Java file, and multiple class files are generated when Javac

Java has documentation comments, which are unique to Java
Note Format for Java:
1. Single-line comment//
2, multi-line Comment
/*
*/
3. Documentation Notes:
/**
*/

Multi-line comments do not allow nested multiline comments

Develop the habit of commenting when you write code

Write code requirements: first write the requirements and ideas, and then write the code
/*
Requirements: Define a Hello World applet.
Ideas:
1.
2.
Steps:
1. Define a class by using the class keyword to write code into the class.
2, in order to ensure the independent operation of the class, define a main function in the class, the format is public static void main (string[] args)
3. Save as a file with the extension java.
4. Compile the Java file in the DOS console using the Javac tool.
5. The generated class file is then executed through the Java command.
*/

class Demo// Define a class {        // main function public        static  void  Main (string[] args)        {                // output Statement                System.out.println (" Hello java ");}        }

Java Learning Note 2--hello World

Related Article

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.