0% found this document useful (0 votes)
59 views

Java Seminar 5

Static variables and methods in Java are associated with the class rather than objects. Static methods can access only static data and can be called directly using the class name without creating an instance. There are built-in packages in Java like java.lang and user-defined packages that are created by programmers. Exceptions in Java can be checked exceptions that must be handled or unchecked exceptions that are automatically handled by the JVM. Common exception types include runtime exceptions and input/output exceptions. Exception handling in Java uses try, catch, and finally blocks.

Uploaded by

Archana Akila
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Java Seminar 5

Static variables and methods in Java are associated with the class rather than objects. Static methods can access only static data and can be called directly using the class name without creating an instance. There are built-in packages in Java like java.lang and user-defined packages that are created by programmers. Exceptions in Java can be checked exceptions that must be handled or unchecked exceptions that are automatically handled by the JVM. Common exception types include runtime exceptions and input/output exceptions. Exception handling in Java uses try, catch, and finally blocks.

Uploaded by

Archana Akila
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

core java concepts

Static variables and static methods

Particular method common to all instances of class Also called as class level variables Static method can access only static data

Static variables and static methods

Syntax
Static Static

datatype variable name; returntype methodname(parameters); int a; int mul(int a, int b)

Static

Static

{ }

How to call static methods

We can directly the method using class name Classname.methodname; Sample.mul();

Objective of static member or method


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.

Built-in and user defined Packages

Java Application Programming Interface Packages(API):


Java.lang Java.util Java.io Java.awt Java.applet

Java User Defined Packages:


Packages

created by user and it can be imported in any java program

Java package hierarchy

Creation of user defined Package


Package packagename; Package app.empdetails; Public class Employee { }

Importing user defined package


Import app.empdetails.Employee; Public class Director extends Employee { }

Exception Handling

Exception Handling

Error
Compile

time error //syntax error

Logical

error // mistaken in loop error //only 3 element s present in the

Runtime

array but we are trying to execute 4th element

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

ArithmeticException ArrayoutofBoundException StringIndexoutofBoundException NullpointerException ArraystoreException OutofMemoryException SecurityException

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

You might also like