Showing posts with label Java Exception Handling. Show all posts
Showing posts with label Java Exception Handling. Show all posts

Monday, January 13, 2014

Java Calculator

Create a java based GUI calculator as shown below ...
Implement only the following functionalities ...
  • Addition
  • Difference
  • Multiplication
  • Division
  • CLR button
  • Back Space button

Saturday, November 23, 2013

Java BufferedReader & StreamTokenizer Example

Write a method that will take a string containing integers and return the sum of the numbers present in the string. For example, given the string "10 2 20 30" should print 62.

Java FileInputStream Example

Write a JAVA Program which reads an input file from the Command Line which contains the numbers sperated by space and find the average for the numbers.

Java File concatenation (Multiple file Handling)

Write a JAVA Program which reads a number of text files from the command line and concatenates the contents of the files into the last file entered on the command line.

Example:
Java Concatenate src1.txt src2.txt src3.txt dest.txt
All the contents of the source files should be concatenated and written in destination file.

Monday, November 18, 2013

Java File reading

Write a JAVA Program which reads a text file from the Command Line and prints it to the console.

Java Threads

Write a program using threads which prints the following:

In first thread:0
In Second Thread:0
In Second Thread:1
In first thread:1
In Second Thread:2
In Second Thread:3
In first thread:2
In Second Thread:4
In Second Thread:5
In first thread:3
In Second Thread:6
In Second Thread:7
In first thread:4
In Second Thread:8
In Second Thread:9
End of first thread
End of second thread

Saturday, November 16, 2013

Java multiple user defined exceptions

Implement a Class BankAccount with two members account_number and balance.It also has two member methods createAccount(acc_num,bal) and withdraw(amount). Implement an Exception class which handles the following exceptions.

  • MinimumBalanceExcpetion: If an account is started with an amount less than the minimum balance,throw this exception.
  • InSufficientFundException: If a person tries to withdraw an amount more than his/her actual balance, throw this exception.

Write a ExDemoClass with main() that tests the same.Include a finally block which prints “In finally block”.

Java user defined Exception Example

Write a program that calls a method to divide two integers entered from the keyboard and throws an user defined exception of type ArithmeticException when trying to divide by zero.The program should take the user input from the console and based on the condition should throw an user defined exception which prints a message.

Sample Output :

Enter the first number:
10
Enter the second number:
0
Exception Occurred :Trying to divide 10/0 .Division by zero is not allowed.