Basic Structure of Java programming

Source: Internet
Author: User
--------------------------------------------------------------------------
This series of documents is introduced in conjunction with the previous article "the path to JBuilder development practitioners" to provide you with the Java programming language at the language level. Refer to Java online documentation and Java2 core technology. Article positioning and intended audience are mainly intended for readers with zero starting points. Basically, the primary readers are gradually guided to the path of Java programming experts.
Zeng Yi, computer software theory lab
--------------------------------------------------------------------------
Basic Structure of Java programming

. Prehistoric Java. Simple Java program construction. Annotation
. Data Type. Variable. Value assignment and initialization
. Operator. String. Control Process
. Large numbers. Array

Prehistoric Java     
Java comes from Sun's Green Project. Its original purpose was to develop a distributed code system for household consumption electronic products, in this way, we can send e-mail to refrigerators, televisions, and other household appliances to control them and exchange information with them. At the beginning, I plan to adopt C ++, but C ++ is too complicated and has poor security. Finally, I developed a new language oak (the front of Java) based on C ++ ), oak is a sophisticated and secure language for networking. Sun once bids for an interactive TV project, but the result is SGI's defeat. The poor oak was almost homeless. At this moment, mosaic and Netscape developed by Mark ardreesen inspired the oak project team members. They used Java to compile the hotjava browser and received support from Scott mcnealy, CEO of sun, this triggers Java to enter the military Internet. The name of Java is also interesting. One day, several members of the Java member group are discussing the name of the new language. At that time, they were drinking Java (Java) coffee in the cafe, one of them said exactly what Java was and was appreciated by others, so the name of Java was passed on like this.

Simple Java program construction

We use the helloworld program to start any language. Facts prove that the results are actually good. Let's get to know the Java programming language with helloworld.

Through the helloworld program, we can have a brief understanding of the Java program structure. First, we need to note that Java is case sensitive. Any case-insensitive error can cause the program to fail. For example, if you write the main in the program as main, it will definitely report an error in Java, But if you write a C # program, then it can pass, because main in C # Is uppercase M.

Pubilc is called an access modifier. What you need to know is that it is a public type, and some other types of access modifiers are intended to be kept in the subsequent articles. Class indicates a Class. Any part of a Java program is contained in a Class. Note the following for class naming: starting from a letter, you can use letters and numbers, but you cannot use Java reserved words. If the class name is composed of multiple words, it is a good habit to use uppercase letters at the beginning of each word, such as MyJavaProgram.

The file name must be exactly the same as your common class name and use. java as the extension. After compilation, A bytecode file is generated. The Compiler automatically identifies this bytecode file. For example, the above example is named HelloWorld. class. Then we will use the Java interpreter to execute the bytecode file. In the Borland JBuilder environment, we only need to use Run Using Default. If it is in the console rather than in the integrated development environment, you need to enter java HelloWorld.

Note that the main method is the starting point for any java program execution. We would like to remind you that the main method must be defined as public, which complies with the latest provisions, however, the following story tells you that if you do not need to declare main as public in JDK, the following code can pass:

The jdk1.2 virtual machine does not check whether the main type must be public, which may occur in MS Windows NT, Linux, and Solaris. This was recognized as a bug for a long time. However, since JDK1.4, the interpreter forces the main method to be public.

One thing I can't help but comment on. One of Sun's smartest points is to make all the bug reports public, which is very helpful for solving the problem, you can even vote for the bug you are most concerned about, so that this bug will be fully valued. All bug reports can be found at the following address. Http://developer.java.sun.com/developer/bugParade

We think that the use of braces is very random. Because the Java compiler ignores all spaces, No matter what program design style you use, you can use them. However, we recommend two methods, one is that the left curly braces keep up with the class name and method name, and the other is that the curly braces are aligned up and down. I prefer the following style.

As you may have noticed, curly braces mark the beginning and end of our method body. The Code statement must use a semicolon as the Terminator. Carriage return does not end the statement. Therefore, a statement can span multiple rows. We used the System. out object and called the println method. The general syntax of Java is:
Object. method (parameters) is: object. method (parameter list)

Java annotations:
There are three annotation methods in the Java programming language. First, let's look at the following code of the annotation:

Method 1: Use // before each line of comment
Method 2: If the comment is multiple rows, we generally use /*...... */Contains all comments.
Method 3: Use /**............ */Used as an automatically generated document.

Through the above discussion, we have a simple understanding of the composition of a Java program. In the next section, we will focus on Java data types.

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.