Java Program to Display Student Information

A school wants to build a simple student information system.

Write a Java program that stores a student’s basic information using appropriate variables and then displays the information in a well-formatted manner.

You store the following information using suitable Java data types in the student information system:

  • Student Name
  • Age
  • Roll Number
  • Percentage
  • Grade
  • Is Student Passed?

Topics Covered: Java Variables and Data Types

Key Concepts

  • Variables: Understanding memory containers for storing data.
  • Primitive Data Types: byte, int, double, char, boolean.
  • Reference Data Types: String class for text handling.
  • Variable Operations:
    • Declaration & Initialization
    • Printing variables using standard and formatted output (System.out.printf)
  • Java Naming Conventions: camelCase naming rules for variable identifiers.

Difficulty Level: Beginner


Input Format

No user input is required. All values must be initialized directly inside the program code.

Example Values:

Name       : Rahul Sharma
Age        : 20
Roll No    : 101
Percentage : 87.5
Grade      : A
Passed     : true

Output Format

Display the student details in a clean, readable format using console output statements.

Expected Output:

Student Information

Name        : Rahul Sharma
Age         : 20
Roll Number : 101
Percentage  : 87.5
Grade       : A
Passed      : true

Constraints

  • Data Types: Use suitable Java data types for every piece of information (e.g., String, byte/int, double, char, boolean).
  • Declarations: Declare each variable separately on its own line.
  • Naming Conventions: Use meaningful, descriptive variable names following Java camelCase conventions (e.g., studentName, rollNumber).
  • Variable Usage: Do not hardcode values directly inside println() or printf() statements. All values must be retrieved from declared variables.
  • Output: Print the actual values stored in the variables alongside appropriate labels.
  • Compilation: The code must be syntactically valid and compile without warnings or errors on modern Java JDKs.

Expected Solution Approach

Step 1: Create a Java class.
↓
Step 2: Define the main() method.
↓
Step 3: Declare variables using appropriate data types.
↓
Step 4: Assign sample values to each variable.
↓
Step 5: Display variable values using the output statement System.out.println().

Why This Approach Works

Each variable stores one specific type of information. For example:

  • Name → String
  • Age → int
  • Percentage → double
  • Grade → char
  • Passed → boolean

Key Takeaway: Choosing the correct data type ensures your program is memory-efficient, type-safe, and easy for other developers to read and maintain.

Complete Java Program

public class StudentInformationSystem {

	public static void main(String[] args) {
		
        // VARIABLE DECLARATIONS AND DATA TYPES

        // String: Used for storing sequences of text/characters (e.g., student full name).
        String studentName = "Rahul Sharma";

        // byte: Used for integer values up to 127; ideal for age to optimize memory.
        byte age = 20;

        // int: Standard 32-bit data type for whole numbers like roll/ID numbers.
        int rollNumber = 101;

        // double: Standard 64-bit floating-point type for fractional numbers with high precision.
        double percentage = 87.5;

        // char: Used for storing a single 16-bit Unicode character (enclosed in single quotes).
        char grade = 'A';

        // boolean: Used to represent truth values; can only hold true or false.
        boolean isPassed = true;

        // FORMATTED DISPLAY OUTPUT

        // Display header box for clean formatting
        System.out.println("     STUDENT INFORMATION SYSTEM         ");
        System.out.println();
        System.out.println("Name        : " + studentName);
        System.out.println("Age         : " + age);
        System.out.println("Roll Number : " + rollNumber);
        System.out.println("Percentage  : " + percentage);
        System.out.println("Grade       : " + grade);
        System.out.println("Passed      : " + isPassed);
    }
}

Expected Output:

    STUDENT INFORMATION SYSTEM         

Name        : Rahul Sharma
Age         : 20
Roll Number : 101
Percentage  : 87.5
Grade       : A
Passed      : true

Code Explanation

Step 1. Class Definition

public class StudentInformation creates a class named StudentInformation. Every standalone Java application requires at least one class wrapper.

Step 2: Main Entry Point

public static void main(String[] args) defines the main() method. The execution of a Java program begins here when the program runs.

Step 3: Storing Textual Data

String studentName = “Rahul Sharma”; creates a reference variable studentName and assigns the value “Rahul Sharma” to it.

Step 4: Storing Whole Numbers (Age)

int age = 20; creates an integer variable to store the age 20.

Step 5: Storing Identification Numbers

int rollNumber = 101; creates a variable of type int and stores the student’s roll number 101 into it.

Step 6: Storing Floating-Point Values

double percentage = 87.5; create a variable named percentage of type double and store the fractional/decimal number 87.5 into it. The data type double is commonly used for percentages, marks, and measurements.

Step 7: Storing Single Characters

char grade = ‘A’; defines a variable named grade of type char and stores a single letter grade, A.

Step 8: Storing Truth Values

boolean isPassed = true; creates a variable named isPassed of type boolean and holds a boolean value true into it. It represents a logical condition.

Step 9: Output and String Concatenation

System.out.println(…) prints text and variable values to the standard output console. The + operator performs string concatenation, which means it joins text with the variable’s value.

Accurate Memory Visual Diagram

After all variables are initialized, the memory conceptually looks like this:

Variable NameData TypeStored Value
studentNameString"Rahul Sharma"
ageint20
rollNumberint101
percentagedouble87.5
gradechar'A'
isPassedbooleantrue

Follow-up Challenge

Modify the program so that:

  1. Instead of assigning values directly, read the student’s details from the keyboard using Scanner.
  2. Add one more variable named collegeName of type String.
  3. Add one more variable named cgpa of type float.
  4. Print all the information in the same formatted output.
  5. Try changing the values and observe how the output changes while the program logic remains the same.
DEEPAK GUPTA

DEEPAK GUPTA

Deepak Gupta is the Founder of Scientech Easy, a Full Stack Developer, and a passionate coding educator with 8+ years of professional experience in Java, Python, web development, and core computer science subjects. With strong expertise in full-stack development, he provides hands-on training in programming languages and in-demand technologies at the Scientech Easy Institute, Dhanbad.

He regularly publishes in-depth tutorials, practical coding examples, and high-quality learning resources for both beginners and working professionals. Every article is carefully researched, technically reviewed, and regularly updated to ensure accuracy, clarity, and real-world relevance, helping learners build job-ready skills with confidence.