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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:15:19+00:00 2026-06-17T04:15:19+00:00

So I just started my second programming class in Java, and this is the

  • 0

So I just started my second programming class in Java, and this is the example given to us by the professor to demonstrate loops and arrays.

public class ArraysLoopsModulus {                       
public static void main(String [ ] commandlineArguments){                   
  //Declare  & Instatiate an Array of 10 integers
  Integer[ ] arrayOf10Integers = new Integer[10];

  //initialize the array to the powers of 2
  Integer powersOf2 = new Integer(1);   
  for(int i=0;i<arrayOf10Integers.length;i++){
    arrayOf10Integers[i] = powersOf2;
    //multiply again by 2
    powersOf2 = powersOf2 * 2;
  }

  //display the powers of 2     
  System.out.println("The first 10 powers of 2 are: ");
  for(int i=0;i<arrayOf10Integers.length;i++){
    System.out.print(arrayOf10Integers[i] + ", ");
  }  
}
}

Having looked through all of the upcoming examples, it seems that my professor never uses primitive data types, he always uses the equivalent object class (in this case Integer instead of int and Integer[] instead of int[]). Also I understand that some situations require the use of objects. My questions are:

What possible reason is there for always using the object? Especially in this simple case when the use of the primitive seems to fit better

Is it a bad habbit to always do this? Should I always use the objects just to make him happy, but know in real life to use the primitive data types when possible

Would this example I gave be considered bad programming?

Thanks

EDIT:
Thanks for all of the great answers, I (a beginner) just needed confirmation that what I was looking at here was not the best way to code.

  • 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-17T04:15:21+00:00Added an answer on June 17, 2026 at 4:15 am

    What possible reason is there for always using the object?

    There is no reason, this code is ugly. Primitives as objects have advantage when using collections, but they are not used in your example.

    Especially in this simple case when the use of the primitive seems to
    fit better

    Absolutley correct, Objects in this case are worse, they need more memory and have no advantage in your example.

    Is it a bad habbit to always do this?

    Yes, you should only use Objects (boxed primitives) if they are needed. Beside use in collections, such object can also be null, this is an advantage which can be used as “value not (yet) existing”, etc.

    Should I always use the objects just to make him happy, but know in
    real life to use the primitive data types when possible

    No, tell him that this makes no sense. But keep in mind, that your professor never wanted to give progarmming lessons. He was probably “forced” to do so.

    Would this example I gave be considered bad programming?

    Yes. maximum bad!

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

Sidebar

Related Questions

I've just started Java programming yesterday (so don't expect too much) and I've written
I just started a new job yesterday and this is only my second job
I've literally just started programming in assembly language this week and I'm having some
I've just started on some raw network programming in C++ and have been compiling
Hi I'm newbie in Programming especially in Database Design. I've just started to work
I just started thinking about using the NHibernate second level cache in one of
I just started programming for Android when my boss asked me to make him
I just started using subclipse for my class projects after a re-writing half of
I just started learning some ruby, and I want to do something like this:
Just getting started with Obj-C and iOS programming. I have some code that loads

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.