SoFunction
Updated on 2025-03-09

30 basic concepts for beginners in Java

Preface:

In the process of learning Java, mastering the basic concepts is very important for our learning, whether it is J2SE, J2EE, or J2ME. J2SE is the foundation of Java, so it is necessary to summarize the basic concepts so that everyone can better understand the essence of Java in the future learning process. Here I have summarized 30 basic concepts.

Java Overview:

Currently, Java is mainly used in the development of middleware (middleware) - the technology of handling communication between clients and servers. Early practice has proved that Java is not suitable for the development of PC applications, and its development has gradually become the development of handheld devices, Internet information stations, and on-board computers. What makes Java different from other languages ​​is that the program runtime provides platform independence, and it is believed that it can use exactly the same code on other operating systems of Windows, solaris, and Linux. The syntax of Java is similar to C++ syntax, which is easy for C++/C programmers to master, and Java is completely and thoroughly object-oriented, and it is proposed to prevent memory overflow.

Java's white paper proposes 11 key features of the Java language for us.

(1) Easy: Java's syntax is relatively simpler than C++. Another aspect is that Java can enable software to run on very small machines. The basic explanation and the supported size of the class library is about 40kb. To increase the memory supported by the basic standard library and threads requires an increase of 125kb.

(2) Distributed: Java has a very powerful routine library of TCP/IP protocol families. Java applications can access remote objects through the network through URLs. Due to the emergence of the servlet mechanism, Java programming is very efficient. Now many large web servers support servlets.

(3)OO: Object-oriented design is a programming technology that focuses on objects and object interfaces. Its object-oriented and C++ are different from multiple inheritance processing and Java's original model.

(4) Robust Features: Java adopts a secure pointer model, which can reduce the possibility of rewrite memory and data crashes.

(5) Security: Java is used to design network and distribution systems, which brings new security issues. Java can be used to build anti-virus and attack-proof systems. As it turns out, Java has done a better job in anti-virus.

(6) Neutral architecture: Java compiles the architecture-neutral object file format that generates architecture can be executed on many processors. The compiler-generated instruction bytecode (Javabytecode) realizes this feature, and this bytecode can be interpreted and executed on any machine.

(7) Portability: Java has strict regulations on the size and algorithm of basic data structure types, so portability is very good.

(8) Multithreading: The process of Java processing multithreading is very simple. Java handes the multithreading implementation to the operating system or threaded program to complete. Therefore, multithreading is one of the popular reasons why Java is a server-side development language.

(9) Applet and servlet: The program that can be executed on web pages is called Applet, which requires many browsers that support Java, and applet supports dynamic web pages, which is something that many other languages ​​cannot do.

    Basic concepts:

The only relationship in this is what the interface of the object is. Just like a computer seller, she doesn't care about the internal structure of the power supply, she only needs to make a difference if she can provide you with power, that is, just know that can or not instead of how and why. All programs are composed of certain attributes and behavioral objects. Access to different objects is completed through function calls. All communication between objects is done through method calls, and by encapsulating object data, the multiplexing rate is greatly improved.

The most important idea in this is that the class is a template and a blueprint. It constructs an object from the class, that is, creates an instance of this class.

3. Encapsulation: It is the implementation process of combining data and behavior in a package) and hiding data from object users. The data in an object is called its instance field.

4. A new class is obtained by extending a class, and all classes are obtained by extending the Object root superclass. The root superclass will be introduced below.

5. Three main features of the object

behavior---Explanation of what this object can do.
state--Reflection of an object when an object applies a method.
identity---Distinguishing flag from other similar behavior objects.
Each object has a unique indentity and these three influence each other.

6. Relationship between classes:

use-a: Dependency
has-a:Aggregation relationship
is-a :Inheritance relationship--Example: Class A inherits Class B. At this time, Class A not only has Class B methods, but also its own methods. (Personality exists in common)

7. Use constructors to construct objects: The constructor is a special method to construct objects and initialize them.

Example: The constructor of the Data class is called Data

new Data()---Construct a new object and initialize the current time.
Data happyday=new Data()--- Assign an object to a variable happyday, so that the object can be used multiple times. The value to be declared here is that the variable and the object variable are different. The value returned by new is a reference.

Constructor features: The constructor can have 0, one or more parameters
The constructor and class have the same name
A class can have multiple constructors
The constructor has no return value
The constructor is always used with the new operator.

8. Overloading: When multiple methods have the same name and contain different parameters, overloading occurs. The compiler must choose which method to call.

9. Package Java allows one or more classes to be collected together into a group, called packages, to facilitate organization of tasks. The standard Java library is divided into many packages. Java, net, etc. Packages are hierarchical. All Java packages are in the java and javax package hierarchies.

10. Inheritance idea: allows new classes to be built on the basis of existing classes. When you inherit an existing class, you reuse the methods and fields of this class, and at the same time you can add new methods and fields to the new class.

11. Extended class: Extended class fully reflects the inheritance relationship of is-a. The form is: class (subclass) extends (base class).

12. Polymorphism: In java, object variables are polymorphic. However, multiple inheritance is not supported in java.

13. Dynamic binding: the mechanism for calling object methods.

(1) The compiler checks the type and method name of the object declaration.

(2) The compiler checks the parameter type of the method call.

(3) Static binding: If the method type is priavte static final, the compiler will know exactly which method to call.

(4) When the program runs and uses dynamic binding to call a method, the virtual machine must call the method version that matches the actual type of the object pointed to by x.

(5) Dynamic binding: It is a very important feature, which can make the program expandable without recompiling stored code.

Class: To prevent others from deriveing ​​new classes from your class, this class is not extensible.

15. Dynamic calls take longer than static calls.

16. Abstract class: The class that specifies that one or more abstract methods must be defined as abstract.

Example: public abstract string getDescription

Each class in it extends from the Object class.

equal and toString methods in the class.

equal is used to test whether one object is equal to another object.

toString returns a string representing the object, and almost every class overloads the method to return the correct representation of the current state.
(The toString method is a very important method)

19. General Programming: All values ​​of any class type can be replaced by object class variables.

20. Array List: ArrayList dynamic array list, is a class library defined in the package and can automatically adjust the size of the array.

The getclass method in the object class returns an instance of the ckass type. The class contained in the main method will be loaded when the program starts. The virtual machine needs to load all the classes it needs, and each loaded class must load the class it needs.

The class provides powerful functional reflection for programs that can dynamically manipulate Java code. This function is particularly useful for JavaBeans. Using reflection Java can support tools that VB programmers are used to using.

Programs that can analyze class capabilities are called reflectors, and the packages that provide this function in Java are called reflection mechanisms that are very powerful.

1. Ability to analyze classes at runtime.
2. Explore the object of the class at runtime.
3. Implement general array manipulation code.
4. Provide method objects.

This mechanism is mainly aimed at tool users rather than applications and programs.

The most important part of the reflection mechanism is that it allows you to check the structure of the class. The APIs used are:

Returns the field.
Return method.
Returns the parameter.

Method pointer: Java does not have method pointer. Passing the address of one method to another method can be called later, and the interface is a better solution.

23. Interface indicates what the class should do without specifying how to do it. A class can implement one or more interfaces.

24. An interface is not a class, but a set of specifications for classes that meet the interface requirements.

To implement an interface, two steps are required:

1. Declare the specified interface that the class needs to implement.
2. Provide definitions of all methods in the interface.

Declaring a class to implement an interface requires the implementations keyword

class actionB implements Comparable The actionb needs to provide a CompareTo method. The interface is not a class and an interface cannot be instantiated with new.

25. A class has only one superclass, but one class can implement multiple interfaces. An important interface in Java: Cloneable

26. Interface and callback. A common mode for programming is callback mode, in which you can specify the method on the callback object when a specific time occurs.

Example: ActionListener interface listening.
Similar APIs are:

 
 

27. Object clone: ​​The clone method is an object protection method, which means that your code cannot simply call it.

28. Inner class: The definition of an inner class is a class defined inside another.

The reasons are:

1. An internal class object can access the implementation of the object that created it, including private data.

2. For other classes in the same package, internal classes can be hidden.

3. Anonymous internal classes can easily define callbacks.

4. Using internal classes can easily write event drivers.

29. Proxy class (proxy):

1. Specify the interface to require all codes

All methods defined by the class (toString equals)

30. Data type: Java is a language that emphasizes types. Each variable must first declare that it is of type. There are 8 basic types in Java. 4 are integers, 2 are floating-point types, and one is character type, which is used in Unicode encoding and Boolean types.