JAVA 2015 Old paper Solutions

3rd Semester

Year 2015

Group B 11 Write a Java Program to display all the even numbers from 1 to 500

12. Make a thread using Runnable interface to display numbers from 1 to 20, each number should be displayed in the interval of 2 seconds.

13. Write a program that reads line of text from keyboard and write to file. Also read the content of the same file and display on monitor. 14

15. Make an interface named num with two functions int add(int x, int y) and int diff(int x, int y) then make a class that implements that interface num

An exception is an abnormal condition that arises in a code sequence at run time. In other words, an exception is a run time error.When an Exception occurs the normal flow of the program is disrupted and the program/Application terminates abnormally, which is not recommended, therefore these exceptions are to be handled.
Some reasons that may cause exception to occur

  • A user has entered invalid data.
  • A file that needs to be opened cannot be found.
  • A network connection has been lost in the middle of communications or the JVM has run out of memory.

17. Define package? Write down steps to create package. Explain with example
Package can be defined as a grouping of related types (classes, interfaces, enumerations and annotations ) providing access protection and namespace management.

  • Some of the existing packages in Java are −
  • java.lang− bundles the fundamental classes
  •− classes for input , output functions are bundled in this package
  • Programmers can define their own packages to bundle group of classes/interfaces, etc. It is a good practice to group related classes implemented by you so that a programmer can easily determine that the classes, interfaces, enumerations, and annotations are related.

Steps to create a Java package

  • Come up with a package name.
  • Pick up a base directory.
  • Make a subdirectory from the base directory that matches your package name.
  • Place your source files into the package subdirectory.
  • Use the package statement in each source file.
  • Compile your source files from the base directory.


Leave a Reply

Your email address will not be published. Required fields are marked *