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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:31:16+00:00 2026-05-27T22:31:16+00:00

When is it necessary to use the new keyword in Java. I know you

  • 0

When is it necessary to use the new keyword in Java. I know you are supposed to use it when you create an instance of an object like this:

TextView textView = new TextView(this);

Sometimes in code I notice that new isn’t used and I get confused..
In this line of code:

    AssetManager assetManager = getAssets();

Why isn’t an instance of the AssetManager created like this:

AssetManager assetManager = new AssetManager();

then it is set equal to getAssests()?

When should new be used?

  • 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-27T22:31:17+00:00Added an answer on May 27, 2026 at 10:31 pm

    You use the new keyword when an object is being explicitly created for the first time. Then fetching an object using a getter method new is not required because the object already exists in memory, thus does not need to be recreated.

    if you want a more detailed description of new visit the oracle docs

    An object will need the ‘new’ keyword if it is null (which is fancy for not initialized).

    This will always print "needs new" under the current circumstances.

    Object mObj = null;
    if (mObj == null)
        System.out.println("needs new");
    else
        System.out.println("does NOT need new");
    
    OUTPUTS: needs new
    

    So to fix it, you would do something like:

    Object mObj = new Object();
    if (mObj == null)
        System.out.println("needs new");
    else
        System.out.println("does NOT need new");
    OUTPUTS: does NOT need new
    

    And under those circumstances we will always see "does NOT need new"

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

Sidebar

Related Questions

Why is it necessary to use the new keyword when a method shall be
When creating a new outlet in Xcode 4 it enters the necessary code like
Possible Duplicate: Java - when to use 'this' keyword Is it generally good convention
Is it necessary to use Nothing keyword to initialize a DataSet in VB.NET?
Like a tag that I can use to store some necessary info? But really
In C#, how do i create a new webpage that I can either use
Is it necessary to use a period for single sentence notification boxes? Even though
One of the things that seems to be necessary with use of STL is
To prevent SQL injection, is it necessary to use mysql_real_escape_string() , when magic_quotes_gpc is
In a ColdFusion Component (CFC), is it necessary to use fully qualified names for

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.