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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:24:07+00:00 2026-05-21T22:24:07+00:00

I’m trying to write a simple program in Java in educational purposes. Basicly you

  • 0

I’m trying to write a simple program in Java in educational purposes.
Basicly you can add students and those grades and after all collect some statistics like average students grade or filtering “good” students apart from “bad” students, etc.
After you run the application in terminal you are able to add student so: -add <name>, add students grade so: -addg <name> <grade>

So I want the application to store student names and list of those grades. The data struture is pretty simple (that is what I want now, at least it seems to be proper structure for this task. It represents simple associative array of arrays in PHP or dictionary of lists in Python):

+---------------------+---------------------+
| String name         | ArrayList grades    |
+---------------------+---------------------+
| String anotherName  | ArrayList grades    |
+---------------------+---------------------+

This would be coded pretty simple in PHP or Python, but in Java I’ve ran into a problem:
I just can’t construct such structure:

$ javac StudentGrades.java
StudentGrades.java:19: variable grades might not have been initialized
                grades.add(5.0f);
                ^
Note: StudentGrades.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

StudentGrades.java:

public class StudentGrades {

    Dictionary studentGrades;

    /**
     * @param args the command line arguments
     */
    public void main(String[] args) {
        //Scanner scanner = new Scanner(System.in);
        ArrayList grades;
        boolean res;
        grades.add(5.0f);
        this.studentGrades.put("Nemoden", grades);
    }

Could you please point me what am I doing wrong and how it should be done properly.
Thank you.

  • 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-21T22:24:08+00:00Added an answer on May 21, 2026 at 10:24 pm

    Instead of ArrayList grades; you’d have to use ArrayList grades = new ArrayList();

    Yet better: ArrayList<Float> grades = new ArrayList<Float>(); //or use Double or Number

    Note that unlike C or C++ creating a variable doesn’t create the object as well.
    In C++ you could imagine your code as ArrayList* grades; i.e. you’d just create the reference/pointer here.

    Additional thoughts:

    1. Dictionary studentGrades; this will be initialized to null.
    2. public void main(String[] args) that’s not a valid main function since it would have to be static
    3. if you have a public static void main(String[] args) you can’t use this since you don’t have an object instance in the static context
    4. You can’t instantiate Dictionary since it is abstract. Use one of its subclasses, e.g. new Hashtable<String, List<Float>>(), or a map, e.g. Map<String, List<Float> dictionary = new HashMap<String, List<Float>>();
    5. Note that local primitive variables are also not initialized, so this could give you an error too: boolean res; In Java only class members are initialized, local variables are not.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.