Core Java Practical
Practical Questions: Core Java Laboratory
For each of
the following practical exercises, you are required to design, implement, and
test a Java program. Ensure your code is well-structured, commented, and
adheres to good programming practices.
1.
Write a Java program that displays the classic "Hello World!"
message on the console.
o
Objective: To familiarize yourself with the basic structure of a Java program,
compilation, and execution.
2.
Develop a Java program to generate and display various star (*) patterns on the console.
o
Objective: To practice using control flow statements (loops) and nested loops to
create patterned output. Examples could include a right triangle, square, or
pyramid.
3.
Create a Java program to calculate and display the area and perimeter of
a circle.
o
Objective: To implement basic arithmetic operations, use appropriate data types
for floating-point numbers, and take user input for the circle’s radius.
4.
Write a Java program that takes two binary numbers (as strings or
suitable data types) as input from the user and calculates their sum,
displaying the result in binary format.
o
Objective: To work with string manipulation or custom logic for binary arithmetic,
demonstrating control flow and data conversion.
5.
Implement a Java program to reverse a given string.
o
Objective: To manipulate strings using loops, character access, or StringBuilder/StringBuffer classes, demonstrating string
handling techniques.
6.
Develop a Java program that accepts a string input from the user and
counts the occurrences of letters, spaces, numbers (digits), and any other
special characters within that string.
o
Objective: To utilize string iteration and character classification methods (e.g.,
Character.isLetter(), Character.isDigit(), Character.isSpaceChar()).
7.
Write a Java function (method) that takes a character array representing
a numeric value as input and calculates the sum of its individual digits.
o
Example: For char[] {‘1’, ‘2’, ‘3’}, the sum should be 6.
o
Objective: To demonstrate iteration over character arrays, type conversion from char to int, and basic arithmetic
operations.
8.
Create a Java program to find and display the smallest and largest
elements present in an array of integers.
o
Objective: To practice array traversal, comparison operators, and conditional
logic to identify extreme values within a data structure.
9.
Design and implement a Java class (e.g., Car or Book) that demonstrates the effective use of
constructors. Your class
should include:
o
At least one default constructor and one parameterized constructor.
o
Instance variables that are initialized by these constructors.
o
A method to display the object’s state.
o
Objective: To understand object creation, initialization through constructors, and
the basic lifecycle of objects in Java (acknowledging Java’s automatic garbage
collection instead of explicit destructors).
10.
Implement a Java program that demonstrates single-level inheritance.
o
Task: Create a Vehicle class (superclass) with common attributes (e.g., brand, year) and a Car class (subclass) that extends Vehicle, adding its own specific attributes (e.g., model, numberOfDoors). Show how to access superclass members and potentially
override a method.
o
Objective: To apply the fundamental concepts of inheritance, super keyword, and method overriding.
11.
Project: Develop a small console-based Java application that integrates
concepts from Units 1-4 of the Core Java syllabus.
o
Objective: To apply your accumulated knowledge to solve a slightly more complex
problem, demonstrating understanding of OOP principles, class design, data
handling, and potentially user interaction and basic error handling. You may
choose a topic like a simple "Student Management System," "Basic
Inventory System," or a text-based "Quiz Application."
o
Submission: Your project should include source code files, a brief design document
(UML/pseudocode), and instructions on how to compile
and run the application.