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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:26:05+00:00 2026-05-13T10:26:05+00:00

Im coming from PHP world and im so confused about how to think when

  • 0

Im coming from PHP world and im so confused about how to think when you declare objects in java.

so when traditionally you do like this:

 Rectangle rect = new Rectangle();

cause rect is a Rectangle datatype.

According to the java tutorial page a number wrapper class is a subclass to Number.
So its a class but when you instantiate it the tutorial did it like this:

 Integer x;
 x = 12;

Why isn´t it like this like the traditional way:

 Integer x = new Integer(12);
 or
 Integer x = new Integer();

And here is another example:

 String s = new Integer(i).toString();

So here s is a String object. that i get. But you got new Integer(i). Why new? What does it mean here and what happens when it sends ‘i’ to the constructor. Where can i see what the constructor is doing with the parameters in java API?

Many questions, but couldnt find sources on the net explaining it.

  • 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-13T10:26:06+00:00Added an answer on May 13, 2026 at 10:26 am

    Firstly you can just use the primitive types:

    int x = 12;
    double d = 3.3456;
    

    Secondly, you can optionally use the object wrappers for those numbers:

    Integer x = new Integer(12);
    Double d = new Double(3.3456);
    

    Third, if you want the string representation you can do this simply with:

    String s = Integer.toString(12);
    

    or just:

    int x;
    String s = "x = " + x;
    

    or even printf() like syntax:

    int x = 12;
    String s = String.format("x = %d", x);
    

    Lastly, Java since version 5 has supported auto-boxing and unboxing, which may confuse you if you’re not expecting it. For example:

    Integer i = 1234; // autoboxes int to Integer
    

    and

    int i = new Integer(1234); // autounboxes Integer to an int
    

    Just use the primitive types unless you need the Number wrappers. The most common reason to use them is to put them in collections (Lists, etc).

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

Sidebar

Related Questions

My current project is in Rails. Coming from a Symfony (PHP) and Django (Python)
Coming from C++ to Java, the obvious unanswered question is why didn't Java include
Coming from a java background, one of the things I am used to is
I am new to the world of coding, XHTML, CSS and PHP. This is
I'm new to Tomcat, servlets and Spring Web. I'm coming from a PHP background
Coming from PHP I understand the difference in using == verses === in a
I have a pretty nested JSON coming from a ldap_search() call. I would like
Coming from a corporate IT environment, the standard was always creating a class library
Coming from a Classic ASP background, I'm used to multiple forms on a page,
Coming from a background, I'm familiar with GUI editors that do a poor job

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.