Getting Started with HelloWorld and documentation comments _java Java programming

Source: Internet
Author: User
Tags class definition deprecated documentation throw exception

HelloWorld

public class HelloWorld
{public
  static void Main (String args[])
  {
  System.out.println ("Hello world!");  //Output A statement to the console, and must end with;   


Run the above program as shown in the picture

We begin to analyze and learn the basics of the Java language through the above procedures;

1. Note:

Java annotations are divided into three kinds: single note/Multiline comment/*...*/document comment

The HelloWorld program, like the above, uses multiple lines of comments and single-line comments.

Java also provides an annotation called a document annotation, if the Java source code is written with appropriate documentation comments, and then the Javadoc tool provided by the documentation can be directly extracted from the source code document comments into a system's API documentation. An API document is a document that describes the application interface. In the case of Java, API documentation usually explains the functionality and usage of each class, each method.

Download address for the Java Language API documentation: http://www.oracle.com/technetwork/java/javase/downloads/index.html

About documentation comments, I'll have a special article in the back

2, the organization of Java

Java programs must be in class class form, the class is the smallest program unit class
name
{
 /*java interpreter rules: If a class can be interpreted directly by the interpreter, the class must contain the Main method, And the main method must be decorated with pulbic static void, and the formal parameter of the main method must be a string array type (string args[] is the form of an array of strings) that means that the main method is basically fixed.
  public static void Main (String args[]) 
 {
 
  }   
}

3. Naming rules for Java source files
1 Java program source file suffix must be. Java, can not be other file suffix name

2 A Java source file can contain more than one class definition, but can only contain a public class definition, and the file name of the source file must be the same as the class name of the public class if the Java source file contains a public class definition

3 The Java language is a strictly case-sensitive language. Because the file name of the source file is saved, it should also be case aware

4 The keywords in the Java program are all lowercase

Summary: Through the above program simply said the Java program Framework structure.

Document comments

The Java language provides a more powerful form of annotation: documentation comments. If you add appropriate documentation comments when you write Java source code, then the Javadoc tools provided by JDK can be used to extract the documentation comments from the source code directly into a system's API documentation. API is the meaning of the application interface, API is the BASIC programming interface Java provides, when programming in the Java language, all Java classes, all methods can not be written down, then if we encounter an uncertain place, we must through the API document to view a class, The function and usage of a method.

Download address for Java API documentation: http://www.oracle.com/technetwork/java/javase/downloads/index.html

When the download is complete, open the index.html file in the Docs/api folder,

1, API document home page as shown

2, class description area pattern as follows chart

Since only content that is decorated with public or protected is content that you want to expose to others, and the API documentation primarily provides information to the consumer, the Javadoc tool handles only public or protected-decorated content by default. If the developer really wants the Javadoc tool to extract private-decorated content, you can add the-private option when using the Javadoc tool to implement

Below we use a demo program to illustrate documentation comments

Package Gee;
/**
 website: <a href= "http://www.geeit.me/" > Author Blog station </a>
 <br/> This is a program for Javadoc tool demo
 <br/ > Program Name: Javadoc Demonstration Program
 <br/> program file name: Javadocdemo
 @author Gee
 @version 1.0/Public
 class Javadocdemo
 {
   /** simple test field
   *
   /protected String name;
   /** Main method, program entry/public
   static void Main (string[] args)
   {
       System.out.println ("Hello world!");
   }
 

In addition, if we want the Javadoc tool to generate more detailed documentation information, such as generating detailed descriptive information for method parameters, method return values, and so on, you can use the Javadoc markup. The commonly used Javadoc tags are as follows.

    • @author: Specify the author of the program
    • @version: Version of source file
    • @deprecated: Deprecated methods
    • @param: Parameter description information for the method
    • @return: Description information for return value of method
    • @see: "See" To specify the contents of the cross Reference
    • @exception: type of throw exception
    • @throws: Thrown exception, and exception synonymous.

The Javadoc tool does not extract @author and @version two tag information by default, and if you need to extract both tags you should use the-author and-version two versions specified by the Javadoc tool

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.