Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 561269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:25:55+00:00 2026-05-13T12:25:55+00:00

Wrapper class are just fine and their purpose is also well understood. But why

  • 0

Wrapper class are just fine and their purpose is also well understood. But why do we omit the primitive type ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:25:56+00:00Added an answer on May 13, 2026 at 12:25 pm

    It depends what you mean by “primitive”

    “Primitive” in Java is usually taken to mean “value type”. However, C# has a string keyword, which acts exactly the same as Java’s String, it’s just highlighted differently by the editor. They are aliases for the classes System.String or java.lang.String. String is not a value type in either language, so in this way it’s not a primitive.

    If by “primitive” you mean built into the language, then String is a primitive. It just uses a capital letter. String literals (those things in quotes) are automatically converted to System.String and + is used for concatenation. So by this token, they (and Arrays) are as primitive as ints, longs, etc.

    First, what is a String?

    String is not a wrapper. String is a reference type, while primitive types are value types. The means that if you have:

    int x = 5;
    int y = x;
    

    The memory of x and y both contain “5”. But with:

    String x = "a";
    String y = x;
    

    The memory of x and y both contain a pointer to the character “a” (and a length, an offset, a ClassInfo pointer, and a monitor). Strings behave like a primitive because they’re immutable, so it’s usually not an issue, however if you, say, used reflection to change the contents of the string (don’t do this!), both x and y would see the change. In fact if you have:

    char[] x = "a".toCharArray();
    char[] y = x;
    x[0] = 'b';
    System.out.println(y[0] == 'b'); // prints "true"
    

    So don’t just use char[] (unless this is the behavior you want, or you’re really trying to reduce memory usage).

    Every Object is a reference type — that means all classes you write, every class in the framework, and even arrays. The only things that are value types are the simple numeric types (int, long, short, byte, float, double, char, bool, etc.)

    Why isn’t String mutable like char[]?

    There are a couple reasons for this, but it mostly comes down to psychology and implementation details:

    • Imagine the chaos you’d have if you passed a string into another function and that function changed it somehow. Or what if it saved it somewhere and changed it in the future? With most reference types, you accept this as part of the type, but the Java developers decided that, at least for strings, they didn’t want users to have to worry about that.
    • Strings can’t be dealt with atomically, meaning multithreading/synchronization would become an issue.
    • String literals (the things you put in your code in quotes) might be immutable at the computer’s level1 (for security reasons). This could be gotten around by copying them all into another part of memory when the program starts up or using copy-on-write, but that’s slow.

    Why don’t we have a value-type version of a string?

    Basically, performance and implementation details, as well as the complexity of having 2 different string types. Other value types have a fixed memory footprint. An int is always 32 bits, a long is always 64 bits, a bool is always 1 bit, etc.2 Among other things, this means that they can be stored on the stack, so that all parameters to a function live in one place. Also, making gigantic copies of strings all over the place would kill performance.

    See also: In C#, why is String a reference type that behaves like a value type?. Refers to .NET, but this is just as applicable in Java.

    1 – In C/C++ and other natively-compiled languages, this is true because they are placed in the code segment of the process, which the OS usually stops you from editing. In Java, this is actually usually untrue, since the JVM loads the class files onto the heap, so you could edit a string there. However, there’s no reason a Java program couldn’t be compiled natively (there are tools which do this), and some architectures (notably some versions of ARM) do directly execute Java bytecode.

    2 – In practice, some of these types are a different size at the machine level. E.x. bools are stored as WORD-size on the stack (32 bits on x86, 64 bits on x64). In classes/arrays they may be treated differently. This is all an implementation detail that’s left up to the JVM — the spec says bools are either true or false and the machine can figure out how to do it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 315k
  • Answers 315k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From your code, I'm guessing TSQL, so here is a… May 13, 2026 at 11:13 pm
  • Editorial Team
    Editorial Team added an answer It sounds like you're probably just missing change notifications on… May 13, 2026 at 11:13 pm
  • Editorial Team
    Editorial Team added an answer Connection pooling keeps the connection alive: http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx May 13, 2026 at 11:13 pm

Related Questions

I think I am very close to assembling an MVC repository correctly but just
I have a feeling I already know the answer people are going to give,
I need to make a large c++ library avaiable for use in .Net languages
When unit testing, it is always hard to know how low down to the
I am working on a site with the current working copy held at: www.OnlineUticaCollege.com/david

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.