-
string s="a"+"b"+"c"0 or 1 objects were created.
Take string s = abc"The string statement created in this form is stored in the constant pool, so the statement is assigned to the right of the symbol"a"、"b"、"c""are all constants.
If there is a corresponding string in the constant pool, no new string object is created, that is, no space is reallocated in the constant pool. So, if you have previously created in the above form"abc"This string, the statement will no longer create objects.
Instead, it will become after directly presenting the results"abc"。Otherwise, create one in a constant pool"abc", so the statement is created with 0 or 1 objects.
-
There are five in total, four of which are temporary variables that quickly become garbage**.
string s is the name of the object, but it doesn't really assign an address, only a reference, a reference (which is equivalent to a pointer, which is just a number in memory, pointing to the position of "five"), so s is just a name, and does not have a real memory allocation. It's as if a person already exists, and the name is just a name, not the person itself
For example, there are now three people: A, B, and C.
We have to allocate memory space for at least three people, A, B, and C, to store these three objects, and there is no doubt about that.
Now A and B want to join forces to form a class, so we need to build a new memory (class) to define the existence of these two people.
Then C decides to create a larger group and summon both A and B in, so a larger memory needs to be created in memory to be able to hold all three people at the same time.
Finally, after the largest collective is generated, we need to give it a nice name, let's call it an S.
But S is just a name, and there is no need to assign him a classroom.
Finally, bs those classmates who call one, haha, it can't be an object, haha.
You may be able to step aside if you say four.
-
One; Personally, it is understood that it is equivalent to a string merged into a string, which is equivalent to (string s1="abc");
As you can see in the following example, the hashcode value is the same.
public class t
-
I created one.
to the right of the assignment symbol"a"、"b"、"c"、"d"、"e"They are all constants, and for constants, they are stored directly at compile time, not their references, and at compile time, they are directly spoken, and the result of their connection is extracted and becomes"abc"
This statement is equivalent to string s = abc in the class file"
And then when the jvm executes this sentence, it looks in the string pool and if there is no string, it will generate one.
-
I'll explain to you with the following **, I'm using the debug mode to see the id::of the value of these three strings
** As follows: string s = a" +b" +c";
string s1 = abc";
string x = ab";
string s2 = x+"c";
The result of the debug is as follows:
s "abc" (id=44)
count 3
hash 0
offset 0
value (id=50)
0] a1] b
2] cs1 "abc" (id=44)
count 3
hash 0
offset 0
value (id=50)
0] a1] b
2] cx "ab" (id=52)
count 2
hash 0
offset 0
value (id=53)
s2 "abc" (id=59)
count 3
hash 0
offset 0
value (id=60)
The ID of both the value of s and s1 is 53, and the id of the value of S2 is 60
It shows that s and s1 are the same object, and the value of s2 is the same as s and s1, but the address in memory is different. Therefore, s2 is the object that comes out of new.
From this, it is perfectly certain that string s="a"+"b"+"c"It's the same thing as string s = abc".
There is only one object.
-
The answer is to create one.
string s = a" +b" +c" ;
to the right of the assignment symbol"a"、"b"、"c"They are all constants, and for constants, they are stored directly at compile time, not their references, and at compile time, they are directly spoken, and the result of their connection is extracted and becomes"abc"
This statement is equivalent to string s = abc in the class file"
And then when the jvm executes this sentence, it looks in the string pool and if there is no string, it will generate one.
-
Your satisfactory answer is obviously wrong. If you have learned the principle of compilation, you will know. a, b c are all constants, and they are optimized to a constant abc at compile time.
-
Isn't that the same way string s is written?
-
There are 5 objects in total, 4 of which are string objects.
A is a reference, which is a reference object that exists in the stack.
1" is a string object.
2" is also a string object.
1" +2" produces a new string object, new string("12"), and a new string object, so there are a total of 4 string objects, the first three of which are constants of the string type, stored in the stack, and the last new string object is stored in the heap.
-
I think it should be "1" for an object "2" for an object new string("12"One A object adds up to four.
-
One in the heap, it's new.
One in the constant pool, yes"12","1"+"2"The compiler is directly optimized to:"12"Finish.
-
2 pcs. 1, a-value.
A reference address, also known as a reference object.
-
string s=new string("xyz"There are two types of objects:
1.If the string is in the common sense pool, it has already been created"xyz", the creation will not continue, and only one object, new string(, will be created"xyz");
2.If the string is in the common sense pool, it is not created"xyz", two objects are created, one with a value of"xyz", an object new string("xyz")。
-
That's pretty much it.
An xyz string object and a string object are created.
-
There is no such thing as a constant pool, the constant should be added to the final, so if you say so.
string s="xyz";
string s1="xyz";
Then s==s1 is true, I don't think your understanding is very true.
-
Please use equals;
The comparison is the memory address.
-
There are two things to understand about the question of creating objects for strings:
Strings are constants, their values cannot be changed after they are created (final), they can be shared.
string str = "hello";The str in the statement exists in the stack, the string constant object hello exists in the constant pool, and the str in the stack points to the constant hello in the constant pool. When declaring string str2="hello";The first thing to check is whether there is a constant hello in the constant pool, and if it exists, it will not assign a hello, but directly assign the address of the existing object hello to str2 in the stack (this process is the compiler's ization).
The first case:string str = "hello";
Objects are not created in the heap, only in the string pool.
The second scenario:string str1 = new string("hello");
Objects are created in both the heap and the string pool, and only the new objects are in the heap. (If this statement is preceded by the above statement, no object is created in the string pool, only in the heap).
-
In the first question, two objects are created, and since the compiler will merge the ones to the right of the equal sign, he will create one in the constant area"12' string, and then, create an object on the heap called a
Question 2: Log triggers, I don't know the difference, table and view. Tables are stored in the database, and views are some database statements, which do not correspond to the storage of the database.
The table is the inner mode, and the view is the outer mode (I personally think it's a bit of a problem, the table is real, and the view is virtual).
Question 3: If you import a large number of objects into hibernate, you can use VO mode to optimize network traffic.
Question 4: The role of struts is to better reflect the MVC model, you read the book, this thing is not very good, too open.
Topic 5: Spring's IOC, control reversal, the advantage is to maintain the relationships between objects through configuration, rather than letting these relationships be written in **. This minimizes the degree of coupling between objects.
Question 6: Operational steps of a transaction. (start the transaction, run the transaction, end the transaction) and let them as one atom either succeed or fail together.
-
string:
n.Skewer; ropes, straps; filament, plant fibers; [computer science] string;
vt.winding, tuning; Make a line or a series; tie, tie or hang with a thread; Extend or extend.
I don't know what your question means.
-
string
s=newstring("xyz"There are two types of objects:
1.If the string is in the common sense pool, it has already been created"xyz", no further creation will be continued, and only one object new will be created
string("xyz");
2.If the string is in the common sense pool, it is not created"xyz", two objects are created, one with a value of"xyz", an object new
string("xyz")。
I'll give you a very useful suggestion, you give me one.
He has been sending you messages before, he is active, you are passive. >>>More
Dynamically create controls:
for (int i = 0; i < 10; i++)string strname = "textb" + >>>More
What is the method of setting or modifying the properties of an object in VB? >>>More
The answer is 1 4
First, turn all the cos into sin >>>More
The time value of a beat is not fixed. Usually every piece of music will have a mark like "one note = n", which means that n of these notes will be played every minute, and usually such notes marked on it are one beat. >>>More