Professional Documents
Culture Documents
Java Seminar 5
Java Seminar 5
Particular method common to all instances of class Also called as class level variables Static method can access only static data
Syntax
Static Static
Static
Static
{ }
Member common to all instance of class Class level variables Only one copy of the member It avoid multiple instance to call the method Static method are accessed directly using class name
Java.math.*
methods)
Package(contains 80 static
Math.sqrt(a,b)
Class staticdemo { Static int a; Static void display() { Return a*a; } Psvm { int a; a=staticdemo.display(); System.out.println(a); } }
Packages
Collection of interface of classes Namespace for organizing classes and interface in a logical manner Each programmer can define their own namespace and place their code within that namespace, thus two classes that have exact same name are now distinguishable since they occur in different namespace.
Exception Handling
Exception Handling
Error
Compile
Logical
Runtime
Exception Handling
Error occurs during runtime of the program called exception Checked Exception: Program handles the exception Unchecked Exception: automatically handled by JVM
Exception Handling
Types of Exception
Runtime
Exception Exception
Input/Output
Exception Handling
Input/Output Exception:
File not found exception Stack overflow Class not found exception Number format exception
Runtime Exception
Exception Handling
try { } Catch { } Finally { }
Exception Handling
Messages:
getmessage(); getstacktrace(); PrintStacktrace();
Exception Handling
Class excepdemo { Psvm { int a=15; int b=5,c=5; Try { int result = a/ b-c; } Catch(ArithmeticException e) { System.out.println(Message+e.getmessage()); } } }
Thank you