Java employee details program
In
Java
, the most searching program is of employee details. An employee is an entity that can have several attributes like id, name, and department, etc. In order to create a java employee details program, we need to create a class for the employee entity and create properties of the employees.
We will create the getter and setter for getting and setting the values of the properties. In the main class, we will create the object of the Employee class, and by using its object, we will access the properties of the Employee class.
The code of the employee details program is very easy to understand. Let's implement the code of the above theory.
EmployeeDetails.java
package JavaTpoint.JavaObjectToJSON;
//Creating Employee class
class EmployeeDetails {
//Creating properties of Employee class
int emp_id, salary;
String name, address, department, email;
//Getter and setters for getting and setting properties
public int getEmp_id() {
return emp_id;
public void setEmp_id(int emp_id) {
this.emp_id = emp_id;
public int getSalary() {
return salary;
public void setSalary(int salary) {
this.salary = salary;
public String getName() {
return name;
public void setName(String name) {
this.name = name;
public String getAddress() {
return address;
public void setAddress(String address) {
this.address = address;
public String getDepartment() {
return department;
public void setDepartment(String department) {
this.department = department;
public String getEmail() {
return email;
public void setEmail(String email) {
this.email = email;
//Overriding toString() method
@Override
public String toString() {
return "Employee [emp_id = " + emp_id + ", salary = " + salary + ", name = " + name + ", address = " + address
+ ", department = " + department + ", email = " + email + "]";
//Creating main class
public class Employee{
//main() method start
public static void main(String args[]) {
//Creating object of EmployeeDetails class
EmployeeDetails emp = new EmployeeDetails();
//Setting values to the properties
emp.setEmp_id(101);
emp.setName("Emma Watson");
emp.setDepartment("IT");
emp.setSalary(15000);
emp.setAddress("New Delhi");
emp.setEmail("Emmawatson123@gmail.com");
//Showing Employee details
System.out.println(emp);
//Getting salary using getter
int sal = emp.getSalary();
int increment = 0;
//Incrementing salary based on condition
if ((sal >=1000) && (sal <=1500))
//incrementing salary 2%
increment += (sal * 2)/100;
sal = sal+increment;
emp.setSalary(sal);
System.out.println("\n Salary is incremented \n");
System.out.println(emp);
}else if ((sal >=1500) && (sal <=20000)){
//incrementing salary 5%
increment += (sal * 5)/100;
sal = sal+increment;
emp.setSalary(sal);
System.out.println("\n Salary is incremented \n");
System.out.println(emp);
}else {
System.out.println("\n Salary is not incremented \n");
System.out.println(emp);
Output
Employee [emp_id = 101, salary = 15000, name = Emma Watson, address = New Delhi, department = IT, email = [email protected]]
Salary is incremented
Employee [emp_id = 101, salary = 15750, name = Emma Watson, address = New Delhi, department = IT, email = [email protected]]
In the above program, we have created limited properties of the Employee class. You can create the number of properties for the Employee class. In the above code, we not only show the employee details but also access the property value using the setters. We update the value of a property based on the conditions too.
Next TopicJava is case sensitive explain