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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:36:07+00:00 2026-06-14T15:36:07+00:00

I am converting to Java from Javascript (cause of university) and cannot seem to

  • 0

I am converting to Java from Javascript (cause of university) and cannot seem to come around to the logic of array / object assignment.
What I’m trying to achieve is to have something like used to be in Pascal “record” with different variables. This then call in main class and create few instances of that. This is the simple structure I have for example:

class shoppingCart {
    public static void main(String[] args){
        // Define objects
        Product[] products = new Product[3];        

        // Fill in products
        products[0] = {
            title: "Product 1",
            code: "AB432",
            price: 13.60,
            quantity: "dozen"
        }                    
    }
}

class Product {
    public String title;
    public String code;
    public float price;
    public String quantity;
}

Can someone please point me the right way how to create “records” and how to assign values to them? I had the same problem with array in Java before when I declared the variable (array) and later tried

someArray = {23,2,32,523}

and compiler gives me error…

  • 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-14T15:36:08+00:00Added an answer on June 14, 2026 at 3:36 pm

    You need to create an object… ideally without using public fields. For example, if you give your Product class a constructor taking the four values, you can use:

    Product[] products = 
    {
        new Product("Product 1", "AB432", 13.6, "dozen"),
        new Procuct( /* etc */ )
    };
    

    Also note that you shouldn’t use float to store a price. Use BigDecimal instead, or an integer number of cents/pennies/whatever.

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

Sidebar

Related Questions

I'm trying to compile my first legit program that I'm converting from Java (I
Spring MVC + Jackson converting Java object to/from Json data. I want to validate
I am manually converting code from Java (1.6) to C# and finding some difficulty
I'm having an issue converting from Fahrenheit to Celsius in Java. I just started
I'm in the processing of converting a program from Perl to Java. I have
I'm converting some services from Apache SOAP to Axis2, so the Java service classes
Is there a straightforward way of converting a Java SQL Date from format yyyy-MM-dd
Am converting an application from java to objective-c and have run into an issue
I am converting an application from Flex to Javascript. My workflow within Eclipse for
I am manually converting code from Java to C# and struggling with (what 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.