This document introduces Java basics including syntax for defining classes with methods, object instances, class diagrams, method binding and overriding. It also covers exception handling with keywords like throw and throws. Throw is used to explicitly throw an exception while throws is used to signal and propagate checked exceptions in a method signature by listing the exception classes. The document concludes with a brief mention of object-oriented programming features in Java.
9. Difference between throw and throws
No. throw throws
1) In Java, the throw keyword is used to
explicitly throw an exception.
In Java, the throws keyword is used to
signal the occurrence of an exception.
2) Throwing alone will not propagate
checked exceptions.
Throws can be used to propagate checked
exceptions.
3) An instance follows the throw. Throws is immediately followed by class.
4) Throws is immediately followed by
class.
The keyword throws is used in the method
signature.
5) You can't throw several exceptions at
the same time.
Multiple exceptions can be declared. e.g.
public void method()throws
IOException,SQLException.