0% found this document useful (0 votes)
44 views2 pages

Java Practice Questions

The document contains a series of Java programming practice questions covering fundamental concepts such as class creation, constructors, object declaration, static vs non-static methods, package creation and access, importing packages, CLASSPATH understanding, auto boxing, and string manipulation. Each question provides a specific task to implement, demonstrating key programming principles. The exercises are designed to enhance understanding and application of Java programming skills.

Uploaded by

kgond332007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views2 pages

Java Practice Questions

The document contains a series of Java programming practice questions covering fundamental concepts such as class creation, constructors, object declaration, static vs non-static methods, package creation and access, importing packages, CLASSPATH understanding, auto boxing, and string manipulation. Each question provides a specific task to implement, demonstrating key programming principles. The exercises are designed to enhance understanding and application of Java programming skills.

Uploaded by

kgond332007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Programming Practice Questions

1. Class Fundamentals

Create a class `Book` with attributes: `title`, `author`, and `price`. Write methods to input book details

and display them. Create multiple objects and call methods to test.

2. Constructors

Create a class `Employee` with a constructor to initialize name, ID, and salary. Add a method to

display the employee details. Create at least two employee objects using the constructor.

3. Declaring Objects (Object & Object Reference)

Write a program that creates a class `Car`, and then instantiate it in the `main()` method using object

references. Demonstrate how to access fields and methods using the object reference.

4. Static and Non-Static Variables/Methods

Create a class `Calculator` with a static method `add()` and a non-static method `multiply()`. Show

how to call both methods from the main method and explain the difference in access.

5. Creating and Accessing Packages

Create a package named `bank`. Inside it, define a class `Account` with methods to deposit and

withdraw money. Access this class from another class in a different package.

6. Importing Packages

Use Java's built-in package `java.util` to create a program that uses the `Scanner` and `ArrayList`

classes. Demonstrate how to import and use classes from a package.

7. Understanding CLASSPATH

Write two classes in different packages. Compile and run them using the command line by setting

the CLASSPATH manually. (You can include class-level comments on how to do this.)

8. Auto Boxing

Create a program that takes an `int` value and stores it in an `Integer` object using auto boxing.
Then demonstrate unboxing by converting the `Integer` object back to `int`.

9. String

Write a Java program that reads a sentence from the user and counts the number of vowels, words,

and characters using various `String` class methods.

10. StringBuffer

Write a Java program that takes a string from the user and:

- Reverses it using `StringBuffer`

- Appends a message

- Deletes a portion of the string

You might also like