What is Java?
Java seems to be everywhere - even on TV. Still, it's not easy to tell what Java is and what it can do. People who are new to Java usually have three questions:
What is Java? ?
What can Java do? ?
How does Java change my life? ?
Let’s answer the first question first: What is Java? ?
Java is both a programming language and a platform. ?
Java programming language?
Java is a high-level programming language with the following characteristics:?
Simple?
Object-oriented?
Distributable?
Interpretable?
Robust?
Secure?
Structured?
p>Lightweight?
Powerful?
Multi-threaded?
Dynamic?
Java can be compiled and can be interpreted. A compiler translates a Java program into an intermediate code - called bytecode - that is platform-independent and can be interpreted by the Java interpreter. Through the interpreter, each Java byte instruction is analyzed and then run on the computer. You only need to compile it once and it will be interpreted and executed when the program is running.
As long as there are many tutorials, it is useless to say that you have learned them
These days, there are a lot of Java tutorials on the Internet, and many of us Java babies have read them. They are dazzled and don’t know what to do. I also went through this process back then. I read many teachers’ Java tutorials every day and I felt dizzy after listening to them. Of course, I’m not saying that what they taught was wrong. They were talking about knowledge-based things. That's right, but many teachers who do Java tutorials are not good at explaining things in simple terms and explaining knowledge to us in an easy-to-understand way. What is a good tutorial? A good tutorial is one that makes us feel suddenly enlightened after learning it, instead of not knowing where we are. What I want to say is that if you don’t read this kind of tutorial, it will be a waste of time and confused yourself.
Second, there is a kind of tutorial that can teach you live no matter where you are.
Many tutorials circulating on the Internet are from many years ago and are far from suitable. Nowadays, the needs of new Java applications are basically obsolete products. Many friends find this kind of junk on the Internet and have a great time learning it. They are also drunk. To sum up, many of us cannot learn Java well because we made the wrong choice from the beginning. If we choose incorrectly, our efforts will be in vain. In order to allow the vast number of Java students to learn the essence of Java system knowledge online and understand this knowledge in an easy-to-understand manner, we have decided to teach everyone to learn Java live online every night. Our teachers, ordinary teachers do not need it, we only Let the awesome teacher speak, and you don’t need to pay anything. You just need to come to our group and listen. The first part at the beginning is: 426., the second part in the middle is: 396, and the last part is Yes: 284. There is no excuse for learning. If you want to be strong, you have to work hard. At the same time, this is not an era of going it alone. Everyone is here to learn together and create a new world of Java that belongs to us.
Three 30 basic concepts for beginners in Java
In the process of learning Java, mastering the basic concepts is very important for our learning, whether it is J2SE, J2EE, or J2ME. Importantly, 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:?
At present, Java is mainly used in the development of middleware (middleware)---processing communication technology between clients and servers. Early practice has proved that Java is not suitable for the development of PC applications. Its development has gradually become the development of handheld devices, Internet information stations, and vehicle-mounted computers. The difference between Java and other languages ????is that it provides platform independence when the program is running. It is said that it can be used in The exact same code is used on windows, solaris, linux and other operating systems. Java's syntax is similar to C syntax, which is easy for C/C programmers to master, and Java is completely object-oriented, and a good GC is proposed (Garbage Collector) garbage disposal mechanism to prevent memory overflow. ?
Java’s white paper proposes 11 key characteristics of the Java language. ?
(1)Easy: Java’s syntax is relatively simpler than C’s. Another aspect is that Java can enable software to run on very small machines. The basic explanation is that the size of Java and class library support is about 40kb, adding the basic standard library and thread support requires an additional 125kb of memory. ?
(2) Distributed: Java has a very powerful routine library of the TCP/IP protocol family. Java applications can access remote objects across the network through URLs. Due to the emergence of the servlet mechanism , making Java programming 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 design is very different from C, in terms of handling of multiple inheritance and Java's Original class model. ?
(4) Robust characteristics: Java adopts a safe pointer model, which can reduce the possibility of overwriting memory and data corruption. ?
(5) Security: Java is used to design networks and distribution systems, which brings new security issues. Java can be used to build anti-virus and anti-attack systems. Facts have proved that Java is very effective in anti-virus Excellent job in this aspect.
(6) Neutral architecture: Java compiler generates an architecture-neutral object file format that can be executed on many processors. The instruction bytecode (Javabytecode) generated by the compiler realizes this feature. This word Section code 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 it is very portable. ?
(8) Multi-threading: The process of handling multi-threading in Java is very simple. Java leaves multi-threading implementation to the underlying operating system or thread program. Therefore, multi-threading is the popularity of Java as a server-side development language. One of the reasons. ?
(9) Applet and servlet: Programs that can be executed on web pages are called Applets. There are many browsers that need to support Java, and applets support dynamic web pages, which is something that many other languages ??cannot do. . ?
Basic concepts: ?
1. The only thing that matters in OOP is what the interface of the object is. Just like a computer seller, she doesn’t care what the internal structure of the power supply is, he only Just know whether the relationship can provide you with electricity, that is, you only need to know can or not instead of how and why. All programs are composed of certain attributes and behavior objects. Access to different objects is completed through function calls. Between objects All communication is through method calls, and by encapsulating object data, the reuse rate is greatly improved. ?
2. The most important idea in OOP is classes. Classes are templates and blueprints. Constructing an object from a class means creating an instance of this class.
?
3. Encapsulation: It is the implementation process of combining data and behavior in a package) and hiding the data from object users. The data in an object is called its instance field. ?
4. Obtaining a new class by extending a class is called inheritance, and all classes are extended by the Object root superclass. The root superclass will be introduced below. ?
5. Three main characteristics of objects
behavior---describes what this object can do.?
state---when the object applies methods The reflection of the object.?
Identity---a distinguishing mark from other objects with similar behavior.?
Each object has a unique identity and these three influence each other. ?
6. Relationship between 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 independence)?
7. Construct objects using constructors: The introduction of constructors. Constructors are a special method that constructs objects and initializes 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()---Assign an object to a variable happyday, so that the object can be used multiple times. What is declared here is that the variable and the object variable are different. The value returned by new is a Quote. ?
Constructor features: A constructor can have 0, one or more parameters?
Constructor and class have the same name?
A class Can there be multiple constructors?
Constructors have no return values?
Constructors are always used with the new operator.?
8. Overloading : Overloading occurs when multiple methods have the same name but different parameters. The compiler must pick out which method to call. ?
9. Package (package) Java allows one or more classes to be collected together into a group, called a package, to facilitate the organization of tasks. The standard Java library is divided into many packages.java.lang java .util java, net, etc., the packages are hierarchical. All java packages are within the java and javax package levels. ?
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. At the same time you can add new methods and fields in the new class. ?
11. Extension class: The extension 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. 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 extensible without the need to recompile the existing code.
?
14.final class: To prevent others from deriving new classes from your class, this class is not extensible. ?
15. Dynamic calls take longer than static calls. ?
16. Abstract class: A class that specifies one or more abstract methods must itself be defined as abstract. ?
Example: public abstract string getDescripition?
17. Every class in Java is extended from the Object class. ?
18. The equal and toString methods in the object class. ?
equal is used to test whether one object is equal to another object. ?
toString returns a string representing the object. Almost every class will overload this method in order to return a correct representation of the current state. ?
(The toString method is a very Important method)?
19. Universal programming: All values ??of any class type can be replaced by variables of the same object class. ?
20. Array list: ArrayList dynamic array list is a class library defined in the java.uitl package that can automatically adjust the size of the array. ?
21. The getclass method in the class object class returns an instance of the ckass type. The class included in the main method will be loaded when the program starts. The virtual machine must load all the classes it needs. Each Each loaded class must load the classes it needs. ?
The 22.class class provides powerful reflection functions for writing programs that can dynamically manipulate Java code. This function is particularly useful for JavaBeans. Using reflection Java can support tools that VB programmers are accustomed to using. ?
A program that can analyze class capabilities is called a reflector. The package that provides this function in Java is called Java.lang.reflect. The reflection mechanism is very powerful.?
1. Analysis at runtime class capabilities. ?
2. Exploring class objects at runtime. ?
3. Implement universal 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 inspect the structure of the class. The APIs used are: ?
java.lang.reflect.Field return field.?
java.reflect.Method returns the method.?
java.lang.reflect.Constructor returns the parameter.?
Method pointer: Java does not have a method pointer, put one The address of the method is passed to another method, which can be called later, and interfaces are a better solution. ?
23. Interface (Interface) describes what a 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 requirements of the interface. ?
If you implement an interface, you need 2 steps: ?
1. Declare the specified interface that the class needs to implement. ?
2. Provide definitions for all methods in the interface. ?
To declare that a class implements an interface, you need to use the implements keyword?
class actionB implements Comparable and its actionb needs to provide the CompareTo method. The interface is not a class, and you cannot use new to instantiate an interface. ?
25. A class has only one superclass, but a class can implement multiple interfaces.
An important interface in Java: Cloneable?
26. Interfaces and callbacks. A common pattern in programming is the callback pattern, in which you can specify methods on the callback object when a specific time occurs. . ?
Example: ActionListener interface monitoring.?
Similar APIs include: java.swing.JOptionPane?
java.swing.Timer?
java.awt.Tookit?
27. Object clone: ??The clone method is a protected method of object, which means that your code cannot simply call it. ?
28. Internal class: The definition of an internal class is a class defined inside another. ?
The reasons are: ?
1. An object of an inner class can access the implementation of the object that created it, including private data. ?
2. Internal 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. ?
29. Proxy class (proxy):?
1. All codes required by the specified interface?
2. All methods defined by the object class (toString equals)?
30. Data type: Java is a language that emphasizes types. Each variable must first declare its type. There are a total of 8 basic types in Java, 4 of which are integers. , 2 types are floating point types, one is character type, which is used for characters in Unicode encoding, Boolean type.