Advanced Java programmers: essential knowledge points of Java4 core basics

This article summarizes several basic knowledge points for zero-based learning of the Java programming language. I hope it will be helpful to Java novices who are just getting started.

 

01

First understand what are the four aspects of Java

It is also essential for beginners to understand these basic concepts of Java. Rote memorization is definitely not enough. The emphasis is on understanding, understanding the differences and connections between them, and what applications are there.

 

Think about what knowledge points are used in these codes, don't just type the code according to the book without understanding.

①Java programming language, namely grammar

②Java file format, that is, the suffix of various folders and files

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

④Java application programming interface (Java API)

 

02

Master static methods and properties

Static methods and attributes are used to describe the characteristics of a certain group of objects, rather than the characteristics of a single object. A lot of static methods and properties are used in Java, which is a common technique.

 

But this technique is not used frequently in many languages. Understanding static methods and properties is very helpful for understanding the relationship between classes and objects. In a large number of Java specifications, static methods and properties are frequently used.

 

image

The picture has nothing to do with the content

 

Therefore learners should understand static methods and properties. Java is consistent in calling methods and properties, and the difference is only in the declaration, which is different from C++.

 

03

The relationship between JAVA's three technology platforms

Java is divided into three systems , namely Java SE (J2SE, Java2 Platform Standard Edition, Standard Edition), JavaEE (J2EE, Java 2 Platform, Enterprise Edition, Enterprise Edition), Java ME (J2ME, Java 2 Platform Micro Edition, Micro Edition) Version).

 

You must know that java is divided into two parts : one is to compile and the other is to run.

 

javac: Responsible for the compilation part. When javac is executed, the java compiler program will be started. Compile the .java file with the specified extension, and generate a bytecode file that can be recognized by jvm, which is the class file, which is the running program of java.

java: The part responsible for running will start the jvm to load the class library required at runtime and execute the class file. To be executed, a file must have a starting point for execution, which is the main function.

 

04

Master the basic format of JAVA code

①Java comment as much as possible the whole surface

The comment of the method should include detailed input and result description, and the situation of exception throwing should also be described in detail: the comment of the class should include the function description, author and modifier of the class.

 

②The same variables used multiple times are best summarized into constants

Variables with the same value used in multiple places should be summarized as a constant as much as possible to facilitate future maintenance.

 

③ Perform method calls in the loop as little as possible

Try to make fewer avoidable method calls in the loop, so as to save the creation of method stacks.

E.g:

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);

}

 

④The definition of constant can be put in the interface

In Java, only constants are allowed in interfaces, so the keywords public static final can be omitted by putting constants in the interface declaration.

 

⑤The choice of ArrayList and LinkedList

This problem is relatively common. Generally, it is best for programmers to evaluate the usage scenarios of the list and then make a choice based on the characteristics.

 

The bottom layer of ArrayList is implemented using arrays, so random reading of data is much faster than LinkedList, while LinkedList is implemented using linked lists. The speed of adding and deleting data is much faster than ArrayList.

 

⑥String,StringBuffer和StringBuilder

This problem is also relatively common. When concatenating strings, String usually generates multiple objects, and multiple values ​​are cached in the constant pool.

E.g:

String a=“a”;

String b=“b”;

a=a+b;

 

In this case, jvm will produce three objects "a", "b", and "ab". And the performance of string splicing is also very low. Therefore, StringBuffer and StringBuilder are usually used when string processing is required.

 

⑦The choice of packaging and basic types

In the code, if you can use basic data types for local variable types, try to use basic data types, because basic types of variables are stored in the stack, and packaging variables are in the heap, and the stack operation speed is faster than the heap. a lot of.

 

image

The picture has nothing to do with the content

 

⑧As soon as possible, assign variable references that are no longer used to null

Doing so can help jvm reclaim memory faster. Of course, many people are not cold about this practice.

 

⑨Release resources in the finally block

The typical scenario is when using the io stream, no matter whether there is an exception or not, the stream should be closed in finally.

 

⑩Use an Object as the key in HashMap

In jdk's HashMap implementation, the criterion for judging whether the keys of two Object types are the same is whether the hashcode is the same and the return value of the equals method.

 

If the business needs to store two memory objects with the same data as different keys in the hashmap, the hashcode and equals methods must be overwritten.

 

The main way for Java to describe complex data structures is the collection framework. Java does not have pointers, but uses a powerful collection framework to describe complex data structures such as arrays and object arrays.

 

image

The picture has nothing to do with the content

 

Learning the description methods of these data structures is very important for application programming, especially when it comes to server-side and 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 collection framework system, many beginners are at a loss, let alone what they are used for, so they should attract enough attention.

 

The above is the entire content of this tweet. If your friends also need help, please forward it to TA~

 

At last

I will share with you a wave of Java learning materials. These materials are all Java e-books, study notes, latest learning routes, written examination questions, interview questions, development tools, PDF documents, books and tutorials that I have compiled in the past few years when I have been working on Java. Video courses, Java job application resume templates, Java programmers face and other learning materials are free to share with you. All the materials are in my Java technology qq exchange group: 127522921, there is no routine, please download it by yourself! I bought many of them with money. Welcome everyone to join the group, you can also discuss the technology, welcome to join!

Guess you like

Origin blog.csdn.net/deqing271/article/details/114676139