-------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------
This series of documents cooperate with the previous "JBuilder Development Practitioner Road" series of articles, standing at the level of language itself for you to learn the Java programming language. Mainly refer to Java online documentation, as well as "Java2 core technology". Article positioning and reader objects are mainly readers for zero start. Basically, the road to the Java program design masters is basically adjusted to the Java program.
Zeng Yi Yu in Computer Software Theory Lab
-------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------
Java programming basic structure
Prehistoric Java. Construction of a simple Java program. Notes
Type. Variable. Assignment and initialization
Operator. String. Control flow
Big numbers. Array
Prehistoric Java
Java came from Sun's project called Green, its original purpose was to develop a distributed code system for household consumer electronics, so we can send E-mail to refrigerators, TV sets, etc. Control, communicate with them. Start, ready to use C , but C is too complicated, the security is poor, and finally based on C develops a new language Oak (Java's predecessor), Oak is a language for the exquisite and secure language, Sun has bidding A interactive television project, but the result is defeated by SGI. Poor OAK almost homeless, happening MOSAIC and Netscape developed by Mark Ardresen in this time, the Oak project group members, they have prepared the Hotjava browser with Java, got the support of Sun CEO SCOTT MCNEALY, triggered Java Entering the Internet. Java's name also has a job. One day, members of several Java Member Groups are discussing what name to this new language, when they were drinking Java (Java) coffee in the cafe, there is a law to say that it is called Java, how others are appreciated, so the name of Java will pass this way.
Construction of a simple Java program
We all use the HelloWorld program in any language. It turns out that it is not bad. We have helloworld to start to know the JAVA programming language journey.
With the HelloWorld program, we can have a comparative summary understanding of the structure of the Java program. First we need to pay attention to Java is case sensitive. Any errors on the case can cause the program to fail. For example, you wrote main in the program, which will definitely report in Java, but if you write a C # program, then he can pass, because C # main is uppercase M.
Pubilc is called access modifier, what you need to know is that he is a public type, and some other types of access modifiers are intended to stay in the following article unified introduction. Class Indicates that any part of the Java program is included in a class. About Class's naming, it is necessary to pay attention to some: From the letter, letters and numbers can be used, but cannot use Java reserved words, this is the case. If the class name consists of multiple words, then each word starts the letters (this is a good habit, but if you don't do this, there is no bigger), such as Myjavaprogram.
The file name needs to be exactly the same as your total class name, and you need to be .java as an extension. After compiling is a band code file, the compiler will automatically clearly clear this bytecode file, such as the last example is HelloWorld.class. Then we use the Java interpreter to execute the bytecode file. If we are in the Borland JBuilder environment, we only need to use Run Using Default. If it is under the console instead of an integrated development environment, you need to enter Java HelloWorld. It should be noted that the main method is the starting point for any Java program execution. It is still to remind everyone that the main method must define as public, which is in line with the latest regulations, but one story below tells you if you don't need to declare the main declaration as public in JDK1.2, the following code actually Can pass:
JDK1.2 The virtual machine does not check if the type of Main is already public, which occurs under MS Windows NT, Linux, and Solaris. This is recognized as bug for a long time. However, starting from JDK1.4, the interpreter is enforceding the main method must be public.
One thing I can't help but comment, one of Sun's most savvy is that all bug reports are public, so it is very beneficial to solve the problem, you can even put a ticket for your most concerned BUG, so This bug will get full attention. All BUG reports can be found from the address below.
http://developer.java.sun.com/developer/bugparade
About the use of braces We think it is very casual, because the Java compiler will ignore all spaces, so no matter what kind of program design style you use, we can recommend two kinds, one is the left flower parentheses With the class name and method name, another method is to rough the brackets. Individuals are more biased below this style.
Everyone may have already noticed that the curly bracket marks the beginning and end of our method. Our code statement must be a semicolon as a finger, and the carriage return cannot represent the end of the statement. So a statement can span multiple lines. We used the System.out object to call the PrintLn method. Java's general syntax is:
Object.method (parameters) is: Object. Method (Parameter List)
Note in Java:
There are three notes in the Java programming language. We first look at the following code:
Method 1: Use // Before every line of comments
Method 2: If the comment is multi-line, we generally use / * ... * / contain all comments.
Method 3: Use / ** ............ * / as automatic documentation.
Through the discussion above, we have a relatively simple understanding of a Java program. In the next section we will focus on the data type of Java.