Sie sind auf Seite 1von 7

EXPERIMNET 0: (Environment configuration & sample program)

 JDK installation
 Eclipse installation
 Java path environment variable setting
 Java home environment variable setting
 Compiling and running of a sample program to print “Hello World”.
(i) By using only JDK & Notepad (ii) By Using Eclipse IDE.

EXPERIMNET 1:
Verify following properties for a simple “Hello world” program (Given Below)
class Demo{
public static void main(String args[]){
System.out.println(“Hello world”)
}
}
a. Compile and Run the program with/without path variable setting.
b. Class name may/may not start with capital letter.
c. Source file’s name may /may not be same as the declared class.
d. How to handle declaration of two or more class declarations within the same source file.
e. What will be the effect of interchanging public and static keywords.
f. Verify that “args” is an identifier or not.
g. Can we modify the name and/or parameters of the main() method.
h. Who will call the main () method?

EXPERIMENT 2:
1. Write a java program that will illustrate the concept of object aliasing.
2. Write a java program that will demonstrate the following facts:
(i) the static fields(members) can be directly accessed in both static and non-static contexts.
(ii) the non-static fields can be directly accessed in non-static context only (not in the static
context).
3. Write a java program that will demonstrate the usage of javadoc tool with respect to class
declaration, method declaration and field declaration.
4. Prove or disprove the following statement: “Nesting of multiple line comments are allowed.”
5. Write a java program will show that the default values for fields are of their types.
6. Write a java program that will prove the following statement: “Local variables must be
explicitly initialized before being used.”
EXPERIMENT 3:
1. Write a java program that will take following types of inputs from the user and simply print
the user inputs. (i) int (ii) float (iii) char (iv) string (v) a line
Hint: Use Scanner class of Java APIs.
2. Write a java program to find out whether an input number is prime or not. Please ensure that
the end user may input anything(float, string, char etc) , Also your program will display an
appropriate message to the user based on his/her input and the program will ask for the input until
a valid input is entered by the user without program termination.

EXPERIMENT 4:
1. Write a java program that will demonstrate the usage of “this” reference to elaborate the
following concepts:
(i)“this” reference cannot be used in static context(i.e. it can be used in any non-static context )
(ii) “this” reference cannot be modified as it’s a final reference.
(iii) “this” reference is useful in situations where a local variable hides/shadows a field with the
same name.
2. Write a java program that will demonstrate “method overloading”.
3. Write a java program that will demonstrate the following fact: “Class Names and method
names exist in different namespaces”.

EXPERIMENT 5:

1. WAP that will overload the main() method that is called by JVM. Also call the main()
method explicitly.
2. WAP that will demonstrate the usage of “anonymous array”.
3. What are ragged arrays? WAP that will demonstrate the usage of “ragged array”.
4. With the help of a program prove the following fact: “Java doesn’t support call by
reference”.
5. Comment about the code given below, what will happen and why?
void myfun() {

int[] x= 0;
}

EXPERIMENT 6:

1. WAP that will take three “program arguments” and print these program arguments.
2. WAP that will demonstrate the usage a variable arity method with two formal parameters
(int & String …) also show some valid invocations of this method with different number of actual
parameters.
3. Define the main() method that is called by JVM as variable arity method and call this main()
method explicitly with zero or more number of actual parameters.

EXPERIMENT 7: (Controlling Execution)

1. (i) Write a program that generates 25 random int values. For each value, use an if-else statement
to classify it as greater than, less than, or equal to a second randomly generated value.
(ii) Modify Exercise (i) so that your code is surrounded by an “infinite” while loop. It will then
run until you interrupt it from the keyboard (typically by pressing Control-C).
2. Write a program that uses two nested for loops and the modulus operator (%) to detect and print
prime numbers (integral numbers that are not evenly divisible by any other numbers except for
themselves and 1).
3. A Fibonacci sequence is the sequence of numbers 1, 1, 2, 3, 5, 8, 13, 21, 34, and so on, where
each number (from the third on) is the sum of the previous two. Create a method that takes an
integer as an argument and displays that many Fibonacci numbers starting from the beginning,
e.g., If you run java Fibonacci 5 (where Fibonacci is the name of the class) the output will be: 1,
1, 2, 3, 5.
4. A vampire number has an even number of digits and is formed by multiplying a pair of numbers
containing half the number of digits of the result. The digits are taken from the original number in
any order. Pairs of trailing zeroes are not allowed. Examples include:
1260 = 21 * 60
1827 = 21 * 87
2187 = 27 * 81
Write a program that finds all the 4-digit vampire numbers.
EXPERIMENT 8: (Packages)
Consider the following package hierarchy:

Here,
wizard, pandorasBox ,artifacts & spells are the names of package/subpackages.
The accessibility of various types(classes and interfaces) are declared as follows:
Clown, LovePotion(within the package wizard.pandorasBox) & Ailment:- public
All others:- default
(i) What will be the minimum number of source files required to represent this package hierarchy?
(ii) Write a java application that will provide the overall structure of each source file by assuming
that each type has blank body i.e. {}.
Hint: Include all the package and import statements in each source file.

EXPERIMENT 9: (Just for practice purpose)

1. Display the largest and smallest numbers for both float and double exponential notation.
2. Write a method that displays char values in binary form. Demonstrate it using several different
characters.
3. Write a program that demonstrates that autoboxing works for all the primitive types and their
wrappers.
4. Create a class containing an uninitialized String reference. Demonstrate that this reference is
initialized by Java to null.
5. Create a class without a constructor, and then create an object of that class in main( ) to verify
that the default constructor is automatically synthesized.
EXPERIMENT 10: (Packages, Access specifiers)

1. Create a class in a package. Create an instance of your class outside of that package.
2. Create a class with public, private, protected, and package-access fields and method members.
Create an object of this class and see what kind of compiler messages you get when you try to
access all the class members. Be aware that classes in the same directory are part of the “default”
package.
3. Show that protected methods have package access but are not public.

EXPERIMENT 11: (Strings)


1. Write your own versions of String search methods indexOf() and lastIndexOf().
2. Write an application that uses String method compareTo to compare two strings input by the
user. Output whether the first string is less than, equal to or greater than the second.
3. Write an application that inputs a line of text and a search character and uses String method
indexOf to determine the number of occurrences of the character in the text.

EXPERIMENT 12: (Inheritance)


1. Prove that the base-class constructors are (a) always called and (b) called before derived-class
constructors.
2. Create two classes, A and B, with default constructors (empty argument lists) that announce
themselves. Inherit a new class called C from A, and create a member of class B inside C. Do not
create a constructor for C. Create an object of class C and observe the results.
3. Create a class with a method that is overloaded three times. Inherit a new class, add a new
overloading of the method, and show that all four methods are available in the derived class.
4. Create a class called Amphibian. From this, inherit a class called Frog. Put appropriate methods
in the base class. In main( ), create a Frog and upcast it to Amphibian and demonstrate that all
the methods still work.
5. Create an inheritance hierarchy of Rodent: Mouse, Gerbil, Hamster, etc. In the base class,
provide methods that are common to all Rodents, and override these in the derived classes to
perform different behaviors depending on the specific type of Rodent. Create an array of Rodent,
fill it with different specific types of Rodents, and call your base-class methods to see what
happens.

EXPERIMENT 13: (abstract and final classes)

1. Create a class as abstract without including any abstract methods and verify that you cannot create
any instances of that class.
2. Create a base class with an abstract print( ) method that is overridden in a derived class. The overridden
version of the method prints the value of an int variable defined in the derived class. At the point of
definition of this variable, give it a nonzero value. In the base-class constructor, call this method. In main(
), create an object of the derived type, a`nd then call its print( ) method. Explain the results.
EXPERIMENT 14: (Interfaces)

1. Create an interface containing three methods, in its own package. Implement the interface in a different
package
2. Prove that all the methods in an interface are automatically public.
3. Create three interfaces, each with two methods. Inherit a new interface that combines the three,
adding a new method. Create a class by implementing the new interface and also inheriting from a
concrete class. Now write four methods, each of which takes one of the four interfaces as an argument.
In main( ), create an object of your class and pass it to each of the methods.

EXPERIMENT 15: (GUI )


EXPERIMENT 16: (Event Handling)

1. Write a program that will create a frame with a Textfield and two buttons. Manage events such that
by clicking each button different text will appear in the Textfield.

EXPERIMENT 17: (Servlets/Applets )

1. Write a servlet program to print “hello world”. (Include all files associated with the servlet)
2. Write an applet to print “welcome to java”. (Include all files associated with the applet )

EXPERIMENT 18: (Design Pattern/Java Beans )

1. Write a java program that explain Singleton design pattern.


2. Write a JavaBean class having a property of each type: int, Boolean & String.

Das könnte Ihnen auch gefallen