Employee details program in java

Employee details program in java as as below.

Here two classes are created

  1. Employee class
  2. EmployeeMain class

Details of these two classes are as below


This class contains various field of employees like id, fname, lname, address etc.

Its corresponding getter and setter method is created in program.

Employee.java is a java bean and it good example of java encapsulation.

fields of Employee object can not be directly accessible outside the class to access this we need getter and setter methods.

Default and parameterized constructor are created to initialize employee object.

toString() of Object class is overridden to convert object to String.

Some fields like hra, providentFund and grossSalary are calculated from basicSalary.

So user provides only basicSalary value and other derived values are calculated based on it.

Two different methods are used to initialize values(Parameterised constructor and setter methods).

So calculation of derived values are done inside constructor and in setter method.

Providing addDate value is optional for user it user does not provide this value constructor or setter method does this.


This class contain public static void main() (java main method) inside main tho objects of Employee class is created.

First object is created using parameterized constructor and object’s value is printer by overriding the toString() of Object class.

Second object is created using default constructor of employee and values are assigned using setter methods of class.

To print value of object getter method is used. Insted of using getter method toString() can also be used.

Its up to used which method he wants to use to set values in object.

Result of above program is

Employee details

If any one want to change value of any field then appropriate setter method needs to called

like want to update lname of employee object then use


this will assign new value to lname.

Hope you understand how to show Employee details program in java

Read More

  1. Database operations with employee details
  2. Constructors in Java- Type Overloading and examples