answersLogoWhite

0


Best Answer

Here's a Hello World application:

import static java.lang.System.out;

class HelloWorld

{

public static void main(string[] arguments)

{

out.println("Hello world!") //this will print out the words 'Hello world!' to the screen

} //End of main method

} //End of class HelloWorld

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

The most common reason I have for catching Exceptions in Java is when reading information from a file. So let's look at an example where we read and display the contents of a file.

// Note that the main method may throw a FileNotFoundException.

// This means that if the file we try to read from doesn't exist, the program will

// exit with an Exception.

public static final void main(final String[] args) throws FileNotFoundException {

// Create a new FileReader object which reads from myfile.txt

// This is the line which may throw the FileNotFoundException

Reader in = new FileReader("myfile.txt");

// Begin the try block, which will catch any IOExceptions

try {

// Read and display the file contents

int ch;

while ((ch = in.read()) != -1) {

System.out.print((char) ch);

}

// Close the input object

in.close();

} catch (IOException ex) {

}

// And we're done.

System.out.println("End Of File Reached");

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a simple java program using exceptions?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you code the program using arithmetic exceptions?

Never.A program should handle exceptions, but should NEVER USE exceptions to control program flow.


You want to write a simple without using pointer or array c program which will print greatest number when you give 20 number?

i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?


Write a sample program using ASPNET explaining all the syntax and semantics of the program?

write a sample program using asp.net explaining all the syntax and semantics of the program


How do you write Square program using vb?

write a vb program to find the magic square


Write Client and server program in C language using UDP?

Write and run a client and a server program in C-language using UDP


How do we write c program without using swap to interchange values by accessing another variable?

int a,b; a=a+b; b=a-b; a=a-b; that's it simple


How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


Write a program that read phrase and print the number of lower-case letter in it using function of counting?

write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program


Write a program By using if else statement to read a number and check whether it is positive or negative?

write a c++program by using if statement to read a number and check whether it is positive or negative


How to write a C program to find largest 2 numbers using pointers?

program to find maximum of two numbers using pointers


Write a program using CSharp to simulate a text editor to convert to upper Case?

richTextBox1.Text = richTextBox1.Text.ToUpper(); Simple, but i would execute on a button click, not on a Textchanged Condition.


Write a program to find the grade obtained by the students of a class using structure?

Write a program to find the grade obtained by the students of a class