Skip to main content
CMP175
Unit 2 of 8
9 Hours

Basic Java

9 topics18 videos17 assignments
2.1

Introduction to Java: Features of Java

LecturePractical1 assignment

Assignment

Set Up Java Development Environment (JDK 21 + VS Code)

Assignment BriefDue: Complete before Topic 2.2 (JVM, Parts of Java Program, Naming Conventions)

Set Up Java Development Environment (JDK 21 + VS Code)

Install JDK 21 and Visual Studio Code, then verify Java works by running both `java -version` and `javac -version` in your terminal.

2.2

JVM, Parts of Java Program, Naming Conventions

LecturePractical2 assignments

Assignment 1

Importance of Java Virtual Machine (JVM)

Assignment BriefDue: Complete before Topic 2.3 (Variables and Constants)

Importance of Java Virtual Machine (JVM)

List the advantages of using the Java Virtual Machine. Explain how JVM contributes to Java's platform independence and security features.

Assignment 2

Explain Naming Conventions in Java

Assignment BriefDue: Complete before Topic 2.3 (Variables and Constants)

Explain Naming Conventions in Java

Describe the standard naming conventions for classes, methods, variables, and constants in Java. Provide examples of each.

2.3

Variables and Constants

LecturePractical2 assignments

Assignment 1

Variables in Java

Assignment BriefDue: Complete before Topic 2.4 (Data Types in Java)

Variables in Java

Define a variable in Java and explain the three types: local, instance, and static variables. Write a single Java program that demonstrates all three types with appropriate output.

Assignment 2

Constants in Java

Assignment BriefDue: Complete before Topic 2.4 (Data Types in Java)

Constants in Java

Explain what a constant is in Java and how it is declared using the final keyword. Write a program that declares constants for PI (3.14159) and MAX_SPEED (120), uses them in a calculation, and attempts to reassign one — then explain what error occurs and why.

2.4

Data Types in Java

LecturePractical2 assignments

Assignment 1

Primitive Data Types in Java

Assignment BriefDue: Complete before Topic 2.5 (Operators in Java)

Primitive Data Types in Java

List all eight primitive data types in Java with their size in bytes and value range. Write a Java program that declares one variable of each type, assigns a valid value, and prints each variable with a descriptive label.

Assignment 2

Type Casting in Java

Assignment BriefDue: Complete before Topic 2.5 (Operators in Java)

Type Casting in Java

Research and explain the concept of type casting in Java. What is the difference between widening and narrowing conversion? List two real-world scenarios where each type of casting would be used. No coding required — write your answer in your own words.

2.5

Operators in Java

LecturePractical1 assignment

Assignment

Operator Categories and Examples

Assignment BriefDue: Complete before Topic 2.6 (Reading and Displaying Output)

Operator Categories and Examples

Write brief notes on arithmetic, relational, logical, assignment, unary, and ternary operators in Java. For each category, provide at least two operator symbols and one short example expression.

2.6

Reading and Displaying Output

LecturePractical3 assignments

Assignment 1

Console Output Practice with println, print, and printf

Assignment BriefDue: Complete before Topic 2.7 (Command Line Arguments)

Console Output Practice with println, print, and printf

Write a Java program that displays your name, program, semester, and a formatted marks table using print, println, and printf. Use printf formatting for aligned columns and two decimal places where needed.

Assignment 2

User Input with Scanner

Assignment BriefDue: Complete before Topic 2.7 (Command Line Arguments)

User Input with Scanner

Create a Java program that reads student name, age, and three subject marks from the keyboard using Scanner. Display the input back with total and percentage in a clean formatted report.

Assignment 3

Mini Input-Output Calculator

Assignment BriefDue: Complete before Topic 2.7 (Command Line Arguments)

Mini Input-Output Calculator

Build an interactive calculator that asks the user for two numbers and an operator (+, -, *, /, %), then displays the result with a meaningful message. Handle division by zero with a user-friendly output.

2.7

Command Line Arguments

LecturePractical1 assignment

Assignment

Command Line Argument Parser

Assignment BriefDue: Complete before Topic 2.8 (Control Statements in Java)

Command Line Argument Parser

Write a Java program that accepts command line arguments for student name, roll number, and marks in three subjects. Display the inputs, calculate total and percentage, and print a formatted result. Handle missing arguments by showing a clear usage message.

2.8

Control Statements in Java

LecturePractical2 assignments

Assignment 1

Decision Making with if, if-else, and switch

Assignment BriefDue: Complete before Topic 2.9 (Array)

Decision Making with if, if-else, and switch

Write a Java program that accepts a student's percentage and prints the division or grade using if-else-if. Then extend the same program to display a course category message using a switch statement based on a user-entered letter grade.

Assignment 2

Loop Practice with for, while, and do-while

Assignment BriefDue: Complete before Topic 2.9 (Array)

Loop Practice with for, while, and do-while

Create three separate Java programs to demonstrate for, while, and do-while loops. Use them to print the first 20 natural numbers, and the sum of odd numbers from 1 to 20.

2.9

Array

LecturePractical3 assignments

Assignment 1

Array Declaration, Initialization, and Traversal

Assignment BriefDue: Complete as a consolidation of Unit 2

Array Declaration, Initialization, and Traversal

Write a Java program that declares an integer array of size 5, initializes it with user input, and then displays the elements using a for loop. Calculate and print the sum and average of all elements.

Assignment 2

Finding Min, Max, and Average in Arrays

Assignment BriefDue: Complete as a consolidation of Unit 2

Finding Min, Max, and Average in Arrays

Create a program that accepts 10 integers into an array. Find and display the minimum value, maximum value, and average. Also count how many elements are greater than the average.

Assignment 3

Array Searching and Sorting

Assignment BriefDue: Complete as a consolidation of Unit 2

Array Searching and Sorting

Implement a program that stores marks of 5 students in an array. Implement search to find if a specific mark exists. Then sort the array in ascending order and display the sorted marks.