Pages

Java Methods

Methods
Definition

Behavior (Methods) : When a programmer creates a class, she creates methods for that class. Methods are where the class' logic is stored. Methods are where the real work gets done. They are where algorithms get executed, and data gets manipulated.


Difference Between Instance Method and Static Method

A class is a collection of Methods. We have two types of data members they are

1. Instance / Non Static Methods
2. Static Methods

Instance Methods Static Methods
1. Instance methods are always recommended to perform repeated operations like reading records from the file, reading records from the DB 1. Static methods are always which are recommended to perform one operation like opening the files, obtaining a DB Connection.
2. Programmatically instance methods definitions should not be preceded by a keyword static. 2. Programmatically static methods definitions must be preceded by static keyword.
3. Each and every instance method must be access with respective Object name. 3. Each and every static method must be accessed with respect class name.
4. Result of instance method is not sharable. 4. Result set of static method always sharable.