what is difference between checked and unchecked exception
plz explain examples ?

Answer Posted / archana

What is the difference between Checked exceptions and
unchecked exceptions in JAVA?In: Java Programming [Edit
categories]
Computer Programming QuestionsAnswers.com > Wiki Answers >
Categories > Technology > Computers > Computer Programming
> Java Programming > What is the difference between Checked
exceptions and unchecked exceptions in JAVA?
Best Answer.
Unchecked exceptions :


•represent defects in the program (bugs) - often invalid
arguments passed to a non-private method. To quote from The
Java Programming Language, by Gosling, Arnold, and
Holmes : "Unchecked runtime exceptions represent conditions
that, generally speaking, reflect errors in your program's
logic and cannot be reasonably recovered from at run time."
•are subclasses of RuntimeException, and are usually
implemented using IllegalArgumentException,
NullPointerException, or IllegalStateException
•a method is not obliged to establish a policy for the
unchecked exceptions thrown by its implementation (and they
almost always do not do so)
Checked exceptions :


•represent invalid conditions in areas outside the
immediate control of the program (invalid user input,
database problems, network outages, absent files)
•are subclasses of Exception
•a method is obliged to establish a policy for all checked
exceptions thrown by its implementation (either pass the
checked exception further up the stack, or handle it
somehow)
It is somewhat confusing, but note as well that
RuntimeException (unchecked) is itself a subclass of
Exception (checked).

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the benefits of swing over awt?

588


What are the advantage of swing over awt?

503


Explain the difference between jfc & wfc.

566


What is an event in Swing?

607


What is an on stage swing?

549






Explain how to render an html page using only swing.

1026


What are the advantages of swing over awt?

496


What is a swing application?

502


What is an event handler in swing?

632


What is the purpose of serialization in swings?

548


I want to use the markerfor playing a video using the jmf.Suppose my video length is of 2 hours.I want it to play ex-15 mintue or 20 mintue and should stop after assigning the time.I am providing my piece of code............please help me.... package com.jha.cdac.lila.praveen; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import java.net.URL; import javax.media.ControllerAdapter; import javax.media.Manager; /** * * @author vinays */ import javax.media.Player; import javax.media.RealizeCompleteEvent; import javax.media.Time; import javax.swing.JFrame; public class PlayVideo extends javax.swing.JFrame{ Player player; Component center; Component south; // this code is required for playing the video file of mpeg,mp4,mp3,3gp,rm,flv, //wmf,mpv,vob,qt and the asf extension public PlayVideo() { File file = new File("Lesson1.mpg"); try { load(file); // load() } catch (Exception ex) { //Logger.getLogger(LessonNarrative.class.getName ()).log(Level.SEVERE, null, ex); System.out.println("Error while loading file............"+ex); } } //the piece of code given below is used to load the file which user want to play. public void load(final File file) //load the file throws Exception { URL url = file.toURL(); final Container contentPane = getContentPane(); if (player != null) { player.stop(); } // MediaLocator mediaLocator=new MediaLocator (file.toURL()); // DataSource dataSource=Manager.createDataSource (mediaLocator); // player=Manager.createPlayer(url); player = Manager.createRealizedPlayer(url); ControllerAdapter listener = new ControllerAdapter() { @Override public void realizeComplete( RealizeCompleteEvent event) { Component vc = player.getVisualComponent(); player.getVisualComponent(); if (vc != null) { contentPane.add(vc, BorderLayout.CENTER); center = vc; } else { if (center != null) { contentPane.remove(center); contentPane.validate(); } } Component cpc = player.getControlPanelComponent(); if (cpc != null) { contentPane.add(cpc, BorderLayout.SOUTH); south=cpc; } else { if (south != null) { contentPane.remove(south); contentPane.validate(); } } pack(); // //setTitle(file.getName()); //to get the title of Video or Audio File } }; Time tm=new Time(30.4402403); Time tm1=new Time(5.7256199); player.addControllerListener(listener); player.setMediaTime(tm1); player.setStopTime(tm); // player.setMediaTime(new Time(5.0)); //player.setStopTime(new Time(73)); player.realize(); player.start(); } public static void main(String args[]) throws ClassNotFoundException { PlayVideo pv = new PlayVideo(); JFrame f = new JFrame("Lesson1"); f.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); f.getContentPane().add("Center", pv); f.pack(); Dimension screenSize = Toolkit.getDefaultToolkit ().getScreenSize(); int w = 420; int h = 140; pv.setLocation(screenSize.width/2 - w/2, screenSize.height/2 - h/2); pv.setSize(w, h); pv.setVisible(true); }

3864


What is swing delegation event model in java?

552


How to reload a jframe in java swing?

550


What is swing package in java?

522


What is swing api?

531