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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:35:33+00:00 2026-06-14T08:35:33+00:00

I’m doing some processing of images and in my work I use the package

  • 0

I’m doing some processing of images and in my work I use the package java.awt.geom. I am use the class Point. This class extends from Point2D and inherits get methods that return double. Point is meant to be an integer representation of a point.

To access the integer x and y values in Point you need to use publicly accessible variable x and y; My question is

1) Isn’t it bad practice to allow public access to an instance variable? eg. This question

2) Is there a better design of this?

  • 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-14T08:35:34+00:00Added an answer on June 14, 2026 at 8:35 am

    Yes it is bad practice (at least by today’s standards), but there are a few reasons for this…

    1. The super-class Point2D needs to be as generic as possible
    2. Backwards-compatibility
    3. Convenience

    In detail…

    1. The super-class Point2D is a generic object used to represent any kind of point that can be represented in a 2D space. In order to have maximum use as a generic class, the point needs to allow for the highest level of precision possible (ie a double). This is evident by the getX() and getY() methods that return doubles. By using doubles, it allows any sub-class to be compatible with these methods, as a double is the largest primitive java number type with precision, so any sub-class that uses any other primitive numerical variable will always be able to return it as a double without losing any precision.

      You can therefore think of Point as being a simplified version of Point2D, that doesn’t maintain any precision – however it must still conform to the abstract method declarations of the super-class Point2D. An int can be cast into a double directly by the JVM without losing any precision – if Point2D were something other than a double, you would lose some of the precision during the cast. (For example, you couldn’t cast it to a float, as larger int values wouldn’t be able to be directly represented as a float without chopping off some of the higher numbers)

    2. The Point class was introduced in Java 1.0. To maintain backwards compatibility, access to these variables needs to be maintained, even though it may not be best practice. You’ll notice this in other early classes, such as the variable File.separator
    3. Point is a class that is used in a lot of places, and itself is still a pretty generic object. It is much easier/simpler/quicker for programmers to reference an int directly then it is to cast every time you want to get the value (int)getX(). It is also quicker to process by the JVM, as it doesn’t need to convert an int to a double, and then back to an int again.

    If you want a better design, you would probably be best to create additional methods for accessing the int values as ints – ie create the methods getXInt() and getYInt(), and then change the variables back to being non-public (provided you don’t need to retain backwards compatibility).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported

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.