Java Beginner: Beginner's Notes

Source: Internet
Author: User
Tags naming convention java keywords

So far we have introduced a very basic Java programming, so you should have a vague impression of Java, at least know the steps, it is how to run, and can tiger write a short program, this can be considered a phase, we say to this stage, you should pay attention to the points:

1. How to learn Java, a lot of beginners quick success, learned the basic input and output After the Java also feel nothing, began to try, immediately find a lot of Java books, hard to read the hard to learn, specifically pick their own completely do not understand the place to see, and then found that Java is very difficult ah , I have spent weeks or even longer, incredibly do not understand, so since then never touch java. is Java difficult? Responsible to tell you, difficult, very difficult, said not difficult person is standing to talk not waist pain, he forgot he began to learn how to scratch the heart of the liver. In fact, since we can remember, there is no one thing to be studious about.

Can chew, the goal is not too big, because the lofty goal is too unreal, can have the lofty goal, but is not the recent matter which you should consider how to realize concretely. Learning Java is also the case, just learned the input and output of friends, should put most of the effort to the intensive reading how to basic input output, how to define the basic data type of data, how to compile the execution of Java program. Do not underestimate this seemingly extremely simple thing, the basis is the most important, I have been trying to hit a "Hello world" and spent a full number of hours. Hundred feet tall buildings, no good foundation, will collapse, remember to remember. Of course, I am not opposed to beginners to learn the next step of knowledge, I just said to slowly, how slow it? In my experience, if you have not learned any programming language and are not a genius, and you are a diligent person, it will take at least two weeks or so to practice the basic input and output, and then proceed to the next step.

2. Java is very sensitive, that is, uppercase and lowercase letters, in Java can not be seen as the same thing. For example, System.out.println ("I am Student"); This works perfectly fine, but if you write System.out.println ("I am Student"); Absolutely not (unless you have a very painful self-made a package called system, and then inside also made an out package, and then you get a println method, which in theory should be possible, but I did not try, because the comparison is meaningless). Similarly, you write an int n; also wrote an int N; Those two variables are different variables. Java keywords, generally speaking, you can not change, and your own definition of variable name, uppercase lowercase, will also be considered a different thing java.

3. Write the program to a clear format, good readability, the first line to be indented, pairs of curly braces, in addition to the class of parentheses, the last to be in the same column. This is not mandatory, everyone's habits are different, but at least to clear norms, such as someone, never put a pair of curly braces in the same column, but let the eclipse automatic typesetting, although also very normative, but every time I look at her code to change the curly braces to be comfortable, and then she was so angry to change back.

In fact, only from whether it can run, it is not related, Java does not care about your program code to look at the chaos, as long as the right, you can compile and run, which is forced by the Python programmer code format. But you write so messy, you look not upset ah? It's disturbing to see that you don't get upset with others. And in a few days you can see for yourself, you can not understand. Why should someone else look at it? Because if you end up being a programmer, then you have to work with someone else to write the program, and your code is bound to be seen by others. By then you will be too late to develop good habits.

4. Define the data name at least correctly, in accordance with the naming convention, and secondly to make sense. In fact, Baidu there can be found in the Java naming rules, basically, the data name can only be in English mode, continuous, not a Java keyword string, the first character can be letters, underscores or $, some people like to use C-style naming, Some people like to use Pascal's canonical naming method. Here as a rookie, I'm not good at what to comment, I just think Java is Java, things we can learn, and even can be mixed with, but should also retain the characteristics of each thing.

For a few examples, a common data declaration is initialized: String name = "Jianbo Shi"; int age = 30; Double mark = 70.5; The above is correct. Note that some people like to capitalize the first letter of the data name, but I prefer lowercase to the definition of the class name, but it doesn't matter, it's a habit.

Here are a few errors: String my name = "John Mark"; The reason for the error is that there is a space between my name, if you want to make it seem like there is a space in the middle, you can do so string my_name = "John Mark"; There are a lot of people who like to use it. int age = 30; The reason for the error is that the age of two words, not English, perhaps in the Chinese computer, Java will not error or even compile through, but the words can not be run, in short, in addition to the information to display, the code part of not in Chinese. Double 200mark = 70.5; The reason for the error is that the first character of the 200mark is a number.

A few more though yes, but not bad: String a = "John Mark"; int B = 30; Double C = 70.5; Scanner myface = new Scanner (system.in); These four are not good, the reason is, who knows your that a,b,c is what to do? Believe me, if your program is more than hundreds of lines and you wrote it a few weeks ago, I guarantee that even if you go to see that program yourself, you can't immediately say what A,b,c is doing, let alone others. And when did your face become an instance of Java's scanner? Listen to why so upset, so want to take three days not to wash socks hu you ya bear face? You don't believe it, this is what a beginner I have seen wrote.

This is about the above points, these are very important, pay attention to. And do not underestimate the simple procedures, in the long run, relatively simple procedures is the most important, and simple things, has never been as simple as we thought, for example, the following is the program we have done:

The code of this program contains at least a few points of knowledge: the understanding and import of the package, the understanding of the static function, the function return value, the function parameter, the definition of the class instance, and the invocation of the built-in function. If you're forced to say something, you can also contact the default build function. In other words, when you learn a little bit more, look back at this program, in fact, it really is not as simple as you thought.

Even from a beginner's point of view, if you think about it, it is not so easy, for example, that the output results with so many 0, if you want to let those 0 do not show, but still have to use printf? This depends on the other uses of%f. For example, I don't want to System.out.print every time, I want to use print directly every time? Although very few programmers are so sore, however, this can be achieved, as long as the display of import Java is the default import of Lang, but this time to be imported together with the method.

Another egg hurts, I don't want to use the main function, I would like to bypass Java to the main class in the detection of the primary function to start running Java, this line? This is perfectly possible, as long as you borrow the static hand, you can remove the main function:

Do you think it was compiled and run successfully? Yes. This small program is short and not difficult, but it allows you to have a deeper understanding of how static code blocks work. Although this program does not have any practical significance, but I just want to say that simple things are not really so simple, complex things come from simple things, simple things can explain the complex truth, but in turn, seemingly complex things may really broke, you say?

Java Beginner: Beginner's Notes

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.