The basic structure of Java programming

Source: Internet
Author: User
Tags comments access
program | design--------------------------------------------------------------------------


this series of documents with the previous "JBuilder Development Practitioners Road" series of articles launched, stand on the language itself on the level for everyone to learn the Java programming language. Main reference Java online documentation, as well as "JAVA2 core technology." The article orientation and the reader object are mainly for the 0 starting point reader. Basically to the novice reader step-by-step guidance to the Java Programming Master path.


Zeng in computer software theory laboratory


--------------------------------------------------------------------------




The basic structure of
Java programming








. Prehistoric java. The construction of simple Java programs. Annotation


. Data types-variables-assignment and initialization


. Operator. String. Control Flow


. Large numbers-array





Prehistoric Java


Java is from a sun company called Green Project, its original purpose is to develop a distributed code system for household consumer electronics, so that we can send e-mail to refrigerators, televisions and other household appliances, control them and exchange information with them. Start, ready to adopt C + +, but C + + is too complex, security is poor, finally based on C + + development of a new language oak (Java predecessor), Oak is a network of sophisticated and secure language, Sun has been bidding for an interactive TV project, but the result is SGI defeated. Poor oak almost homeless, just then mark Ardreesen developed Mosaic and Netscape inspired the Oak project team members, they used Java HotJava Browser, with the Sun company chief executive Scott McNealy support, Triggered Java's foray into the internet. Java's name also has an anecdote, one day, several members of the Java member group are discussing the name of the new language, when they were drinking Java coffee in the café, there is a person brainwave called Java How, has been praised by other people, So the name of Java passed away.





Simple Java Program Construction





the beginning of any language we use the HelloWorld program. As it turns out, the effect is good. We have helloworld to begin to understand the Java programming language journey.





through the HelloWorld program, we can have a comparative overview of the structure of Java programs. First we need to note that Java is case-sensitive. Any errors on the case can cause the program not to run. For example, you write main in the program, which will definitely give an error in Java, but if you are writing a C # program, then he can pass, because main in C # is uppercase M.





PUBILC is called an access modifier, all you need to know is that he is a public type, and there are some other types of access modifiers that are intended to remain in the following articles for unified presentation. class represents classes, and any part of the Java program is contained within a class. The name of class, you need to pay attention to is actually the following: starting from the letter, you can use letters and numbers, but not the use of Java reserved words, and so on. If the class name is made up of more than one word, then capitalize the beginning of each word (this is a good habit, but if you don't, it's not a big deal), like Myjavaprogram.




The
file name needs to be the same as your common class name, and you need to use. java as the extension. After compiling is a bytecode file, the compiler will automatically clearly this bytecode file, such as the example above will be named Helloworld.class. We then use the Java interpreter to execute the bytecode file. If it is in the Borland JBuilder environment, we only need to use the run using default. If you are under the console rather than in an integrated development environment, you need to enter the Java HelloWorld.








need to be aware that the main method is the starting point for any Java program execution. Here's a reminder that the main method must be defined as public, which is up to date, but the following story tells you that if you do not need to declare main as public at jdk1.2, the following code can pass:




The
jdk1.2 virtual machine does not check whether the type of main is necessarily public, which can occur under Ms Windows NT, Linux, and Solaris. This has been recognized as a bug for a long time. Starting with JDK1.4, however, the interpreter enforces that the main method must be public.





There's one thing that can't help but comment that Sun's smartest thing to do is to make all the bug reports public, so it's very good for the problem, you can even vote for the bug you care about most, so the bug will get a lot of attention. All bug reports can be found from the address below. Http://developer.java.sun.com/developer/bugParade





About the use of curly braces we think it's very casual, because the Java compiler ignores all whitespace, so no matter what program design style You use, however, we recommend two kinds, one is the left curly braces immediately following the class name and method name, the other is the curly braces up and down. The individual is more inclined to the following style.





you may have noticed that curly braces mark the beginning and end of our method body. Our code statement must be a semicolon as a terminator, and a carriage return cannot represent the end of the statement. So a single statement can span multiple lines. We used the System.out object and called the Println method. The common syntax for Java is:


Object.Method (Parameters) is: Object. Method (parameter list)




Comments in
Java:


Java programming language There are three methods of annotation, we first look at the following code:





Method 1: Use//before commenting on each line


Method 2: If the annotation is multiple lines, we generally use/*......*/to contain all the comments.


Method 3: Use/**............*/as an automated document to generate documents.





through the above discussion, we have a relatively simple understanding of the composition of a Java program. In the next section, we'll 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.