Look at business in a different perspective-write "composition" in the "Java language"

Source: Internet
Author: User

In the previous period of time in the work of the spare, more systematic and in-depth re-learning Java some technical knowledge.

Recently also tried to apply for a column, the previous period of some of the gains and knowledge points to do a systematic summary review and summary.

Yesterday was also just finished writing about the various basic language elements in Java Summary, always feel that something is missing.


The understanding and use of basic language elements is actually very important.

As the saying goes, all great actions and thoughts originate from a trivial beginning.

For a language, proficiency in the understanding and use of its basic language elements is the "insignificant start"


It can be said that the basic language elements of a language, it is equivalent to a martial arts of the internal strength.

The "internal strength" of their own practice to perfection, the rest, is only the move (drilling) just.

I see people on the Internet to explain the difference between the internal strength and drilling, and feel that it is used to express what I want to say, very fit:

Internal strength is like a bullet, drilling is like a gun.
Everyone will have bullets and guns, but the question is how much and how bad.
The stronger the internal strength, the more bullets; the stronger the drilling, the better the gun.

The relationship between the two is that the internal strength is the basis, decided drilling building.

That corresponds to Java:

Basic language elements are fundamental, and what we do with the so-called "programming" work is actually creating the use of moves through the foundations.


When I first learned Java, I didn't have enough attention to these basic language elements.

Also failed to have a very systematic understanding of the classification of induction, resulting in the total feel a little messy.

Often thinking, how can the concept of these language elements and use of the way, there is a more visual understanding.

Later in the process of gradual deepening, found that:

The work of "programming" is actually very similar to the "composition" work we have experienced in our students ' time.


For example:

   Please take the stand in ... In the doorway of the book to write an article.   requirements: 1. Self-determined.         2. Style is not limited. Can narrative experience, express feelings, make comments, unfold imagination, and so on.         3. Not less than 800 words
What is this? This is a topic of composition.


and

   There is a 1 million-length array, where two numbers are duplicated, use the   Java language to write a fastest algorithm to find the number of repetitions.
What the hell is this? This is a procedural question.


Therefore, it is not difficult to find that the so-called "Composition topic" and "Program topic".

To summarize: In fact, it is a "realization of demand."

For two different needs, the work we do is actually "writing articles"! The difference is that

    • For "Composition topic", we use the language is: Chinese; for "program topic", we use the language is: Java;
    • For articles written in Chinese, we are often referred to as "a composition"; For articles written in the Java language, we are often referred to as "a Java class."


The composition of a composition may usually include:

    • title : Used to make a short summary of the content of the whole essay. For example, every child may have used the title of the composition of "My Father", the purpose is to let the reading people see on the topic know that this composition is descriptive about your father's deeds.
    • person, thing, place : An article naturally relates to the place where the person, thing and thing happened. For example, "My father" in the article, usually have a classic plot: Remember when a child, the night of high fever under the heavy rain, also can not hit the car. Father resolutely braved the rain behind me ran to the hospital. Cloudmonitor Then the people involved are: "I" and "father", the things involved may include: umbrellas, raincoats, etc., the locations involved may include: "Home", hospital, etc.
    • Storyline (paragraph): The storyline may be the largest part of a composition. And also in my father's words, we usually show the father's good to ourselves according to several cases, and each one corresponds to a storyline. And we will describe the plot separately, and the storyline involves what is called "people, things, places."

Similarly, the composition of a Java class typically includes:

    • class declaration: The class name of the Java class is actually the same as the title of the composition. is used to describe the functionality provided by the class that you encapsulate.
    • Variables/constants: Variables and constants are actually "people, things and places" in the composition.
    • Method (function): A method is used to describe the program functionality we want to provide, just as a paragraph is used to describe a storyline. The paragraph refers to " people, things, places ", the method uses the variable/constant defined.

The conversion of my father, the example mentioned above, into the embodiment of a Java class, may allow us to understand more visually:

*/* composition "My father" in Java class embodies */public class Mydad/* declaration:: Composition title */{//variable (constant) used to record the composition of people, things, places//people: private static final String ME = "  I ";p rivate static final String my_dad =" my father ";//object: private static final string raincoat =" raincoat ";//Location: private static final String my_home = "My Home";p rivate static final String HOSPITAL = "Hospital";//function:: Paragraph private static void See_a_patient () {Stringbuil Der SB = new StringBuilder (); Sb.append ("Remember when you were a child, once"); Sb.append (ME);//Use Variable sb.append ("high fever!) The rain outside the window and the car. Extremely urgent, ");        Sb.append (My_dad);        Sb.append ("Hurry up and take out a piece");        Sb.append (raincoat);        Sb.append ("Put on me, carry me, and take me from the Rain");        Sb.append (my_home);        Sb.append ("Sent to");        Sb.append (HOSPITAL);                System.out.println (Sb.tostring ());} public static void Main (string[] args) {see_a_patient ();}}

The output information that the program runs is:

Remember when I was a child, once I had a high fever! The window was raining hard and the car couldn't be hit. Under extreme urgency, my father hurriedly took out a raincoat for me to put on, carry me, the heavy rain took me from my home to the hospital

Please see, we did not write a "composition" In the Java language?

In this, we understand the structure of a Java class by taking the familiar "composition" as the starting point.

So we know that the composition of a Java class is not really complex, and its structure is usually a class declaration, a variable (constant), and a method (function).

The so-called "complex class" is like "a tens of thousands of-word article" principle, nothing more than:

1, related to people, things more = defined variables \ Constants More

2, paragraph more/description of the storyline more = Defined method (more functions)


And the corresponding, take the novel as an example. If the story of an article has reached a certain range of words, it may affect the reading. At this point, we can further "decompose" it.

For example, an autobiographical novel, a person's life can be described in a lot of plot, then it may be built as follows structure:

There were 10 stories to describe their youth deeds, and we extracted them together to form the first of the novel: "My Youth"

There are 10 stories to describe the deeds of the year, and we have extracted them as the second part of the novel: "My middle age".

And so on. Ultimately the sum of this structure is what we call "fiction".


In Java, the same is true. If multiple classes complete the same aspect of the functionality implementation,

Then we can also extract these classes to form a "chapter", the package structure in Java is the "chapter."

The whole program, which is ultimately composed of multiple package structures, is called a complete Java project.


Again, the spectacular high-rise buildings, the basic is also a number of steel concrete built up.

What architects can do is to make the structure of the building more stable, beautiful and practical by means of design.


We talked about the reason why a novel is structured like this. Because when the number of words reached a certain amount of time, it will affect the reading, the theme will be blurred.

So the same is true in Java, which is, to some extent, one of the original intentions of code refactoring. The class should have sufficient functionality to be attributed.


What we are talking about is the structure of the program , but at the same time I would like to focus on the use of basic Java language elements .

But after understanding the structure of the program, it is relatively easier to understand the meaning of the underlying language elements.

Also take the composition as an example, understand the composition structure is necessary. But what we should do is to take the structure as a starting point,

Continue to look at the basic elements of a composition and the basic ingredients, that is: punctuation, words, statements and other things.

Because even if you study the composition of the structure of the deep, if you do not use the text, no punctuation, no writing statements, that all is empty talk.


Similarly, suppose we are going to build a house. Need to know the structure of the house to have a bedroom, kitchen, bathroom, living room.

But just knowing such a structure may be enough to be a designer of a paper drawing of a building's structure, but it's not enough to really build a house.

To successfully build a house, you also need to understand the building elements of the house is material, like cement, steel, some building materials and so on.


So the corresponding to Java, in fact, is the same truth.

And Java provides us with the materials (Basic language elements), including:

identifiers, keywords, comments, constants (variables), operators, expressions, and program statements.


Here we go to the previous "class declarations, variables, methods," The structure of the Java class, the composition analysis:

class declaration = access Modifier keyword + class declaration keyword + class name designator.

Declaration of variable (constant) = access modifier keyword + data type (base data type or object data type) + Assignment operator + value of variable or constant

Declaration of method = access modifier keyword + class/variable/method modifier keyword + return type keyword + method name identifier + method parameter list (local variable)

The content of the method is usually the operation of the data (variables, etc.) by composing "moves" of the operator , expression , program Statement (simple statement and compound statement).

class declaration public/* access Modifier keyword */class/* class declaration keyword */JAVAARTICLESCRAP/* class name identifier */{private/* access modifier keyword */int/* data type */num_1/* variable identifier */=/* Assignment operator */10;private int num_2 = 20;public/* access modifier keyword */static/* static modifier keyword */int/* method return type */getsum/* Method name designator */(int a , int b)/* parameter list (local variable) */{int sum = a + B;//operator, expression, statement, etc. method contents return sum;}}

As a result, we summarize briefly that the writing of a Java program is usually:

According to "Requirements", the use of Java Basic language features (indicators, keywords, comments, constants (variables), operators, expressions, and program statements) to form a "moves."

Write a structure for: topic (class declaration) + person, object, place (variable/constant declaration) + paragraph (method/function) of "composition".


Look at business in a different perspective-write "composition" in the "Java language"

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.