Posts

Showing posts from October 28, 2010

about user defined exception in Java

User defined exceptions may be implemented by defining a new exception class by extending the Exception class. public class MyException extends Exception { /* class definition of constructors goes here */ public MyException() { super(); } public MyException (String errorMessage) { super (errorMessage); } } Throw and/or throws statement is used to signal the occurrence of an exception. Throw an exception: throw new MyException(“I threw my own exception.”) To declare an exception: public myMethod() throws MyException {…}

about Exceptions in Java

Exceptions in Java -     An Exception is phenomenal condition, which can comes your program when program is executed. And this condition interrupt with program's normal flow.     When any program face the exceptional condition, an exception object is made by JVM and program will be terminate.             For prevent the termination of program, There is need to handle this situation.     There are three type of exceptional event occurs.     1)Error 2)Checked Exceptions 3)Unchecked Exceptions Errors - Error can be occurs for network failure, Hardware failure or any other reason besides your programs. So you can not handle this through program code. Checked Exceptions -     Java compiler checks your code at compile time. If any exception occurs in this time error handler read this at compile time. This is called checked exceptions.     IOException  are in the checked Exception. Unchecked Exceptions -     Unchecked exception occurs at runtime of your application. Th

about Java Garbage Collector

Java Garbage Collector -       Garbage Collector in Java working for release the memory form waste (unreachable) object. Garbage Collector works with heap memory.               Any Object is created in Java it goes to the heap memory. When this object is being waste or unreachable then Garbage Collector release memory from its. Understand about  waste or unreachable object -         String s  = new String(“Albert”);     String s1 = new String (“Another”);     s1=s ;            in this case new String (“Another”); has been waste object. Then  Garbage collector will release the memory form this object.      Garbage Collector called by JVM directly. You can not force for release the memory. You can request to Garbage Collector through System.gc() method.     For tracing the event of Garbage Collection use this command     -verbose:gc

Recent Post

Recent Posts Widget