Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Beginners of Java need to master four core basics.

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

What this article shares with you is that beginners who are introduced to Java need to master four core basics. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Without saying much, follow the editor to have a look.

1 first understand what are the four aspects of Java

It is also essential for beginners to understand these basic concepts of Java, and it is certainly not possible to memorize them by rote, focusing on understanding, understanding the differences and connections between them, and what applications they have. Think about what knowledge points are used in this code. Don't just hit the code according to the book. Without understanding.

The 1.Java programming language, or syntax.

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

The 3.Java virtual machine (JVM), which is the interpreter that processes * .class files.

4.Java Application Program Interface (Java API).

2 master static methods and properties

Static methods and properties are used to describe the characteristics of a group of objects, rather than the characteristics of a single object. Static methods and properties are widely used in Java, which is a common technique. But this technique is not frequently used in many languages.

Understanding static methods and attributes, which are frequently used in a large number of Java specifications, is very helpful in understanding the relationship between classes and objects. Therefore, learners should understand static methods and attributes. Java is consistent in the invocation of methods and properties, except when declared, which is different from C++.

3 beginners also need to understand the relationship between the three technology platforms of JAVA

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

You should 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 compiler program for java will be started. Compiles the .java file with the specified extension. A bytecode file that can be recognized by jvm is generated. That is, the class file, that is, the running program of java.

Java: the part responsible for running. Jvm will be started. Load the class libraries needed for the runtime and execute the class file. For a file to be executed, there must be a starting point for execution, which is the main function.

4 master the basic format of JAVA code

1. Java comments are as comprehensive as possible.

Comments on methods should include detailed input parameters and result descriptions, and exceptions thrown should also be described in detail: comments on classes should include functional descriptions, authors, and modifiers of the class.

2. The same variable used many times had better be reduced to a constant.

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

3. Execute method calls in loops as little as possible

Try to make fewer avoidable method calls in the loop, which can save the creation of the method stack. For example:

For (int iTuno Bandi)

System.out.println (I)

}

Can be modified to:

For (int iMago _ book _ size _ list.size (); I

System.out.println (I)

}

4. The definition of constant can be put into the interface.

In Java, only constants are allowed in the interface, so the keyword public static final can be omitted by declaring constants in the interface.

5. The choice of ArrayList and LinkedList

This problem is quite common. In general, it is best for programmers to be able to evaluate list usage scenarios and then make choices based on features. The underlying ArrayList is implemented using arrays, so randomly reading data is much faster than LinkedList, while LinkedList is implemented using linked lists, adding and deleting data much faster than ArrayList.

6. String,StringBuffer and StringBuilder

This problem is also quite common. When doing string concatenation, String usually produces multiple objects and caches multiple values in a constant pool. For example:

String a = "a"

String b = "b"

A=a+b

In this case, jvm produces three objects: "a", "b" and "ab". And the performance of string concatenation is also very low. Therefore, when you usually need to do string processing, try to use StringBuffer and StringBuilder.

7. The selection of packaging class and basic type

In the code, try to use the basic data type if you can use the basic data type as the local variable type, because the variables of the basic type are stored in the stack and the variables of the wrapper class are in the heap. The stack operates much faster than the heap.

8. Assign unused variable references to null as soon as possible

Doing so helps jvm to reclaim memory faster. Of course, many people are not interested in this practice.

9. Release resources in the finally block

A typical scenario is when using io streams, regardless of whether there is an exception or not, the convection should finally be turned off in finally.

10. When using an Object as a key in HashMap, you should pay attention to how to distinguish whether the Object is the same or not

In the HashMap implementation of jdk, the criterion for determining whether the key 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 in hashmap as different key, override the hashcode and equals methods.

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

It is very important to learn how to describe these data structures for application programming, especially when it comes to server-side and three-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 to do with it, so it should be paid enough attention.

The above are the beginners of Java who need to master the four core basics. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report