Home >Java >javaTutorial >JAVA Tutorial | Chapter 1 Basic Concepts
To learn JAVA, you must first know what JAVA is, what JAVA can do, and what concepts and features JAVA has. First, let’s start with what JAVA is. Let’s start by taking everyone into the pit:
We mentioned some concepts and features of JAVA in the first two articles. In this article, we will make up for the remaining basic concepts. Of course, the conceptual things of each article I will follow the rhythm and each article will not introduce too many concepts at once.
OOP: Object Oriented Programming, object-oriented programming
##JAVA Three Major Features
JAVA Other basic concepts
First of all, let’s review the history. Many of the original ideas of OOP come from the Simula language, and have been further expanded and re-annotated previous ideas during the improvement and standardization process of the Smalltalk language. It can be said that OO thinking and OOPL develop almost simultaneously and promote each other. Different from the actual computing model that is close to the machine represented by functional-programming and logic-programming, OOP hardly introduces precise mathematical descriptions, but tends to establish An object model can approximately reflect the relationship between entities in an application field. Its essence is a computational model that is closer to a philosophical view used by humans to recognize things. This leads to a natural topic, that is, what exactly is OOP? [D&T 1988][B.S 1991] . In OOP, objects serve as calculation subjects and have their own names, statuses, and interfaces for receiving external messages. In the object model, generating new objects, destroying old objects, sending messages, and responding to messages form the basis of the OOP computing model.
There are two basic ways to generate objects: One is to generate new objects based on prototype objects. One is to generate new objects based on classes. The concept of prototype has been used in cognitive psychology to explain the incremental characteristics of concept learning. The prototype model itself attempts to generate various new objects by providing a representative object as a basis, and This continues to produce objects that are more relevant to practical applications. The prototype-delegation is also an object abstraction in OOP and one of the code sharing mechanisms. A class provides a general description of one or more objects. From a formal point of view, classes are related to types, so a class is equivalent to a collection of instances derived from the class. Such a view will also bring about some contradictions. The typical one is that under the inheritance system, the behavioral compatibility between the subset (subclass) objects and the parent set (parent class) objects may be difficult to achieve. This is It is often quoted in OOP that subtype is not equal to subclass [Budd 2002]. In the context of a world view in which everything is an object, a new object model with metaclasses was born based on the class model. That is, the class itself is also an object of other classes. The above three fundamentally different viewpoints each define three object models based on class (class-based), prototype-based (prototype-based) and metaclass-based (metaclass-based). And these three object models have led to many different programming languages (if we put aside the difference between static and dynamic for the moment). Yes, the C++ and Java we often come into contact with use class-based object models, but in addition, there are many OOPLs that we have no contact with that use completely different object models. They are using another point of view. Interpret the connotation of OOP.
What is the basic idea of oop? Separate the implementation and interface of the component and make the component polymorphic. However, there are fundamental differences between the two. OOP emphasizes the syntax of language elements in program construction. You have to inherit, use classes, use objects, and objects pass messages. GP doesn't care whether you inherit or not. It starts by analyzing the classification of products, what types they are, and how they behave. That is, what does it mean for two things to be equal? How to define the equality operation correctly? It's not just the equality operation. If you analyze it deeper, you will find that the general concept of "equality" means that the two object parts, or at least the basic parts, are equal. Based on this, we can have a universal equality operation. Let’s talk about the type of object. Suppose there is a sequential sequence and a set of operations on the sequential sequence. So what are the semantics of these operations? From a complexity trade-off perspective, what kind of sequential sequence should we provide to the user? What operations exist on this sequence? What kind of ordering do we need? Only after the conceptual classification of these components is clear, can we address the issue of implementation: use templates, inheritance or macros? What languages and technologies are used? The basic point of gp is to classify abstract software components and their behaviors using standard taxonomies. The starting point is to build real, efficient and language-independent algorithms and data structures. Of course, the ultimate carrier is language, and programming is impossible without language. stl uses c++, you can also use ada to implement it, or you can implement it in other languages. The results will be different, but the basic things are the same. Binary searches and sorting are used everywhere, and that's what people are doing. The semantics of containers vary slightly from language to language. But the basic difference is clearly the semantics on which gp depends, and the semantic decomposition. For example, we decide we need a component swap, and then figure out how this component will work in a different language. Obviously the focus is on semantics and semantic classification. What oop emphasizes (I think it is overemphasized) is to clearly define the hierarchical relationship between classes. oop tells you how to establish hierarchical relationships, but does not tell you the essence of these relationships.
(This paragraph is not easy to understand. Some terms may not have appropriate Chinese translations until some time - translator)
The object-oriented programming method OOP was developed in the 1990s A very popular software programming method. It emphasizes the "abstraction", "encapsulation", "inheritance" and "polymorphism" of objects. We talk about programming as consisting of "data structure" + "algorithm". From a macro perspective, objects under OOP are programming-centric and program-oriented objects.
##The above is the concept and comparison chart of the three major features , let’s analyze it:
Java’s syntax is relatively simpler than C++’s. Another aspect is that Java It enables the software to run on a very small machine. The size of the basic explanation and class library support is about 40kb. Adding the basic standard library and thread support requires an increase of 125kb of memory.
OO:Object-oriented design is to focus on A programming technology placed on objects and their interfaces.
1. Abstract: Abstraction is to ignore those aspects of a topic that are irrelevant to the current goal in order to pay more full attention to aspects that are relevant to the current goal. Abstraction does not intend to understand the entire problem, but only selects a part of it, leaving out some details for the time being. ##Abstraction includes two aspects, one is process abstraction, and the other is data abstraction. 2. Inheritance: Inheritance is a hierarchical model that connects classes and allows and encourages the reuse of classes. It provides a way to clearly express commonality. A new class of an object can be derived from an existing class, a process called class inheritance. The new class inherits the characteristics of the original class. The new class is called the derived class (subclass) of the original class, and the original class is called the base of the new class. Class (parent class). A derived class can inherit methods and instance variables from its base class, and the class can modify or add new methods to make it more suitable for special needs. 3. Encapsulation: Encapsulation surrounds the process and data, and access to the data can only be through the defined interface. Object-oriented computing begins with the basic concept that the real world can be represented as a series of completely autonomous, encapsulated objects that Access other objects through a protected interface. 4. Polymorphism: Polymorphism Sexuality refers to allowing objects of different classes to respond to the same message. Polymorphism includes parameterized polymorphism and inclusion polymorphism. Polymorphic language has the advantages of flexibility, abstraction, behavior sharing, and code sharing, and can well solve the problem of application functions with the same name. Summary: There is a very important feature in dynamic binding: the program can be extended without modifying the existing code. So remember that polymorphism is the basis of the open and closed principle.
What is the difference between int and Integer Reference types and primitive types behave completely differently, and they have different semantics. Reference types and primitive types have different characteristics and usages, they include: size and speed issues, in which type of data structure this type is stored, what is specified when reference types and primitive types are used as instance data of a class Default value. The default value for object reference instance variables is null, while the default value for primitive type instance variables depends on their type. Is String the most basic data type? Basic data types include byte, int, char, long, float, double, boolean and short. The java.lang.String class is of final type, so this class cannot be inherited or modified. In order to improve efficiency and save space, we should use the StringBuffer class final class: To prevent others from Derive a new class from your class. This class is not extensible. #Every class in Java extends from the Object class. Abstract class: The class itself that specifies one or more abstract methods must be defined as abstract. Example: public abstract string getDescripition Overloading: When multiple methods have the same name but contain different parameters, overloading occurs. The compiler must Pick out which method to call. Inheritance: Obtaining a new class by extending a class is called inheritance (inheritance), and all classes are extended by the Object root super class However, the root superclass will be introduced below. The 3 main characteristics of JAVA objects 1.ehavior- --Describe what this object can do. #2.tate---The reflection of the object when a method is applied to the object. 3.dentity---a distinguishing mark from other similar behavioral objects. Each object has a unique identity, and these three influence each other. Relationship between JAVA classes: use -a: dependency relationship has-a: aggregation relationship is-a: Inheritance relationship--Example: Class A inherits class B. At this time, class A not only has the methods of class B, but also has its own methods. (Personality exists in commonality) Construct an object using a constructor: the proposal of a constructor, a constructor is a special method, constructor object and initialize it. Example: The constructor of the Data class is called Data New Data()---Construction A new object initialized with the current time. Data dujinyang=new Data()---Assign an object to a variable dujinyang, so that the object can be used multiple times, it must be declared here The variables and object variables are different . The value returned by new is a reference. Constructor features: ##The constructor can have 0, one or more parameters The constructor and the class have the same name A class can have multiple constructors Constructors have no return value Constructors are always used with the new operator Interface ) specifies what a class should do without specifying how to do it. A class can implement one or more interfaces An interface is not a class, but a pair of interfaces that conform to the interface A set of specifications for the required class. If you implement an interface, you need 2 steps: 1) Declare the specification that the class needs to implement interface. 2) Provide definitions of all methods in the interface. ---- To declare a class to implement an interface, you need to use the implements keyword. An interface is not a class, and you cannot use new to instantiate an interface. What is a super class (base class)? What is a derived class? A class has only one super class (base class), but a class can implement multiple interfaces. (Note: An important interface in Java: Cloneable.) What is a base class? In fact, it is the parent class. There are two classes in inheritance, one subclass and one parent class. The base class is equal to the parent class, and the derived class is equal to the subclass. Base class, super class, and parent class all have the same meaning, just different expressions. For example: ##class BaBa{} class A extends BaBa{} This can be said BaBa is the base class of A, BaBa is the super class of A, and BaBa is the parent class of A; in turn, A is the subclass of BaBa, or a derived class. Inner class: An inner class is defined within another class. The reason is: 1) An object of an inner class can access the object that created it Implementation, including private data. 2) Inner classes can be hidden from other classes in the same package. 3) Anonymous inner classes can easily define callbacks. 4) Using internal classes makes it very convenient to write event-driven programs. The above is the JAVA tutorial | Chapter 1 Basic Concepts. For more related content, please pay attention to the PHP Chinese website (www.php.cn)! ##3. Other basic concepts of JAVA
The JAVA platform provides two classes: String and StringBuffer, which can store and operate strings , that is, character data containing multiple characters. The String class provides numerically immutable strings. The string provided by this StringBuffer class is modified. You can use StringBuffer when you know the character data is going to change. Typically, you use StringBuffers to dynamically construct character data.
Java provides two different types: reference types and Primitive types (or built-in types). Int is the primitive data type of java, and Integer is the encapsulation class provided by java for int. Java provides wrapper classes for every primitive type.
Primitive type -->> Encapsulation class
boolean -->> Boolean
char -->> Character
byte -->> Byte
short -->> Short
int -->> Integer
long -->> Long
float -->> Float
double -->> Double