Java-1.1 abstract programming process and basic features of java

Source: Internet
Author: User

Java-1.1 abstract programming process and basic features of java

In this chapter, we will briefly discuss the process of object abstraction.

1. All Languages provide abstract mechanisms.

For example: a = 1 (The following are examples. The content mentioned in this example may be incorrect, because I have never learned machine code and Assembly)

Among the machine codes: 1000100111011000

In Assembly: mov a, 1

In C: a = 1

In java:

 

class Test(){   a=1;}

From the above different representations, we can find that the language is constantly being abstracted, from the first 0 and 1 to the creation of an object in java and then assigning values to the object, is a process of continuous image extraction.

 

At the same time, it is also a manifestation of the programming language's efforts to associate the problem space (actual business) with the solution space (computer.

Explanation:

1. in the era of machine code, it is very difficult to directly connect the actual business with the computer. You can see that the simple operation of a = 1 is a large segment of 0 and 1. Who can remember, of course, remember that all of them are strong people.

2. in the era of assembly, the programming language has been improved and the first abstraction is made. 0 and 1 are abstracted into some sentences. a simple sentence can be used to describe a = 1, however, due to the limited degree of abstraction, programming complexity is still relatively high.

3. In the C language era, we can say that abstraction has made a leap. C language can basically handle daily problems and has excellent performance.

4. In the java era, oop was proposed to make the actual business description more consistent with that of the computer solution.

Summary:

The performance is getting lower and lower in the four eras, but the readability is getting higher and higher. Today, unless it is a high-concurrency Internet Enterprise, performance is generally not the biggest problem, and the bottleneck is on people. Therefore, now readability is more important.

 

2. Basic Features of java

1) Everything is an object.

An object is a strange variable. It can store data or perform operations. We can abstract the component of the problem to form a program.

For example, a dog named "jack" is called.

 

class Dog(){  private String name;  private String id;    public void bark(){  }}
We create a dog object, and the dog has a property "name", and it will be called, so there is a method "bark"

 

In the target dog, you can either store the name of the dog or execute the method called by the dog.

 

2) programs are a collection of objects. They send messages to each other to tell each other what to do (to put it bluntly, they call the object method ).

 

package com.ray.ch01;public class Test {public static void main(String[] args) {Dog dog = new Dog();dog.setName(jack);dog.bark();}}class Dog {private String name;public void bark() {System.out.println(name +  is barking);}public String getName() {return name;}public void setName(String name) {this.name = name;}}

In the above program, dog. bark () is the bark method of the Dog object.

 

 

3) each object is stored by other objects.

 

package com.ray.ch01;import java.util.ArrayList;public class GroupOfDogs {private ArrayList
 
   catList;private void initCatList() {for (int i = 0; i < 5; i++) {Cat cat = new Cat();cat.setName(rose + i);catList.add(cat);}}public static void main(String[] args) {new GroupOfDogs().initCatList();}}class Cat {private String name;public void bark() {System.out.println(name +  is barking);}public String getName() {return name;}public void setName(String name) {this.name = name;}}
 

The code above shows that, especially the private ArrayList CatList, which is stored by other objects.

 

 

4) each object has a type.

 

package com.ray.ch01;public class Bird {public static void main(String[] args) {Bird bird = new Bird();}}

In the code above, bird is an object, and its type is Bird. At the same time, bird is also an instance of the Bird type.

 

 

5) a specific type of object can receive the same message.

 

package com.ray.ch01;public class Bird {private void say() {}public static void main(String[] args) {Bird bird1 = new Bird();bird1.say();Bird bird2 = new Bird();bird2.say();}}


The code above creates two different objects, bird1 and bird2, which are of the same type, so they can receive the same information, that is, when I need to call the say method in the Bird type, both bird1 and bird2 can be called.

 

 

Finally, an object has independent storage, methods, and identifiers. In jvm, each object is independent and has a unique id.

 

This section briefly introduces the abstract process of programming languages and the five basic features of java.

 

This chapter is here. Thank you.

 

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.