Learning Java is worth your attention. (1) name it "Learning Java, small details that are easy to be ignored by you" (1)

Source: Internet
Author: User

I remember when my sophomore year was about to end, a girl suddenly asked me, "Do you know Java? Can you help me do my homework ?" To be honest, the girl was really pretty and I wanted to help her at the time. However, I have never been in touch with Java, so that I can't afford to finish my homework on Java programming in just a few days. In the end, I did not promise her, and I missed a chance to do a good job in front of her. I have regretted this for more than a few months.

Now that I am a junior, I have a lot fewer courses. Now I have time to look at Java in a simple way.

In my opinion, as a software engineer, there is no need to be proficient in every programming language. Sometimes, you only need to simply understand the advantages and disadvantages of a programming language and the applicable scenarios. As for the syntax rules, you can simply learn them carefully when using them.

Now let's talk less about it. Next I will show you the small details that are easy to ignore (1 ).

Read the following code snippet

public static int funtion(int x){System.out.println("The funtion has run successfully!");return x;}

This is a function that returns the int type, which is very simple.

A common call method is treated as a processing value.

public static void main(String[] args){int num = funtion(5);                System.out.println(num);      }    

But read the following code snippet carefully.

public class TestDemo1{        public static int funtion(int x){System.out.println("The funtion has run successfully!");return x;}public static void main(String[] args){funtion(5);}}

Running result:

We can see that the funtion method is successfully called. (I thought this was an incorrect syntax !!!)

Small details that are easy to ignore when learning Java (1 ):

  In Java, a non-void method of the return value type can also be called as a statement.In this case, the call function simply ignores the return value.

(Ps: some bloggers asked me in which language similar function calls will go wrong. To be honest, I have never thought about this problem. I tried C, C ++ and other languages immediately and found that there were really no syntax errors. Here I really felt that I was too easy to learn. I also tried to ask some students, but most of them said, "Should I ask about syntax errors ?". I hope that all those who are familiar with the function calling mechanisms in Java, C, and C ++ languages, like me, will be able to take the lessons they have taken to avoid making mistakes. In this way, my goal is to write a blog .)

Applicable scenarios:

When writing a Java program, if the caller is not interested in the returned value and knows that the call operation will succeed, you can use the above call method. However, it is best to call the method of the return value of the oil as a value to avoid program errors.

 

The above is the small details that are easy to ignore by learning Java (1 ).

You are welcome to continue to pay attention to more new trends of this blog. The blog master QQ: 2584451009. If you have any suggestions or suggestions, please comments or leave a message.

 

 

 

 

 

Related Article

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.