Core Java assignments 2

Below are few assignments on Core Java, which you can try out

1.Swap Numbers Without Using Third Variable Java Example*
2.Java program to find Palindrome Number or not. For eg. 12321 is palindrome, and 124869 is not palindrome
3.Program to create an outer and inner classes with some methods and then create an two objects to access both the methods in innner and outer class.
4.Write a program that shows how to access the private members of a class using inner class.
5.Program to create enum class in java
6.Write a Java program by using BufferedReader class to prompt a user to input his/her name from keyboard and then the display output, until done is given as input.(Hint use any loop)
7.Write a program in Java to print Fibonacci series up to given number? Write both iterative and recursive version
8.write a Java program to calculate factorial of an integer number ? Both iterative and recursive solution.
9.Write a program to extract each digit from an int. For example, if the int is 86543, the output shall be 8,6,5,4,3.
Hints: Use n % 10000 to extract first digit, and n = n / 10000 to remove first digit, and continue with this process, to get each digit.

10.Write a program to read an int, a float, and a String in text file called “abc.txt”, and output in below way
integer read is 12
decimal number read is 33.44
String read is “Hello”

11.Write a program to reverse an input String. For example:
Enter input String: wxyz
Reversed String is: zyxw

12.Write a program to print fibonacci series less than 100?

13.Write a program to print, if given number is armstrong number. For example 371 is armstrong number because 3*3*3+7*7*7+1*1*1 = 371

14.When a given string Hello, output need to be printed as H l o
That is only odd characters need to be printed, space need to be printed for even characters.

15.Explain difference between Compile time polymorphism and run time ploymorphism

16.Write program to display Greatest Common Factor, of given numbers.

17.To a TreeSet, add Employee objects, with below fields/data members
employee name, salary, age, department.
Store the employee objects in ascending order of salary. Get all employees with salary greater than 15,000
Hint:Use Comparator or Comparable interface

18.Repeat assignment 17, with descending order of salary.

19.Use 4 threads along with main thread to display each character of a given string. For eg. if “Hello, How are you” String is given, output can be something similar as below.
Thread 1: H
Thread 3: e
Main Thread: l
Thread 2: l
Thread 1: o
Thread 2:
and so on…..

20. Develop
(a) RMI Server object exposing methods, taking radius as parameter, and returns diameter, circumference, surface area,etc…
(b) Develop RMI Client which can lookup to above RMI Server object, and invoke the methods.

21. Develop a circular linked list, by implementing List interface.

(a) RMI Server object exposing a method, taking Collection of City objects as input parameter.A city object can have below fields city name, temperature. RMI Server object need to find average of temperatures in all City objects.
(b) RMI Client object, which can look up and invoke above method.

23. Simple Client and Server. A Client sends int or float to Server. Server need to multiply with 10, and send result back to Client. Client need to display final value.

24. Develop a console based Server and Client. Client need to send commands like current directory, change directory, list files & file properties(like modified date, etc…). Server program need to provide above details, when requested by client.

25. Implement a simple Web Server, which receives request, and serve the requested file, to the Client.

26. Develop a simple console based chat broadcast client, and chat server, using socket programming. Chat server need to serve multiple chat clients. Whenever a client sends a message, the message need to be received by all the chat clients running currently.

27. Can I pass array as parameter to a constructor?
Can an object be declared as static data member.Can u give an example of it, from built ib classes?

28. A method which can take any number of one dimensional arrays, write a program, then create and return an array, which removes duplicate elements.

29. Write program to take non english characters from keyboard, and print them.

30. Can we make a constructor synchronized?

31. Assume that sorted order of alphabets are different, which can be given as input. Given a String arrange characters of this String in customized alphabetical order?

32. What is the difference between Scanner and BufferedReader

33. How to convert Reader to InputStream, and viceversa?

34. What is the output of below program?
package p1;

class Alpha extends Beta{


class Beta extends Teta{


class Teta extends Alpha{


public class Misc1 {
public static void main(String[] args) {
Teta ot = new Teta();
System.out.println(“Everything works fine”);

35. A client program, having two threads, at atime only one thread can send a request to a server program. When one client thread is in the process of sending request, and if other client thread wants to send request, then it need to wait, until first thread completes sending request to server. Note that, the two client threads, can execute simultanesouly, but only one thread can interact with server at a time.

36. In InputStreams what is the purpose of mark and reset?

37. What is chain of responsibility Design Pattern?

38. Advantage of Facade Pattern?

39. Lets assume there is a framework, which is released to App developers. How do you ensure that old Apps are not affected with newer versions of Framework? i..e how do you take care of backward compatibility of already developed Apps, even though underlying components of framework may change. which design patterns do you suggest?

40. A program which receives an input thru network socket, based on the string received, a specific observer need to do some processing. All this can be performed with one thread.

There can be multiple observers, each of which can do one of the following
a. which reverses string
b. which replaces some character in string
c. which concatenates string

Hint: use Observer and Observable

41. Repeat above problem, by using separate thread for each Observer, and perform some long processing in each Observer thread.

42. Solve the same above problem using wait() notify()

43. Create a vehicle class, with below data members

String make_and_model;

String registration_number;

String registration_date; //in format dd-mm-yyyy

You can add appropriate constructor, setter & getter methods to above class. Then create about 10 objects of above class, with different values of data members. Now add these objects to a TreeSet, and ensure that the objects in TreeSet are arranged in ascending order of registration_date.

NOTE: use Comparator interface

44. Print your name 10 times, without using a loop. NOTE: use method recursion

You may also like to read:
Basic Core Java Assignments 1