Essentials of Java programming language Basics __java

Source: Internet
Author: User
Tags finally block stringbuffer java se

Beginners of multiple Java programming do not know what basic knowledge they need to learn when they first touch the Java language program. Here are some of the basics of Java 0 Basics Learning Java programming language. I want to be able to help beginners of the basics of Java programming.

First, understand what is the Java four aspects.

Beginners to understand these basic Java concepts are also essential, rote must not be, emphasis on understanding, understanding the differences between them and the relationship between the application. Think about what the knowledge points are in the code. Don't just hit the code with the book. And not to understand.

Java programming language, or syntax.

Java file format, which is the suffix of various folders and files.

Java Virtual Machine (JVM), an interpreter that processes *.class files.

Java Application Interface (Java API).

You know, Java is divided into two parts: one is compilation, the other is running.

Javac: Responsible for the compiled part, when the javac is executed, the Java compiler program is started. Compiles the. java file for the specified extension. A bytecode file that the JVM can recognize is generated. That is, the class file, which is the Java running program.

Java: The part that is responsible for running. The JVM is started. Loads the class libraries required by the runtime and executes the class file.

A file to be executed must have a starting point for execution, and this starting point is the main function.

Ii. Mastering static Methods and properties

Static methods and properties are used to describe the characteristics of a class of object groups, rather than the characteristics of individual objects. In Java, static methods and properties are applied in large numbers, which is a common technique. But this technique is not used frequently in many languages. Understanding static methods and properties is useful for understanding the relationship between classes and objects, and in a large number of Java specifications, static methods and properties are frequently used. So learners should understand static methods and properties. Java is consistent in the invocation of methods and properties, and the difference is expressed only in the declaration, which is different from C + +.

Third, beginners also need to understand the Java three technical platform of the relationship.

Java is divided into three systems, respectively, Java SE (j2se,java2 Platform Standard Edition, Standard Edition).

Java EE (J2ee,java 2 Platform, Enterprise Edition, Enterprise Edition).

Java ME (J2me,java 2 Platform Micro Edition, Miniature edition).

You know, Java is divided into two parts: one is compilation, the other is running.

Javac: Responsible for the compiled part, when the javac is executed, the Java compiler program is started. Compiles the. java file for the specified extension. A bytecode file that the JVM can recognize is generated. That is, the class file, which is the Java running program.

Java: The part that is responsible for running. The JVM is started. Loads the class libraries required by the runtime and executes the class file.

A file to be executed must have a starting point for execution, and this starting point is the main function.

Four, Master Java code basic format

1. Java annotations as comprehensive as possible

Comments on the method should include detailed arguments and a description of the result, and exceptions thrown in detail: the annotation of the class should contain the functional description of the class, the author, and the person who modified it.

2, the same variable used many times best summed up as a constant

Variables that use the same values in multiple places should be summed up as a constant to facilitate future maintenance.

3, as little as possible in the loop to execute method calls

Try to avoid some avoidable method calls in the loop so that you can save the creation of the method stack. For example:

for (int i=0;i<list.size (); i++) {

System.out.println (i);

}

Can be modified to:

for (int i=0,size=list.size (); i<size;i++) {

System.out.println (i);

}

4, the definition of constants can be put into the mouth

In Java, only constants are allowed in an interface, so declaring a constant in an interface eliminates the public static final keyword.

5, the choice of ArrayList and LinkedList

This problem is more common. It is usually best for programmers to evaluate the use of the list and then make a choice based on the characteristics. ArrayList the bottom is implemented using arrays, so random read data will be much faster than LinkedList, and LinkedList is implemented using a linked list, new and deleted data faster than ArrayList.

6, String,stringbuffer and StringBuilder

This problem is also more common. When string concatenation is done, string typically produces multiple objects and caches multiple values into a constant pool. For example:

String a= "a";

String b= "B";

A=a+b;

In this case, the JVM produces three objects, "a", "B", and "AB". and string concatenation performance is also very low. Therefore, it is often necessary to do string processing as much as possible using StringBuffer and StringBuilder.

7, packaging and basic types of choice

In code, if you can use a basic data type to do a local variable type, use the base data type as much as possible, because the basic type of variable is stored in the stack, the wrapper class is in the heap, and the stack operates much faster than the heap.

8. Assign a variable reference that is no longer used to null as soon as possible

Doing so can help the JVM to reclaim memory faster. Of course, a lot of people actually do not catch a cold in this way.

9, in the finally block to release the resources

A typical scenario is when an IO stream is used, and it should be closed in finally, regardless of whether an exception occurs.

10, when using an object as a key in HashMap, you should pay attention to how to distinguish object is the same

In the JDK HashMap implementation, the criterion for determining whether the two object types are the same is whether the hashcode is the same and the return value of the Equals method. The hashcode and Equals methods should be overwritten if the business needs to store two of the same memory objects as different key stores into HashMap.

The main way Java describes complex data structures is the collection framework. Java has no pointers, but rather a powerful set frame that describes complex data structures such as arrays, object arrays, and so on. The descriptive method of these data structures is very important to the application writing, especially to the server side and the 3-tier structure programming. Programmers can no longer use structures such as database result sets to describe data at this time.

Because many languages do not have such a powerful set frame system, many beginners are overwhelmed, more do not know what to do with, so should arouse enough attention.

Java live public class please add teacher QQ578024144

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.