View transactions from another perspective and transactions from the Perspective

Source: Internet
Author: User

View transactions from another perspective and transactions from the Perspective

Some time ago, I had to spare some work to learn some technical knowledge about Java more systematically and deeply.

Recently, I tried to apply for a column to systematically review and summarize some of the gains and knowledge points of the previous period.

Yesterday, I just wrote a summary of the various basic language elements in Java, And I always felt that something was missing.


Understanding and using BASIC language elements is actually very important.

As the saying goes, all great actions and thoughts come from a negligible start.

For a language, mastering the understanding and use of its basic language elements is a "negligible start"


It can be said that the basic language elements of a language are equivalent to the internal power of martial arts.

Practice your "internal skills" to perfection. The rest is just a trick (external skills.

On the Internet, I saw the difference between the internal and external functions explained by others. I think it is very suitable for expressing what I want to say:

Internal power is like a bullet, and external power is like a gun.
Everyone will have bullets and guns, but the question is how many and what are the advantages and disadvantages.
The higher the internal strength, the more bullets; The stronger the external strength, the better the gun.

The relationship between the two is that internal work is the foundation and determines the external work building.

Corresponding to Java, it is:

The basic language elements are the foundation, and the so-called "programming" work we do is actually the creation and use of tricks through the Foundation.


When I first learned Java, I never paid enough attention to these basic language elements,

It also failed to have a systematic understanding of classification and induction, resulting in a bit messy thinking.

I often think about how to have a better understanding of the concepts and usage of these language elements.

Later, in the gradual deepening process, we found that:

The "programming" Work is similar to the "Composition" work we have experienced in the student age.


For example:

Please refer to "standing ...... For the question. Requirements: 1. Self-defined. 2. Unlimited style. You can record your experiences, express your feelings, post comments, and expand your imagination. 3. No less than 800 words
What is this? This is an essay question.


And:

There is an array of 1 million length, two of which are repeated. Please use Java to write a fastest algorithm and find the number of duplicates.
What is this? This is a program question.


Therefore, it is not difficult to find the so-called "essay question" and "program question ".

To sum up, it is actually a "implementation requirement.

For two different requirements, what we do is actually "write an article "! The difference is that,

  • For "essay questions", the language we use is Chinese; for "program questions", the language we use is Java;
  • For articles written in Chinese, we are generally referred to as "an essay"; for articles written in Java, we are generally referred to as "a Java class ".


The composition of an essay may usually include:

  • Title: used to give a brief summary of the content in the entire essay. For example, when you are a child, you may have used an essay titled "my father". The purpose is to let the readers know that the essay describes the story of your father.
  • People, things, and places: an article will naturally involve people, things, and places where things happen. For example, in my father's article, there is usually a classic story: I remember when I was a child, I had a high fever and heavy rain at night, and I couldn't get a car. My father ran to the hospital with heavy rain. The people involved here are "I" and "my father". The things involved may include umbrellas and raincoats. The places involved may include "home" and hospitals.
  • Storyline (paragraph): a storyline may be the most important part of an essay. Taking my father as an example, we usually use multiple examples to show how good my father is to ourselves, and each case corresponds to one story. We will describe these plots separately through segmentation, which involves the so-called "people, things, and places ".

Likewise, the composition of a Java class usually includes:

  • Class Declaration: The Class Name of the Java class has the same effect as the "title" of the composition. Describes the functions provided by the encapsulated class.
  • Variable/constant: variables and constants are actually "people, things, and places" in the composition ".
  • Method (function): A method is used to describe the functions of the program we want to provide, just as a paragraph is used to describe the story. The section involves "people, things, and locations", and the Defined variables/constants are used in the method.

The above example of "my father" is converted into a Java class embodiment, which may make us better understand:

/** The essay "my father" uses Java class to reflect */public class MyDad/* class declaration: composition title */{// variable (constant) used to record the people, things, places, and characters in the composition: private static final String ME = "I"; private static final String MY_DAD = "my father"; // things: private static final String RAINCOAT = "RAINCOAT"; // location: private static final String MY_HOME = "my home"; private static final String hosploud = "HOSPITAL"; // function :: section private static void see_a_patient () {StringBuilder sb = new StringBuilder (); sb. app End ("Remember when I was a child, once"); sb. append (ME); // use the variable sb. append ("high fever! There was heavy rain outside the window, and there was no car. In an emergency, "); sb. append (MY_DAD); sb. append ("hurry up with a piece"); sb. append (RAINCOAT); sb. append ("put on for me, carry me back, take me from the heavy rain"); sb. append (MY_HOME); sb. append ("sent"); sb. append (hospend); System. out. println (sb. toString ();} public static void main (String [] args) {see_a_patient ();}}

The output information of the program running is:

I remember when I was a child, I once had a high fever! There was heavy rain outside the window, and there was no car. In an emergency, my father quickly took out a raincoat and put it on my back. in heavy rain, he took me out of my house to the hospital.

Have you read that we did not write an "Essay" in Java?

At this point, we have learned the composition structure of a Java class by taking the familiar "Composition" as the starting point.

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

The so-called "complex class" is like the principle of "A tens of thousands of words Article", nothing more:

1. involved persons and things more = Defined variables \ constants more

2. More paragraphs/more descriptive plots = defined methods (more functions)


Take a novel as an example. If the number of words in an article has reached a certain level, reading may be affected. At this time, we can further "break down" it ".

For example, a self-transmitted novel may describe many plots in a person's life, so it may be constructed into the following structure:

There are ten stories used to describe the stories of young people. We extract and put them together to form the first story: my youth

Ten stories are used to describe the stories of the year, and we extract them as the second story: "My middle age".

And so on. In the end, the sum of this structure is called a novel ".


The same is true in Java. If multiple classes are integrated to implement the same function,

We can also extract these classes to form a "chapter ".Package StructureThis is the "chapter ".

The entire program, which is eventually combined by multiple package structures, is a complete Java project.


Another spectacular high-rise building is simply built by a large number of steel cement.

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


We are talking about the reason for constructing such a novel. It is because when the number of words in an article reaches a certain level, the reading will be affected and the topic will be blurred.

So the same is true in Java. To some extent, this is also one of the original intentions of "code refactoring. Class should have sufficient feature characteristics.


What we mentioned above is:Program StructureBut at the same time I want to focus on the JavaBasic Language Elements.

However, after understanding the program structure, it is easier for us to understand the meaning of basic language elements.

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

Continue to take a deeper look at the basic elements and components of an essay, that is, punctuation marks, words, statements, and so on.

Even if you study the composition structure deeply, if you don't use text, punctuation, or statements, it's all empty talk.


Likewise, let's assume we want to build a house. You need to know the structure of the house, including the bedroom, kitchen, bathroom, and living room.

But simply understanding this structure may be enough to become a designer to draw a structural diagram of a house on paper, but it is not enough for you to build a house.

To successfully build a house, you also need to understand the building components of the House, that is, materials, such as cement, steel bars, and some building materials.


The same is true for Java.

Java provides us with materials (basic language elements), including:

Identifier, keyword, comment, constant (variable), operator, expression, and program statement.


Here, we will analyze the composition of the structure of the Java class "class declaration, variables, and methods" mentioned earlier:

Class declaration = access modifierKeywords+ Class declarationKeywords+ Class nameIdentifier.

Declaration of variable (constant) = access modifierKeywords+ Data type (basic data type or object data type) + value assignmentOperator+ Variable or constant value

Method declaration = access modifierKeywords+ Class/variable/method ModifierKeywords+ Return typeKeywords+ Method nameIdentifier+ Method parameter list (local variable)

The content of the method is usually through:Operator,Expression,Program Statement(Simple statements and compound statements) form a "trick" to complete operations on data (variables, etc.

// 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 */=/* value assignment operator */10; private int num_2 = 20; public/* access modifier keyword */static/* static modifier keyword */int/* method return type */getSum/* method name identifier */(int, int B)/* parameter list (local variable) */{int sum = a + B; // return sum for operators, expressions, statements, and other methods ;}}

Therefore, we can briefly summarize the compilation of a Java program, which is usually:

Based on "requirements", the basic Java language elements (indicators, keywords, comments, constants (variables), operators, expressions, and program statements) are used to form a "trick ".

Write an essay with the following structure: Question (class declaration) + person, thing, location (variable/constant Declaration) + section (method/function ".


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.