How to Learn programming languages?

Source: Internet
Author: User

If you have read this article, please leave a comment. If you have reprinted it, please indicate the source and respect the author's Labor achievements. Thank you!

Many people think that programming languages do not know where to start. It is a headache to learn more and more things. The so-called "love her in the heart is difficult to open", in fact, any programming language learning is a rule to follow, and they all have some commonalities, as long as we master this rule and commonalities, it is easy to learn any programming language. Based on years of training experience, I will take the currently widely used Java language as an example (you can promote it to any programming language). I would like to give you a brief introduction and hope to help beginners!

I. Object-Oriented Programming

The widely used languages are basically object-oriented, so we should first establish the concept of object-oriented. This is at the ideological level. In Java, there is a saying: Everything is an object. It has two main concepts: class and object. A class is an abstract and conceptual concept. It is a blueprint or template of an object and is used to describe an object. The object is specific. It has specific attributes and behaviors, so it is also called an instance.

How can this problem be solved? For example, if a person is a class, then the specific person is John, and the person is the object. Schools are classes. Tsinghua University in China and Peking University are objects. The model of the Ferrari sports car designed by designers is a class, so a Ferrari sports car that can play music and run on the road according to this model is the object. Now we understand that object-oriented programming is actually a class design. If we define a "person" class, people should have attributes such as name, age, gender, and behavior such as eating, sleeping, and walking. After abstracting the description of a person, we can generate a person's object based on the information.

 

II. Operator (operator) operand Data Type

Do you think that the so-called program code simply uses some symbols to perform various operations on some different types of data? Therefore, to learn a language, we must first understand which operators and operands it has, and what types these operands belong. An example of a very simple addition operation in mathematics is 3 + 4. Here 3 and 4 to be operated are the operands, which belong to the integer type. The "+" in the middle is naturally an operator. In the Java statement, this operation indicates: int A = 3 + 4;

The numbers 3 and 4 here are called direct numbers in Java, and A is called a variable in Java. The variables declared in Java must belong to a specific type. Int here refers to the Data Type of the variable. "+" Is an arithmetic operator. We are very familiar with it. What is "=? It is also an operator called the value assignment operator, which is combined in the order from right to left. The above sentence refers to executing addition operations in mathematics on 3 and 4, then assign the result to the variable. Now our operators and operands are combined. They are collectively called expressions in Java. Then, if an expression is followed by a separator ";", it constitutes a statement in Java. That is, a piece of code we call it. Multiple statements are a statement block.

Some may ask why do we need to declare variables? We need to know that the basic function of a program is to process data, and our program uses variables to represent data. After we declare a variable named A above, it represents the arithmetic sum of 3 and 4. In the following code, we can use a as the operand to perform other operations. For example, int B = A * 6;

3. Annotation identifier keyword

The Java language defines three types of annotations that must be provided to program developers in any language:

// Single line comment ---- Comment to the end of the line

/* Single-line or multi-line comment */

/** Single-line or multi-line comments that can be used for docized Processing */

As mentioned above, variables and classes must be identified by names. An identifier is used to name variables, classes, and methods. It has different naming rules in different languages. Identifier in Java: it can start with a letter, underscore "_", or "$". It can start with a letter, underscore "_", or "$; cannot be a keyword

In Java, some words with specific meanings and used for special purposes are called keywords (keyword)

4. Process Control

The execution of program code cannot always be a Sequential stream. Sometimes we need to selectively execute some statement code, and sometimes execute some statement code cyclically. This requires process control. Java flow control statements are divided into two types: branch statements and loop statements.

1. branch statement: implements the program flow control function, that is, to selectively execute or skip specific statements according to certain conditions. Java branch statement classification if-else statement switch statement 2. loop statements are used to control the series of statements that need to be repeatedly executed according to the runtime conditions. The loop statements in Java include for do/while

5. Array set

Most of the time, we operate on a group of elements instead of a single element. In this way, we need to use arrays and collections. An array is used to store a group of data structures of the same data type. A set can also be used to store multiple objects.

Sat. Exception Handling

Do not expect your programs to never go wrong. The exception events that occur during Java program running can be divided into two types: Error: JVM internal errors, resource depletion, and other serious exception (exception ): other general problems caused by programming errors or accidental external factors, such as: Negative open square root NULL pointer access attempts to read nonexistent file network connection interruption

7. System API

We want to speak Chinese well. We generally need to learn some idioms. Similarly, to learn a language well, you must make good use of the APIS provided by the system. Among them, the API (Application Programming Interface) refers to some class libraries provided for you to use. These class libraries are useless. Because they are not described, we still need to conveniently check the API doc at any time.

8. Io stream

We often need to transmit and transfer data, such as outputting data from a program to a standard output device (such as a command line), copying a file, chatting online, etc, i/O Stream is required. Think of data as water. Data is moved from one place to another, just as water flows from the source to the destination.

9. Multithreading

If a restaurant can only allow one customer to eat at a time, I think it will soon collapse. The same is true for programs. If our programs can only provide services to one user at a certain time, it will not work if other users want to get the services. We need to achieve simultaneous access by multiple users. So we should learn about multithreading.

10. Socket network communication

Sometimes we need to do some network-related programs. At this time, we need to learn about the TCP/IP protocol and socket.

11. Database Operations

Currently, most of our data is stored in specialized relational databases. If we want to store data to the database or use the existing data in the database, we need to use the database operations provided by the language.

I outlined the learning curve of a programming language in the rough lines above, and did not mention the principle of language implementation. To sum up, we can first establish an object model that simulates the problem field (the system in the real world simulated by the software system) with the idea of object-oriented, various functions in the software system are jointly implemented by the collaborative work of various objects. Objects are generated by classes. So, in the end, what we often say is to design several classes with code by using an object-oriented programming language. Each class can write attributes and methods (actions ), the method body of a method can write several statements (CODE), and multiple codes can complete certain functions. It is a software!

 

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.