Question

Can you explain the internal storage for string, in particular string literals, instances of string, and...

Can you explain the internal storage for string, in particular string literals, instances of string, and characters.

Also, if two string variables have the same data, is the memory reference the same?

String a = "test";

String b = "test";

will a and b both have the same memory address?

Homework Answers

Answer #1

The strings are used to store the sequence of the character in any programming language. They are treated as an object. The string is immutable like an array function. Whenever there is a need to make a change he entirely new string is created.

Strings are stored in the string constant pool in a separate memory location. It is a block of the memory that holds the string variables in the heap area.

Example:

String a=” test”;

String b=” test” ;

Whenever the same name object is created it will not create a new object it will only refer to that.  

A "string literal" is a series of characters stored in double quotation marks (") from a source character list. String literals are used to represent a series of characters that form a null-terminated string, taken together.

Where string literals are stored:

Whenever you create a string object with a literal string, that object is stored in the constant string pool, and when you create a string object with a new keyword, that object is stored in the memory of the heap. When you build string objects, for example, as below, they are stored in the String Constant Pool.

Character:

In programming languages, the type of data used to store characters is char. Characters are interpreted in programming languages using Unicode. Unicode is a foreign character range that describes all characters. The char extends from 0 to 65,535.

We will use java language to conclude our result

String a = "test";

String b = "test";

System.out.println(s1== s2);

This gives results true they will have the same memory reference because of a and b point to the same object. As they both have the same name discussed using the diagram.

Conclusion after solving:

  1. Java tests whether or not a string exists.
  2. If we create a second-string object using a new one and have different content, then it creates an object and assigns a different reference
  3. If we do not create an object using a new one and have the same content, it assigns the same reference as the first string.

Yeah, two or more references may both reference the same thing, e.g. from parameters and/or local variables and/or instance variables and/or static variables.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Research and Discuss variables and data types. 1. What are the various data types you can...
Research and Discuss variables and data types. 1. What are the various data types you can use in C#, Explain memory sizes of these data types? 2. Discuss string variables. What does a string variable provide? Provide details. 3. Provide examples how you would create a values like "Sarah", 2, 3.50, and store into memory. For example, DataType VariableName = "Sarah".
Can you please explain what information will be needed for socket based communication? Can you please...
Can you please explain what information will be needed for socket based communication? Can you please describe the ONE of the following? a. interrupt procedure; b. how system call parameters are transferred; c. how system call API are provided to users Can you please explain how the boot process overcome ONE of the following obstacles? a. Where to find the OS installed on the storage b. How control flow is transferred from firmware to software c. Missing drivers d. Real...
You are part of a quality control team for a factory that manufactures high-quality string for...
You are part of a quality control team for a factory that manufactures high-quality string for special purposes. To make sure the strings are all made to the same high standard, you have decided to make a test facility that measures the harmonic frequencies (the frequencies that create standing waves) of the strings as a function of their tension. You decide that the best way do this is to set up a pattern of standing waves at known tensions. Questions:...
no need to explain. True or False 1. A constructor is a special Class member method....
no need to explain. True or False 1. A constructor is a special Class member method. It is automatically called when an object of the class is created. It can also be called more than once after the object is created. 2. In Java, the new operator is used to create an instance/object of a class in the heap. 3. A reference variable is a memory location contains an address of an object stored in the stack. 4. Encapsulation and...
In Python: This will require you to write several functions, and then use them in a...
In Python: This will require you to write several functions, and then use them in a program. Logical Calculator The logical calculator does math, but with logical operators. In logic, we represent a bit with 0 as false and a bit with 1 as true. The logical operators are NOT, AND and OR. Bitwise logical calculations operate on each bit of the input. The NOT operator works on just one three-bit argument. NOT 011 = 100 The AND operator works...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
1.One-way ANOVA can be applied to: a)Regression model with several dummy variables (created for a qualitative...
1.One-way ANOVA can be applied to: a)Regression model with several dummy variables (created for a qualitative independent variable) to test the overall usefulness of the model b)Regression model with several quantitative independent variables to test the overall usefulness of the model c)Both of the above D) none of the above 2. You need to decide whether you should invest in a particular stock.  You would like to invest if the price is likely to rise in the long run.  Assuming the past...
A particular system is found to obey the following two equations of state: T= 3As2/v P=As3/v2...
A particular system is found to obey the following two equations of state: T= 3As2/v P=As3/v2 where A is a constant. a. Find the fundamental equation of this system by direct integration of its molar total differential form: du(s,v)=Tds - Pdv . (This is an integration over multiple variables, but the variables are not independent of each other. Your solution will have only one term, not two.) b. Find the chemical potential \mu as a function of s and v...
Johaan Sri believes that his new drug Krnili-alpha can enhance memory performance in elementary school children....
Johaan Sri believes that his new drug Krnili-alpha can enhance memory performance in elementary school children. He has gained access to the local school system and appropriate permissions to conduct a study which would allow him to test the memory of these children with and without the drug. For each child he records the number of facts the student recalls with the drug and without the drug (repeated measures design). If he uses a sign test, explain the two one-tailed...