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

Java object, operator, control execution flow analysis

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces "Java object, operator, control execution process analysis". In daily operation, I believe that many people have doubts about Java object, operator, control execution flow analysis. Xiaobian consulted all kinds of data and sorted out simple and useful operation methods. I hope it will be helpful to answer the doubts of "Java object, operator, control execution flow analysis". Next, please follow the editor to study!

1. Data can be stored in five different places:

(1) registers: this is the fastest storage area, it is located inside the processor, and its number is so limited that it can be allocated according to demand, and you cannot directly control or perceive its existence (but the C and C++ runs suggest to the compiler how registers should be allocated).

(2) Stack: located in general-purpose RAM (random access memory), but can be directly supported from the processor through the stack pointer. If the stack pointer moves down, new memory is allocated, and if it moves up, memory is freed. This is a fast and efficient method of allocating storage, second only to registers. The Java system must know the life cycle of all items stored in the stack (which limits flexibility) in order to move the stack pointer up and down, and references to the Java object are stored in the stack.

(3) heap: is a memory pool (also located in the RAM area) for storing all Java objects, the compiler does not need to know the survival time of the stored data in the heap (reflecting flexibility), when new an object, it will automatically allocate storage in the heap, using the heap for storage allocation and cleaning will take more time than using the stack.

(4) constant storage: constant values are usually stored directly inside the program code, which is safe because they will never be changed.

(5) non-RAM storage: if the data exists completely outside the program, it can be free from any control of the program and can exist when the program is not running. Such as stream objects and persistent objects, in stream objects, objects are converted into byte streams, in persistent objects, objects are stored on disk, and after the program is terminated, they can still maintain their own state.

two。 For some basic types, especially small, simple variables, Java uses the same method as C # and C++. Instead of new to create variables, it creates an "automatic" variable that is not a reference, which stores the "value" directly and puts it on the stack, so it is more efficient. But these basic types usually also have corresponding wrapper classes and can be reversed (converting the data of the wrapper class to simple variable storage).

3. The high-precision computing class BigInteger supports arbitrary precision integers and BigDecimal supports arbitrary precision fixed points. They get precision at the expense of computing speed.

The 4.Java object does not have the same declaration cycle as the primitive type, and when creating a Java object with new, it can survive outside the scope:

{String s = new String ("a string");}

The reference s disappears at the end of the scope, but the String object entity that s points to continues to occupy memory space, but we cannot access the object after that scope because the only reference to it is out of scope. When Java's garbage collector detects these objects that will no longer be referenced, they free up memory space for other new objects to use.

5. The act of calling a method is often referred to as sending a message to an object.

Int x = a.f ()

The message is f () and the object is a.

Why is there no sizeof () in 6.Java?

In C and C++, the biggest reason to use sizeof () is to "port", different data types may have different sizes on different machines; because Java is built on JRE, all data types are the same size on all machines, no need to use sizeof ().

7. Shift operator:

(1) left shift operator (): moves the Operand on the left side of the operator to the right according to the number of digits specified on the right side of the operator (symbol positive: insert 0 at high bit; negative: insert 1 at high bit)

(3) move the "unsigned" right operator (>):... Insert 0 in the high position

Note:

Shift + equal sign, specify the number of bits to move, for example: K > = 10

5 00010100 changed from 5 to 20

> >: expand 2 ^ k

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

Internet Technology

Wechat

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

12
Report