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 7952201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:47:23+00:00 2026-06-04T02:47:23+00:00

Are Java non-primitive (object) data types treated in the same way as primitive data

  • 0

Are Java non-primitive (object) data types treated in the same way as primitive data types? By treatment I mean…

1 : Should they be private in the class?

2 : Should they be initialized to some value during the declaration? (e.g. String S = "" instead of String S)

3 : Should they have getters and setters too?

  • 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-06-04T02:47:24+00:00Added an answer on June 4, 2026 at 2:47 am

    The simple answer to all three questions is “yes”. The three practices are sound irrespective of whether the variable in question is of a primitive type.

    One gotcha to be aware of is that, if you have a reference to a mutable object, and your getter returns that reference, this potentially permits the caller to modify the object (which you thought was private to your class!)

    Another difference between the two cases is that object references can be set to null. This can be useful, but can also be a source of errors. It is perhaps worth pointing out here that String s = null and String s = "" are not the same.

    Finally, with objects it is important to understand the difference between obj1 == obj2 and obj1.equals(obj2). This distinction doesn’t arise with primitive types, since there’s only one way to compare them for equality.

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

Sidebar

Related Questions

From what I read about Java NIO and non-blocking [Server]SocketChannels, it should be possible
I have some non well-formed xml (HTML) data in JAVA, I used JAXP Dom,
So in java, say you have a non-static method 'bar()' in an class 'Foo'.
I am looking for a Java regex way of replacing multiple spaces with non-breaking
Just by experiment I discovered that Java non static methods overrides all same named
Is there any way to start non-Java process from Java and then stop it?
Is there any way to customize Java application's title bar? I don't mean app
Is it possible to grab textarea using java from another non-java application? Known way
I am confused about when to use primitive vs. non-primitive(?) types (i.e. int vs.
Possible Duplicate: static in the main class java and non static in constructor i

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.