Core Java Programming: From Beginner to Project Development

Lesson 1.10: Practice Exercises

Introduction

Congratulations! You have successfully completed Module 1: Introduction to Java.

In this lesson, you will revise everything you learned throughout the module by solving practical exercises. Programming is a skill that improves with practice, so it is important to write the code yourself instead of simply reading it.

The exercises in this lesson will strengthen your understanding of Java basics and prepare you for the next module.


Learning Objectives

After completing this lesson, you will be able to:

  • Create and run Java programs independently.

  • Understand the basic structure of Java programs.

  • Practice writing Java syntax correctly.

  • Improve problem-solving and logical thinking.

  • Gain confidence before learning variables and data types.


Exercise 1: Print “Hello, Java!”

Problem Statement

Write a Java program to print:

Hello, Java!

Solution

public class HelloJava {

    public static void main(String[] args) {

        System.out.println("Hello, Java!");

    }

}

Exercise 2: Print Your Personal Information

Problem Statement

Write a Java program to display:

  • Name

  • Roll Number

  • Department

  • College Name

  • City

Sample Output

Name        : Rahul Kumar
Roll Number : 210101
Department  : Computer Science
College     : Government Polytechnic
City        : Ranchi

Exercise 3: Print Multiple Lines

Problem Statement

Write a program that prints:

Welcome to Java
Programming is Fun
Let's Learn Java

Exercise 4: Using print() and println()

Problem Statement

Write a program to understand the difference between print() and println().

Expected Output

Hello Students
Welcome to Java

Exercise 5: Using Escape Sequences

Problem Statement

Write a program using:

  • \n

  • \t

  • \"

Expected Output

Student Information

Name    : Rahul
Course  : Java Programming

He said, "Welcome to Java!"

Exercise 6: Write Your Favorite Quote

Create a Java program that prints your favorite motivational quote.

Example:

"The future depends on what you do today."

Exercise 7: College Introduction

Display the following information in a neat format:

College Name
Department
Semester
Subject
Teacher Name

Exercise 8: Create a Class

Create a class named:

StudentInfo

Inside the main() method, print your personal details.


Exercise 9: Create Multiple Java Files

Create the following Java files:

  • Hello.java

  • Student.java

  • College.java

Run each program successfully.


Exercise 10: Command Prompt Practice

Open the Command Prompt and perform the following:

Compile the program:

javac Hello.java

Run the program:

java Hello

Observe the generated .class file.


Mini Challenge

Without copying any previous code, create a Java program that displays:

******************************
      STUDENT PROFILE
******************************
Name       : Your Name
Department : Computer Science
Semester   : 3rd
College    : Government Polytechnic
******************************

Try to format the output neatly.


Module 1 Quiz

Choose the correct answer.

1. Java was developed by:

A. Dennis Ritchie

B. Bjarne Stroustrup

C. James Gosling

D. Guido van Rossum

Answer: C


2. Java source files have which extension?

A. .class

B. .java

C. .exe

D. .txt

Answer: B


3. Which method is the starting point of every Java program?

A. start()

B. begin()

C. execute()

D. main()

Answer: D


4. Which command compiles a Java program?

A.

java Hello

B.

javac Hello.java

C.

compile Hello

D.

run Hello

Answer: B


5. Which command runs a compiled Java program?

A.

javac Hello.java

B.

execute Hello

C.

java Hello

D.

run Hello

Answer: C


6. Java programs are compiled into:

A. Machine Code

B. Bytecode

C. Binary File

D. Assembly Language

Answer: B


7. Which component executes Java Bytecode?

A. Compiler

B. JDK

C. JVM

D. Editor

Answer: C


8. Java is known as a:

A. Platform-Dependent Language

B. Platform-Independent Language

C. Database Language

D. Markup Language

Answer: B


Programming Assignment

Complete all of the following tasks:

  1. Create 5 different Java programs using System.out.println().

  2. Create 3 programs using escape sequences.

  3. Compile and execute every program.

  4. Organize all files inside a folder named Module 1 Practice.

  5. Take screenshots of the program outputs and save them for submission.


Module 1 Summary

Congratulations!

You have completed the first module of this course.

You learned:

  • What Java is

  • Features and applications of Java

  • JDK, JRE, and JVM

  • Installing Java

  • Installing Visual Studio Code

  • Writing your first Java program

  • Java program structure

  • Compilation and execution process

  • Basic programming practice

You are now ready to move to Module 2, where you will begin writing real programs using variables, data types, operators, and user input.


What’s Next?

In the next module, you will learn how to:

  • Store data using variables.

  • Work with different data types.

  • Perform calculations using operators.

  • Accept input from the user.

  • Build interactive Java programs.

Next Module: Module 2 – Variables, Data Types, and Operators

Next Lesson: Lesson 2.1 – Variables in Java

 

Scroll to Top