HackIndia Logo
HackathonsNewsSkillsGrowth
HackIndia LogoContact: +91 9910125804

General

  • Companies
  • Colleges
  • Board of Advisors
  • Brand Ambassadors
  • FAQ
  • Contact
  • Report a Bug

Hackathons

  • Upcoming Hackathons
  • Judges
  • Mentors
  • Partners
  • Participating Colleges

Resources

  • About Us
  • Branding
  • Latest News
  • Growth
  • Skills
  • Ecosystem
  • Forum
  • Ideas
  • Prompt Optimizer
  • How to earn XP

© 2026 HackIndia. All rights reserved.

Privacy PolicyTerms of ServiceCode of ConductSitemap

Build 2.139 · 09 Nov 2026, 10:59 UTC

    HackIndia
    HackathonsNewsInternshipsSkillsGrowth
    OpenJDKWorking towardsJava
    0%

    0 of 10 steps done · +100 XP · +50 SHARP when it is yours

    1. 1Java project worth showing5 min · +10 XP · +5 SHARP
    2. 2Types and collections4 min · +10 XP · +5 SHARP
    3. 3Classes and interfaces5 min · +10 XP · +5 SHARP
    4. 4Generics and exceptions4 min · +10 XP · +5 SHARP
    5. 5Streams and lambdas4 min · +10 XP · +5 SHARP
    6. 6Files and JSON handling4 min · +10 XP · +5 SHARP
    7. 7Maven or Gradle basics4 min · +10 XP · +5 SHARP
    8. 8Submit your public repo4 min · +10 XP · +5 SHARP
    9. The check10 questions, 7 to pass · +10 SHARP
    10. Hand in the taskA project that uses the skill
    11. Skill and certificate+100 XP · +50 SHARP
    Lesson 6 of 8 4 min

    Java

    Files and JSON handling

    • +10 XP for this lesson
    • +100 XP when the skill is proved
    • 4 learning it right now
    In 30 seconds
    • Read recruiter data from files instead of hard-coding it.
    • Store candidates or jobs as JSON that is easy to inspect.
    Handle missing or broken files without crashing blindly.
    Key point

    One rule

    Your CLI should treat files as input, not as your program’s memory. Read data at the edge, convert it into Java objects, then let the rest of your code work with those objects.

    Why JSON here

    For this recruiter project, JSON is a good sample data format. It is readable, common in APIs, and easy for another builder to edit before running your app.

    Use it for things like candidates, jobs, skills, cities, expected salary, or application status. Keep the file small enough to understand in one screen.

    Example

    Sample data file

    Place sample files in a clear folder like data/. Do not hide them inside random package folders.

    Example: data/candidates.json

    [
      {
        "id": 1,
        "name": "Asha Nair",
        "city": "Kochi",
        "skills": ["Java", "SQL", "Git"],
        "expectedSalaryLpa": 6.0
      },
      {
        "id": 2,
        "name": "Rohit Sharma",
        "city": "Pune",
        "skills": ["Java", "Spring", "PostgreSQL"],
        "expectedSalaryLpa": 8.5
      }
    ]

    Reading files safely

    In Java, use Path and Files from java.nio.file for normal file work. They are cleaner than old File code for most CLI apps.

    Start with plain file reading. Then parse the JSON using a library such as Jackson or Gson once your build lesson adds dependencies.

    Example

    Read a JSON file

    This method reads the full file into a String. Your JSON parser can use that string later.

    It also gives a clear error if the file is missing, which is better than a long stack trace during a demo.

    import java.io.IOException;
    import java.nio.file.Files;
    import java.nio.file.Path;
    
    public class JsonFileReader {
        public static String readJson(String filePath) {
            Path path = Path.of(filePath);
    
            if (!Files.exists(path)) {
                throw new IllegalArgumentException("File not found: " + filePath);
            }
    
            try {
                return Files.readString(path);
            } catch (IOException e) {
                throw new RuntimeException("Could not read file: " + filePath, e);
            }
        }
    }
    
    // Usage:
    // String json = JsonFileReader.readJson("data/candidates.json");
    Common mistake

    Avoid hard-coded data

    A common beginner mistake is creating all candidates inside main(). That makes your project look like a coding exercise, not a usable CLI tool.

    Keep two or three sample records in JSON. Let the user pass the file path later, or keep a sensible default like data/candidates.json.

    Tip

    Check AI output

    If you ask an AI tool to create sample JSON, check three things before committing it: valid JSON syntax, realistic field names, and data that matches your Java class names and types.

    For example, do not let one record use expectedSalary and another use expectedSalaryLpa unless your parser is built for that.

    Your to-do

    Do this now

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    Quick check

    0 of 2 right
    1.Your CLI recruiter app needs sample candidates. Where should the data live?
    2.Your app cannot find data/candidates.json during a demo. What should your code do?

    Answer the quick check to finish this lesson.

    ← Lesson 5Skip to lesson 7 →
    OpenJDK
    Working towards
    Java +100 XP

    0 of 8 lessons done · proved by a project that uses the skill

    See the track