1.
Datatypes, Variables, and Arrays
Assignment 1: Employee Record Manager
Description:
Create a class Employee with fields for id (int), name (String), salary (double), and isActive
(boolean).
Tasks:
Write constructors to initialize all fields.
Write a main method to create an array of 5 Employee objects and assign values via constructor.
Print all the employee details using a loop.
2. Literals, Assignments, and Variables
Assignment 2: Literals and Type Compatibility
Description:
Practice using various literal values and assignments.
Tasks:
Declare variables for all primitive types (byte, short, int, long, float, double, char, boolean) and
assign a proper literal to each.
Print their values to verify correct assignments.
Attempt to assign an incompatible literal (int to boolean, float to int, etc.) and comment on the
resulting compiler error.
3. Literal Values for All Primitive Types
Assignment 3: Primitive Defaults Table
Description:
Display the default values for all primitive datatypes in class fields and local variables.
Tasks:
Declare all primitive types as fields in a class (PrimitiveDefaults).
Inside main, print each field’s value.
Repeat as local variables (ensure to initialize them, observe compile errors otherwise).
4. Using Uninitialized and Unassigned Variables
Assignment 4: Local Variables vs. Fields
Description:
Explore what happens when local variables and class fields are used before assignment.
Tasks:
Declare a local variable without initializing, attempt to print it (expect compiler error).
Declare a field (instance variable) without initialization in a class and print its value in the
constructor (expect default values).
5. Local (Stack) Primitives and Objects
Assignment 5: Stack and Heap
Description:
Observe lifetimes of local variables and objects.
Tasks:
In a method, declare a local primitive and a local reference to a new object.
Call the method several times from main, print a message in the constructor and finalize of the
object (override finalize() method in your object class).
Observe which objects are collected and when.
6. Passing Variables into Methods
Assignment 6: Method Parameter Behavior
Description:
See the impact of passing primitives vs. references.
Tasks:
Write a method that tries to change the value of an int and another that changes an element in an
array.
Call both from main; print variables before/after to demonstrate pass-by-value and mutation of
references.
7. Does Java Use Pass-By-Value Semantics?
Assignment 7: Pass-By-Value Demonstration
Description:
Prove that Java is always pass-by-value, even for objects and arrays.
Tasks:
Pass an object to a method and attempt to reassign it to a new object.
Then, change a field inside the passed object.
Show that the original reference in the calling method remains the same, but its internal state can be
changed.
8. Array Declaration, Construction, Initialization
Assignment 8: Array Creation and Initialization
Description:
Work with various ways to create and initialize arrays.
Tasks:
Declare an integer array of size 10, assign values using a loop.
Create a string array with initial values in a single line.
Initialize a two-dimensional array (matrix) and print it row-wise.
9. Initialization Blocks
Assignment 9: Initialization and Static Blocks
Description:
Explore usage of class and instance initialization blocks.
Tasks:
Create a class with static and instance initialization blocks, set field values and print messages from
each block.
Demonstrate when each block runs by creating multiple objects and comparing output with static
block (runs once) and instance block (runs per object).
10. Challenge Assignment: Mini Student Management System
Description:
Combine topics to build a simple system.
Requirements:
Define a Student class with id, name, marks (array of ints), and a field for the average.
In main, create an array of 3 students, take input for their marks (hard-coded or via Scanner),
calculate averages in a for-loop.
Use a method to print details and grades ('A' for >80, 'B' for >60, else 'C').
Extras: Test Your Understanding
Assignment Concept Practiced Example Task
1 Arrays, object creation Create array of Employee, print details
2 Literals and assignments Assign/test all primitive types
4 Variable initialization Show compile/runtime output with/without init
6, 7 Method param passing Show value vs. object reference change
8 Arrays/multi-dimensional Implement and print a matrix
9 Init blocks Observe run order for static/instance blocks
10 Case study/application Build a multi-feature class with arrays/methods
How to Submit
Create a single Java file per assignment or combine related small demos to a main Practice.java file.
For assignments requiring input, either use Scanner or hardcode data for simplicity.
Test, document, and comment your code for clarity.