30 Basic concepts for beginners in Java

Source: Internet
Author: User

30 Basic concepts for beginners in Java
in the course of learning Java, mastering the basic concepts is very important to our study, whether it is J2se,j2ee,j2me, J2SE is the basis of Java, so it is necessary to summarize the basic concepts, So that everyone in the future learning process to better understand the essence of Java, here I summed up 30 basic concepts.
Java Overview:

currently Java is mainly used in the development of middleware (middleware)---processing client-to-server communication technology, early practice proved that Java is not suitable for the development of PC applications, and its development has gradually become in the development of handheld devices, Internet Information stations, and vehicle computer development. Java differs from other languages in that the program runs with the platform's independence, and commends the ability to use the exact same code on windows,solaris,linux other operating systems. Java syntax is similar to C + + syntax, C++/C programmers are easy to master, and Java is completely object-oriented, which presents a good GC (garbage Collector) garbage disposal mechanism to prevent memory overflow.

The Java White Paper presents 11 key attributes of the Java language.

(1) Easy:java syntax is relatively simple than C + +, another aspect is that Java can make the software run on a very small machine, the basic interpretation of its 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 example libraries, Java applications can pass through the network URL to access remote objects, due to the advent of the servlet mechanism to make Java programming very efficient, now many large web The servlet is supported by the server.

(3) OO: Object-oriented design is a programming technique that focuses on the interface of objects and objects. Its object-oriented and C + + have many differences in the processing with multiple inheritance and the original class model of Java.

(4) Robust trait: Java has adopted a secure pointer model that reduces the potential for rewriting memory and data crashes.

(5) Security: Java is designed to design networks and distributed systems, which introduces new security issues that Java can use to build anti-virus and anti-attack system. It turns out that Java is doing a great job with antivirus.

(6) Neutral architecture: Java compiles its generation architecture-neutral target file format can be executed on a number of processors, the compiler-generated instruction bytecode (Javabytecode) implements this feature, and this bytecode can be interpreted and executed on any machine.

(7) Portable: Java has strict requirements for the size and algorithm of the basic data structure type, so portability is good.

(8) Multithreading: Java process of multithreading is very simple, Java to the implementation of multi-threaded to the bottom of the operating system or threading program. So multithreading is one of the popular reasons for Java as a server-side development language.

(9) applets and Servlets: programs that can be executed on a Web page are called applets, many browsers need to support Java, and applets support Dynamic Web pages, which many other languages cannot.

Basic Concepts:

The only relationship in 1.OOP is what the object's interface is, like a computer vendor she doesn't care what the internal structure of the power supply is, he only has the ability to supply you with electricity, that is, just know can or not rather than how and Why. All programs are composed of a certain property and the behavior of the object, the access of different objects through the function call to complete, all communication between objects is through the method call, through the encapsulation object data, greatly improve the reuse rate.

The most important idea in 2.OOP is the class, the class is the template is the blueprint, constructs an object from the class, namely creates an instance of this class (instance).

3. Encapsulation: is to combine data and behavior in a package, and to hide the data for the object user implementation process, the data in an object called his instance field (instance field).

4. By extending a class to obtain a new class called Inheritance (Inheritance), all classes are extended by the object root superclass, and the root superclass is described below.

5.3 main features of the object

Behavior---Explain what this object can do.
State ---The object's reflection when the object imposes a method.
Identity---A distinguishing token from other similar behavior objects.
Each object has a unique indentity and these 3 are affected by each other.

6. Relationships between classes:

use-a: Dependencies
has-a: Aggregation relationship
is-a: Inheritance Relationship--Example: Class A inherits Class B, at which point a class has not only the method of Class B, but also its own method. (Personality exists in commonness)

7. Construct objects using constructors: Constructors are proposed, constructors are a special method of constructing objects and initializing them.

Example: The constructor of the data class is called Data

the new Data ()---Constructs an 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, where the variable to be declared differs from the object variable. The value returned by new is a reference.

constructor Features: Constructors can have 0, one or more parameters
constructors and classes have the same name
A class can have more than one constructor
The constructor has no return value
constructors are always used with the new operator.

8. Overloading: Overloads occur when multiple methods have the same name and have different parameters. The compiler must pick out which method to call.

9. Package Java allows one or more classes to be gathered together as a group, called packages, to facilitate the organization of tasks, and the standard Java library is divided into many packages. Java.lang Java.util java,net and so on, Packages are hierarchical and all Java packages are within the Java and Javax package hierarchy.

10. The idea of inheritance: Allow new classes to be built on top of existing classes, and when you inherit a class that already exists, you reuse the methods and fields of the class, and you can add new methods and fields to the new class.

11. Extension classes: The extended class fully embodies the inheritance of is-a. The form is: Class (subclass) extends (base class).

12. Polymorphism: In Java, the object variable is polymorphic. Multiple inheritance is not supported in Java.

13. Dynamic binding: A mechanism for invoking 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 the static final compiler will know exactly which method to call.

(4) when a program runs and uses dynamic binding to invoke a method, the virtual machine must call the method version that matches the actual type of the object that X points to.

(5) Dynamic binding: It is an important feature that makes the program extensible without the need to recompile the saved 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 prescribes one or more abstract methods must itself be defined as abstract.

Example: Public abstract string Getdescripition

each of the classes in 17.Java is extended from the object class.

the equal and ToString methods in the 18.object class.

equal is used to test whether an 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 substituted with the object class variable.

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

the GetClass method in the 21.class class object class returns an instance of the Ckass type, the class that is contained in the main method is loaded when the program starts, the virtual machines load all the classes that he needs, and each loaded class loads the classes it needs.

The 22.class class provides powerful functional reflection for writing programs that dynamically manipulate Java code, a feature that is particularly useful for JavaBeans, and uses reflective Java to support tools that are used by VB programmers.

A program that can analyze class capabilities is called a reflector, and the package called Java.lang.reflect, which provides this functionality in Java, is very powerful.

1. Ability to parse classes at run time.
2. Probe the object of the class at run time.
3. Implement universal array manipulation code.
4. Provide the method object.

and this mechanism is mainly for the tool and not the application and the program.

The most important part of the reflection mechanism is allowing you to examine the structure of the class. The APIs used are:

Java.lang.reflect.Field returns the field.
Java.reflect.Method Returns the method.
Java.lang.reflect.Constructor returns the parameter.

method Pointers: Java has no method pointers, passes the address of one method to another, can call it later, and the interface is a better solution.

23. The interface (Interface) describes what the class should do without specifying how to do it, and a class can implement one or more Interface.

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

If implementing an interface requires 2 steps:

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

declaring a class implementing an interface requires the use of the Implements keyword

class ACTIONB implements comparable its actionb need to provide a CompareTo method, the interface is not a class, you cannot instantiate an interface with new.

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 of programming is the callback pattern, in which you can specify a method on the callback object when a specific time occurs.

Example: ActionListener interface monitoring.
Similar APIs are: Java.swing.JOptionPane

Java.swing.Timer
Java.awt.Tookit

27. The object Clone:clone method is an object-protected method, which means that your code cannot simply call it.

28. Inner class: The definition of an inner class is a class that is defined within 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. For other classes in the same package, inner classes can be hidden.

3. Anonymous inner classes can easily define callbacks.

4. It is very convenient to write event drivers using an internal class.

29. Agent Class (proxy):

1. Specify that the interface requires all code

all methods defined by the 2.object class (ToString equals)

30. Data type: Java is the language of the emphasis type, each variable must first declare that it is a type, Java has a total of 8 basic types. 4 types are integer, 2 are floating point types, one is character type, is used in Unicode encoding characters, Boolean type.

30 Basic concepts for beginners in Java

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.