SlideShare a Scribd company logo
Hands-on Exercises
Java 101: Introduction to Java
Hands-on Exercise
Basic Java Program
Create Basic Java Program
• Create the following program by typing it into
a text editor, and save it as HelloWorld.java.
Compile Basic Java Program
• Compile it by typing at the command-line: javac
HelloWorld.java.
• This creates a Java bytecode file named:
HelloWorld.class.
Execute Basic Java Program
• Execute it by typing at the command-line: java
HelloWorld.
Hands on Exercise
Command Line Arguments
Command Line Arguments
• Create a program that takes a name as command-line argument and
prints “Hi <name>, How are you?”
Hands-on Exercise
Integer Operations
Exercise: Integer Operations
• Create new Java project in Eclipse called IntegerOperations
• Create a Java class named IntOps that performs integer operations on a pair of integers
from the command line and prints the results.
Solution: Integer Operations
Hands-on Exercise
Leap Year Finder
Exercise: Leap Year Finder
• A year is a leap year if it is either divisible by 400 or
divisible by 4 but not 100.
• Create a java project in Eclipse named LeapYearFinder
• Write a java class named LeapYear that takes a year as
command line argument and prints true if it’s a leap
year and false if not
Solution: Leap Year Finder
Hands-on Exercise
Powers of Two
Exercise: Powers of Two
• Create a new Java project in Eclipse named Pow2
• Write a java class named PowerOfTwo to print powers of 2 that are
<= 2N where N is a number passed as an argument to the program.
– Increment i from 0 to N.
– Double v each time
Solution: Power of 2
Bonus Exercises
Java 101: Introduction to Java
Hands-on Exercise
Random Number Generator
Exercise: Random Number Generator
• Create a new java project in Eclipse called RandomInteger
• Write a java class named RandomInt to generate a pseudo-random
number between 0 and N-1 where N is a number passed as an
argument to the program
Solution: Random Number Generator
Hands-on Exercise
Array of Days
Exercise: Array of Days
• Create a new Java project in Eclipse named ArrayOfDays
• Create a java class named DayPrinter that prints out
names of the days in a week from an array using a for-
loop.
Solution: Arrays of Days
public class DayPrinter {
public static void main(String[] args) {
//initialize the array with the names of days of the
week
String[] daysOfTheWeek =
{"Sunday","Monday","Tuesday","Wednesday",
"Thuesday","Friday”,"Saturday"};
//loop through the array and print their elements to
//stdout
for (int i= 0;i < daysOfTheWeek.length;i++ ){
System.out.println(daysOfTheWeek[i]);
}
}
}
% javac DayPrinter.java
% java DayPrinter
Sunday
Monday
Tuesday
Wednesday
Thuesday
Friday
Saturday
Hands-on Exercise
Print Personal Details
Exercise: Print Personal Details
• Write a program that will print your name and
address in the Console view of Eclipse, for
example:
Alex Johnson
23 Main Street
New York, NY 10001 USA
Hands-on Exercise
Sales Discount
Exercise: Sales Discount
• Create a new project in Eclipse named Sale
• Create, compile, and run the FriendsAndFamily class as illustrated below
• Debug this program in your IDE to find out how it works

More Related Content

PDF
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PDF
PPSX
Introduction to Java
PDF
Javascript basic course
PPTX
Data Types, Variables, and Operators
PPT
Java Servlets
PPTX
oops concept in java | object oriented programming in java
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Basic Concepts of OOPs (Object Oriented Programming in Java)
Introduction to Java
Javascript basic course
Data Types, Variables, and Operators
Java Servlets
oops concept in java | object oriented programming in java

What's hot (20)

PDF
Introduction to flutter
PPTX
Classes, objects in JAVA
PPTX
Object Oriented Programming
PDF
Introduction to java (revised)
PPTX
Java swing
PDF
Java Course 8: I/O, Files and Streams
PPTX
JavaFX Presentation
PPT
Knowledge Sharing : Java Servlet
PPT
SQLITE Android
PPTX
Core java complete ppt(note)
PPTX
Applets in java
PDF
Java Collection framework
PPT
Asp.net control
PPTX
Python-Polymorphism.pptx
PDF
Jdbc connectivity in java
PDF
JavaFX Overview
PDF
Web Development with Python and Django
PDF
JAVA PPT Part-1 BY ADI.pdf
PPTX
Class, object and inheritance in python
PPTX
A Presentation on Development of a Simple Calculator
Introduction to flutter
Classes, objects in JAVA
Object Oriented Programming
Introduction to java (revised)
Java swing
Java Course 8: I/O, Files and Streams
JavaFX Presentation
Knowledge Sharing : Java Servlet
SQLITE Android
Core java complete ppt(note)
Applets in java
Java Collection framework
Asp.net control
Python-Polymorphism.pptx
Jdbc connectivity in java
JavaFX Overview
Web Development with Python and Django
JAVA PPT Part-1 BY ADI.pdf
Class, object and inheritance in python
A Presentation on Development of a Simple Calculator
Ad

Viewers also liked (20)

PPTX
Java 102 intro to object-oriented programming in java - exercises
PDF
Programming exercises
PDF
Introduction to Agile
PPTX
Java 101 Intro to Java Programming
PPTX
Java 201 Intro to Test Driven Development in Java
PPTX
Java 102 intro to object-oriented programming in java
PPTX
Computer Programming Overview
PPTX
Java 103 intro to java data structures
PPTX
Java 101 intro to programming with java
PDF
Java Day-7
PDF
Enum Report
PDF
Java Day-2
PPTX
Data structures and algorithms lab5
PPSX
data structure(tree operations)
PPTX
Java package
PDF
Java data structures for principled programmer
PPT
Interface in java By Dheeraj Kumar Singh
PPT
2310 b 09
ODP
Nosql availability & integrity
PPT
Forms authentication
Java 102 intro to object-oriented programming in java - exercises
Programming exercises
Introduction to Agile
Java 101 Intro to Java Programming
Java 201 Intro to Test Driven Development in Java
Java 102 intro to object-oriented programming in java
Computer Programming Overview
Java 103 intro to java data structures
Java 101 intro to programming with java
Java Day-7
Enum Report
Java Day-2
Data structures and algorithms lab5
data structure(tree operations)
Java package
Java data structures for principled programmer
Interface in java By Dheeraj Kumar Singh
2310 b 09
Nosql availability & integrity
Forms authentication
Ad

Similar to Java 101 Intro to Java Programming - Exercises (20)

PPTX
Java 101
PPTX
Introduction to java 101
PDF
Java Lab
PDF
Proyect of english
PDF
Java for beginners programming course
PDF
Java for beginners programming course (updated)
PDF
Java conceptual learning material
PDF
Java Script Sysllabus for the computer.pdf
PPTX
Fundamentals of java --- version 2
PPTX
Java-Programming.forBSITSTUDENTfreespptx
PPTX
Core Java introduction | Basics | free course
PPT
bai giang java co ban - java cơ bản - bai 1
PDF
OpenThink Labs Training : Diving into Java, The Head First Way
PDF
Download full ebook of Programming With Java Edet Theophilus instant download...
PDF
Intro To Java Alpharetta Meetup Day-1
PDF
Java 8 for complete beginners
PDF
03 expressions.ppt
PDF
Java for complete beginners programming course
Java 101
Introduction to java 101
Java Lab
Proyect of english
Java for beginners programming course
Java for beginners programming course (updated)
Java conceptual learning material
Java Script Sysllabus for the computer.pdf
Fundamentals of java --- version 2
Java-Programming.forBSITSTUDENTfreespptx
Core Java introduction | Basics | free course
bai giang java co ban - java cơ bản - bai 1
OpenThink Labs Training : Diving into Java, The Head First Way
Download full ebook of Programming With Java Edet Theophilus instant download...
Intro To Java Alpharetta Meetup Day-1
Java 8 for complete beginners
03 expressions.ppt
Java for complete beginners programming course

Recently uploaded (20)

PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
System and Network Administraation Chapter 3
PDF
AI in Product Development-omnex systems
PDF
Nekopoi APK 2025 free lastest update
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
top salesforce developer skills in 2025.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Operating system designcfffgfgggggggvggggggggg
Adobe Illustrator 28.6 Crack My Vision of Vector Design
CHAPTER 2 - PM Management and IT Context
wealthsignaloriginal-com-DS-text-... (1).pdf
Reimagine Home Health with the Power of Agentic AI​
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Design an Analysis of Algorithms II-SECS-1021-03
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Which alternative to Crystal Reports is best for small or large businesses.pdf
Understanding Forklifts - TECH EHS Solution
Wondershare Filmora 15 Crack With Activation Key [2025
Navsoft: AI-Powered Business Solutions & Custom Software Development
System and Network Administraation Chapter 3
AI in Product Development-omnex systems
Nekopoi APK 2025 free lastest update
2025 Textile ERP Trends: SAP, Odoo & Oracle
top salesforce developer skills in 2025.pdf

Java 101 Intro to Java Programming - Exercises