The article recommended to you today is about the basic concepts of Java, master these basic concepts are very important to learn J2SE, J2EE, J2ME, also can better understand the essence of Java, beginners should pay attention to!

▶ summary of Java.

Java is currently mainly used for middleware, which handles communication between the client and server. Early practice proved that Java was not suitable for PC application development, and it has been developed for handheld devices, Internet information stations, and in-car computer development. Java differs from other languages in that it provides platform-independent runtime, allowing you to use exactly the same code on Windows, Solaris, and Linux operating systems. Java syntax is similar to C++ syntax, which is easy for C++/C programmers to learn, and Java is completely and thoroughly object-oriented, with a good Garbage Collector mechanism to prevent memory overflow.

The Java whitepaper presents 11 key features of the Java language.

(1)Easy: Java syntax is relatively simple than C++, another aspect is that Java can make software run on a very small machine, basic explanation and class library support size of about 40kb, increase the basic standard library and thread support memory needs to increase 125kb.

(2) distributed: Java with a very powerful TCP/IP protocol family routine library, Java applications can access the remote object through THE URL through the network, due to the emergence of the servlet mechanism, Java programming is very efficient, now many large Web server support servlet.

(3)OO: Object-oriented design is a programming technique that focuses on objects and their interfaces. Its object-oriented and C++ are different in many ways in dealing with multiple inheritance and Java’s primitive class model.

(4) Robust features: Java adopts a safe pointer model to reduce the likelihood of overwriting memory and data crashes.

(5) Security: Java is used to design network and distributed System, which brings new security problems. Java can be used to build anti-virus and anti-attack System. It turns out that Java does a better job of protecting against viruses.

(6) Architecture neutral: Java compilation and its generation architecture neutral object file format can be executed on many processors. This feature is realized by the compiler’s instruction bytecode, which can be interpreted and executed on any machine.

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

(8) Multithreading: Java processing multithreading process is very simple, Java to multithreading implementation to the following operating system or thread procedures to complete. So multithreading is one of the reasons for Java’s popularity as a server-side development language.

(9) Applets and servlets: Programs that can run on web pages are called applets, which require a Java browser. Applets support dynamic web pages, which many other languages cannot.

▶ Basic Concept:

1. In OOP, the only thing that matters is what the interface of the object is. Just like a computer vendor, she doesn’t care what the internal structure of the power supply is, she only cares whether it can provide you with electricity. All programs are composed of certain attributes and behavior objects, different objects access through function calls to complete, all communication between objects are through method calls, through the encapsulation of object data, greatly improve the reuse rate.

2. The most important idea in OOP is classes, which are templates and blueprints for constructing an object from a class, i.e. creating an instance of that class.

  1. Encapsulation: The process of combining data and behavior in a package and hiding the data from the object user. The data in an object is called its instance field.

4. Extending a class to obtain a new class is called inheritance. All classes are derived from the Object root superclass, which is described below.

  1. Object has three main features:

(1) Behavior — Specify what this object can do.

(2) state– the response of the object when the object imposes a method.

(3) Identity — A distinguishing mark between other similar behavior objects. Each object has a unique IndEntity and these three objects interact with each other.

  1. Relationships between classes:

(1) use-a: dependency

(2) HAS-A: aggregation relationship

(3) IS-A: inheritance relationship — example: Class A inherits class B, at this time, class A not only has the method of class B, but also its own method. (Individuality is found in generality)

7. Construct objects using constructors: A constructor is a special method of constructing objects and initializing them.

Example: The constructor of the Data class is called Data

New Data()– constructs a new object and initializes the current time.

Data happyDay =new Data()– Assigns an object to a variable happyday, so that the object can be used more than once. The value returned by new is a reference.

Constructors can have zero, one, or more arguments. The constructor and class have the same name; A class can have multiple constructors; The constructor returns no value; The constructor is always used with the new operator.

8. Overloading: Overloading occurs when multiple methods have the same name but different parameters. The compiler must sort out which method to call.

9. Packages: Java allows you to group one or more classes together into a group, called packages, for easy task organization. Standard Java libraries are divided into many packages. Java.lang java.util Java.net etc., packages are hierarchical, all Java packages are in the Java and Javax package hierarchy.

10. Inheritance idea: Allow you to build new classes from existing classes. When you inherit an existing class, you reuse the methods and fields of that class, and you can add new methods and fields to the new class.

  1. Extension class: The extension class fully embodies the INHERITANCE relationship of IS-A. The form is class (subclass) extends (base class).

  2. Polymorphic: In Java, object variables are polymorphic. Multiple inheritance is not supported in Java.

  3. Dynamic binding: 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: The compiler knows exactly which method to call if the method type is Priavte Static Final.

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

(5) Dynamic binding: an important feature that allows programs to be extensible without recompiling existing code.

  1. Final classes: To prevent others from deriving new classes from your class, this class is not extensible.

  2. Dynamic calls take longer than static calls.

  3. Abstract Class: The class that specifies one or more abstract methods must itself be defined as abstract. Public abstract String getDescripition

17. Every class in Java extends from the Object class.

  1. The equal and toString methods in the Object class.

(1) Equal tests whether one object is equal to another.

(2) toString returns a string representing the object, and almost every class overrides this method to return a correct representation of the current state. (The toString method is an important one.)

  1. General-purpose programming: All values of any class type can be replaced with variables of the same class as Object.

A dynamic ArrayList is a class library defined in the java.uitl package that automatically resists arrays.

  1. Class: The getClass method of the Object class returns an instance of ckass. Classes contained in main are loaded when the program starts. The virtual machine loads all the classes it needs, and each loaded class loads the classes it needs.

22. The Class class provides powerful reflection for writing programs that can dynamically manipulate Java code. This feature is particularly useful for JavaBeans, using reflection Java to support tools VB programmers are used to. The program that analyzes the capabilities of a class is called reflector, and the package in Java that does this is called java.lang.Reflect.

(1). Ability to analyze classes at run time.

(2). Explore class objects at runtime.

(3). Universal array manipulation code.

(4). Provide method objects.

This mechanism is aimed primarily at toolmakers rather than applications and programs.

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

Java.lang.reflect. Field Returns the Field.

Java.reflect. Method Returns the Method.

Java. Lang. Reflect the Constructor return parameter.

Method Pointers: Java has no method Pointers, so passing the address of one method to another can be called later, and interfaces are a better solution.

  1. Interfaces describe what a class should do without specifying how to do it. A class can implement one or more interfaces.

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

To implement an interface, there are two steps:

(1). Declare the specified interface that the class needs to implement.

(2). Provide definitions of all methods in the interface.

Declare that a class implements an interface using the implements keyword

Class ActionB implements Comparable Its ActionB needs to provide CompareTo methods.

A class has only one superclass, but a class can implement multiple interfaces.

An important interface in Java: Cloneable

  1. Interfaces and callbacks. A common pattern for programming is the callback pattern, in which you specify the method to call back on an object when a particular time occurs.

Example: The ActionListener interface listens.

Similar apis are:

ja va.swing.JOptionPane

j ava.swing.Timer

java.awt.Tookit

  1. Clone object: The clone method is an object protection method, which means your code cannot simply call it.

  2. Inner class: The definition of an inner class is a class defined within another inner class.

The reason is:

(1). An object of an inner class can access the implementation of the object that created it, including private data.

(2) inner classes can be hidden from other classes in the same package.

(3). Anonymous inner classes make it easy to define callbacks.

(4). It is very convenient to write event drivers using inner classes.

  1. Proxy class:

(1). Specify that the interface requires all code

(2).object all methods defined (toString equals)

30. Data types: Java is a type oriented language. Every variable must be declared to be typed. Four are integers, two are floating-point, and one is a character, used in Unicode encodings, Boolean.

A programmer learning platform to share with you, so that you accumulate experience in practice to master the principle. The main direction is JAVA engineers. If you want to get a high salary, want to break through the bottleneck, want to compete with others to get an advantage, want to enter BAT but worry about the interview, you can add my Java learning exchange group: 282711949.

Note: Add group requirement

1. I majored in Java in college, but I was frustrated in the interview after graduation and could not find a suitable job

2. I have been in the company for a long time and now I am comfortable, but I hit a wall in the interview when I change my job. Need to study in a short time, job-hopping to get a high salary

3. After attending the offline training, I have not mastered the knowledge deeply enough, and it is difficult to find employment. I want to further my study

4, already in the Java related departments work on the job, on their own career planning is not clear, dawdle

5, have a certain C language foundation, contact with Java development, want to change careers

Do not disturb the trumpet, do not like to add