JAVA thinking 01

Source: Internet
Author: User

As soon as humans think, God will laugh.

But we will not stop thinking because of God's laughter. Isn't fate in our own hands? Let's just let God fuck.

Well, what is it? Thinking is because we humans have things to solve, so we need to consider ......

Let's start thinking.

Should I be a small boss or a big boss?

First of all, please forgive me for asking such a seemingly secular question. I also know that money is not omnipotent, but it is still a saying: no money is absolutely impossible...

Now, please answer your question: are you willing to be a small boss or a big boss? I guess you must say that you are a big boss? Congratulations! Your JAVA will certainly learn well: in fact, it doesn't matter if you are a small boss. You can still learn JAVA well, because big bosses start from small bosses .)

Story:

Comrade Tang Miao is bored at home after learning the story and wants to start a company.
The procedures were complete and the company started up.

The company was just launched and its scale was small. Comrade Tang Miao had to do many things in person every day:
From morning till night: opening the door, sweeping the floor, official business, accounting, and other services, closing the door-all things are done in one day.

After a while, Comrade Tang Miao found that my boss was so tired that he was very tired and killed.

So Tang Miao decided: I want to become a big boss.
Recruit Secretaries: recruit from the secretaries;
Security recruitment: from security groups;
Accounting recruitment: recruit from the accounting group.

Now, what's the matter? You don't have to do it yourself. You just need to instruct a specific employee to take care of it.

The story is complete! Let's summarize:

Conclusion: There are two ways to do one thing: 1. Do it yourself. 2. Find someone who will do it.

Therefore, we have extracted two concepts:

1. process-oriented (I know how to do things in detail, because I am a small boss and I have to do everything myself)

2. object-oriented (I don't know how to do things, because I am a big boss, as long as I find the specific object to do things, let him do it OK, as long as the result shows me how)

Now, I tell you that JAVA programming is to make you a big boss and calm down.

How can I build a big company?

If the company wants to grow bigger, I cannot do it by myself. I am not omnipotent, but different people will have different things, so, we may wish to divide people in the real world into several categories based on their functions. Each category covers the things that such groups will do, such as security and classification, accounting and other different functions.

[In fact, a complete JAVA Project is a programmer who has made many classes with different functions. When he wants to use the functions of a class, he wants to create a specific object of the class, then let this object implement the function of that class, that's easy. (For example, the entire category has the tea-Serving Function. If you want to drink tea, you need to recruit a specific delegate from the category and then ask her to serve tea.)]

As a result, we can see that there are several steps for the object-oriented approach:

1. First, you must have such a class. This class has one or more functions. [first, you must have a producer class, which has tea ends or more functions.]

2. When you want to use the functions of this class, you must find a specific object of this class. [When you want to settle an account, you must have an accountant. You cannot ask the security guard to settle the account because the security guard is not responsible for accounting.]

3. Finally, when looking for a specific class object, we can tell this object to execute the object class function. [With a secretary, let the Secretary serve tea]

Now, I tell you in professional terms that JAVA programming is a class that programmers develop with one or more different functions. Foreigners call this class.

Now we can start learning JAVA.

Class: contains several functions, which are called classes in Java.
Function: it belongs to a class. The function of the class is called method in JAVA.

Let's write some code:

1. Write a class-(Category class)

Syntax:

 
 
  1. Public class name
  2. {
  3.  
  4. }

For example:

 
 
  1. public calss Mishu  
  2. {  
  3.  

Note:
1. After the class is edited, the file name must be exactly the same as the class name, including the case.
2. The class name must be an English letter with an uppercase letter. Chinese characters and other characters are not allowed.
3. Note that there must be a set of braces after the class name.

2. Write a method (the method belongs to the class, so the method must be written inside the class) (tea-end method)

Syntax:

 
 
  1. Public class name
  2. {
  3. Public void method name ()
  4. {
  5.  
  6. }
  7. }

For example:

 
 
  1. public class Mishu  
  2. {  
  3.      public void duanCha()  
  4.      {  
  5.  
  6.      }  
  7. }  

Note:


1. Naming rules: All letters are used, and the first word is in lowercase, and the first letter is in uppercase.

Now we have written classes and Methods. How can we use a method to complete a function?
For example, if we have an example class and want to recruit a specific secretary from the example class to serve tea, how can we do it?

Look down:

Instance program: (we use two classes for Demonstration: one boss class and one worker class)

I. Category (there is a tea method)

 
 
  1. Public class Mishu
  2. {
  3. Public void duanCha ()
  4. {
  5. System. out. println ("I'm a secretary. I'll serve tea with you ...");
  6. }
  7. }

Note:
When you learn new things, if you cannot understand something, remember it first. I will tell you:
System. out. println ("output content ");
This sentence is used to output the quotation marks to the screen.
That is to say, when you call the Secretary's tea-serving method, this sentence will be output to the screen.

Ii. Boss

 
 
  1. public class Boss  
  2. {  
  3.     public static void main(String [] args)  
  4.     {  
  5.         Mishu ms = new Mishu();  
  6.         ms.duanCha();  
  7.     }  

Note:
Public void main (String [] args) {} method is called as the primary method in JAVA,
Because what we do is to write a program, and what the program is, the program is a step, step by step, and the main method is the first step of all program steps.
The writing of the main method is dead, and it is a provision and cannot be changed.

Mishu MS = new Mishu ();
The purpose of this Code is to recruit employees of a certain class. Here we are looking for employees in the category of recruitment.
Ms is actually a name for this object, called the object name. For example, a new employee gives a employee ID.

Get object syntax (isn't this sentence a bit more appealing ?) :

 
 
  1. Class Name object name = new Class Name ();

Ms. duanCha ();
The role of this Code: Let the object do a function of its class: The method called to execute the object class in JAVA.
Syntax is also in the dead format: Object Name. Method Name ();

If you understand the above content, I can tell you that your JAVA is getting started.

Summary:
1. What is process-oriented and object-oriented?
2. How to Write JAVA classes?
3. How to Write the JAVA method?
4. How do I call methods of a class? Write the code.

Note:

1. Naming rules for JAVA class names: Use nouns whenever possible, and the first letter of each word in a group of compound class names must be capitalized.
2. Naming rules for method names: use the verb + noun method to form a method name, for example, duanCha (). All the first words are in lowercase, and the first letters are in uppercase.
3. In the code in the method, only one sentence is written for each line, and each sentence must be followed by a seal.

This article is from the "Houniter" blog, please be sure to keep this source http://houniter.blog.51cto.com/4600703/805269

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.