Advanced Java Programming

Image
                          Advanced Java Programming Advanced Java Programming :-   Introduction to advance java   As most of us already know that if we want to make normal applications it  can be easily built using core Java concepts. But, when it we need to develop web applications, advanced Java fundamentals, like JSP, Servlets, JDBC etc. needed, so to add capabilities and features of the application advance java is essential for developers. Through the motive of this blog is to explain about Advanced Java, I will be giving you a complete insight into the fundamental concepts of Advance Java. Figure - 1.2 If you want to see complete video on this please  have a look the video below.                              Learn with Resh u Advanced Java Programming Course Figure - 1.3 I hope you understood by the slide why Advanced Java is essential. For your better understanding, I have divided this article int

Learn Complete OOPS Concepts in one Project

Learn Complete OOPS Concepts in one Project



 In this Page i will give a example Code for covering all oops concepts in only one single project.
                         
                       Class Model  
     
                           Code Example

Explanation:- 

Suppose there is a Organization which has many departments and many  Employees Some Employees are Part of  Some Departments  So In this Code example What i have created is A Organization Class Which is having Many Employees so One Employee Class and Employee is a part of Departments so We have Created one Departments ClassNow Organization, Department and Employee has some task to be done so for that i have created Interfaces for each one where i Have Defined tasks to be done by theses classes.

1. Organization.java

In This Organization Class below I have used Encapsulation concept to create getters and setters same i have created one default constructor and some variable of all kind of datatypes. I have created private methods as getters and setters.
1. 

package com.all.examples;

     public class Organization {
Organization(){
}
//Encapsulation
    private static String name = "Learn With Reshu";
private int id;
private boolean status;
private char grade;
private int numberOfEmployee;
private double growth; 

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public boolean isStatus() {
return status;
}

public void setStatus(boolean status) {
this.status = status;
}

public char getGrade() {
return grade;
}

public void setGrade(char grade) {
this.grade = grade;
}

public double getGrowth() {
return growth;
}

public void setGrowth(double growth) {
this.growth = growth;
}

public int getNumberOfEmployee() {
return numberOfEmployee;
}

public void setNumberOfEmployee(int numberOfEmployee) {
this.numberOfEmployee = numberOfEmployee;
}

public String getName() {
return name;
}


}


2. Employee.java :- 

In Employee class I have created one Parametrized Construction having two parameters growthrate and name and created some private getters and setters with variables defined.

2   

package com.all.examples;

public class Employee {

      Employee(double growthrate, String name){
       this.growthRate= growthrate;
       this.name = name;
}
      
    private String name;
  
   private int id;
  
   private boolean status;
  
   private char grade;
  
   private double salary;
  
   private double growthRate; 
  
  
   public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public boolean isStatus() {
return status;
}

public void setStatus(boolean status) {
this.status = status;
}

public char getGrade() {
return grade;
}

public void setGrade(char grade) {
this.grade = grade;
}

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
this.salary = salary;
}

public double getGrowthRate() {
return growthRate;
}

public void setGrowthRate(double growthRate) {
this.growthRate = growthRate;
}

}

  3. CallDepartments.java :- In this example Calldepartments.java class is used to show how can we extends abstract class Departments  and how can we override methods by this example i have explained about method overriding concepts  of Polymorphism in the method statusOfDeparment() 


3. 

package com.all.examples;

public class CallDepartments extends Departments {

@Override
public void statusOfDepartment() {
        CallDepartments cd = new CallDepartments();
cd.setStatus("Active");
System.out.println("Department status is " + cd.getStatus());
}

}

4 Departments.java :- 

Departments class is a Abstract class by this i am showing how can we define abstract class  and abstract method statusOfDepartment() which i have override in CallDeparments class.


4.

 package com.all.examples;

public abstract class Departments {
private String status ;

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}
public abstract void statusOfDepartment();

}

5. IOrganization.java, IDepartments and IEmployee  :- 

By this Interface i have defined some static final variables and abstract methods and public methods  IDepartments  interface is extending IEmployee, IOrganization Interfaces so by this way i have shown how can we extends Interfaces. 


5. 

 package com.all.examples;

import java.util.List;

public interface IOrganization {
public float revanuPerYear(List employees);

 public char gradeOfOrganization(Organization organization);
 
public boolean statusOfCompany(Organization organization);
}

6. 

package com.all.examples;

public interface IEmployee {
public static final char gradeAEmployee = 'A';
public static final char gradeBEmployee = 'B';
public static final char gradeCEmployee = 'C';
 public abstract double salaryPerMonth(Employee employee);
public boolean jobStatus(int id);
public char GradeOfEmployee(double Salary);
}

7.

 package com.all.examples;

public interface IDepartments extends IEmployee, IOrganization {
public static final double gradeAEmployeeSalary = 2000;
public static final double gradeBEmployeeSalary = 1000;
public static final double gradeCEmployeeSalary = 500;
public String nameOfDepartment(char grade); 

}

6. Main.java.- 

Main.java class extends Departments Interface so bedefault it should implements the methods define in Departments Interface and because IDepartments Interface has extends IEmployee and IOrganization Interface so Main class needs to implements Methods define in IOrganization and IEmployee class as well.

8.

 package com.all.examples;

import java.util.ArrayList;
import java.util.List;

public class Main implements IDepartments{
public static double bonus = 8.3;
public static void main(String[] args) {
Organization organization = new Organization();
Main m = new Main();
Employee em = new Employee(70.5, "Reshu");
Employee em1 = new Employee(60.5, "Ria");
Employee em2 = new Employee(80.5, "Jiya");
List employees= new ArrayList();
employees.add(em);
employees.add(em1);
employees.add(em2);
for(Employee employee : employees) {
if(employee.getGrowthRate()==80.5) {
employee.setGrade(IEmployee.gradeAEmployee);
employee.setId(1);
}else if(employee.getGrowthRate()==70.5) {
employee.setGrade(IEmployee.gradeBEmployee);
employee.setId(1);
}else if(employee.getGrowthRate()==60.5){
employee.setGrade(IEmployee.gradeCEmployee);
employee.setId(3);
}
    
double salary = m.salaryPerMonth(employee);
    boolean status= m.jobStatus(employee.getId());
m.GradeOfEmployee(salary);
System.out.println(employee.getName()+ " of "+ m.nameOfDepartment(employee.getGrade()) + "\n"+
" has grade "+employee.getGrade() + "\n"+ " has Id "+ employee.getId() + "\n"+ " of a Organization " + organization.getName() + 
"\n"+ " has salary per month "+ salary + "\n"+ " and job status " + status );
System.out.println("\n");
}
organization.setNumberOfEmployee(employees.size());

System.out.println("Grade of a organization is " + 
m.gradeOfOrganization(organization)+ " and " + " revanue is " + m.revanuPerYear(employees));
System.out.println("\n");
if( m.statusOfCompany(organization) == true) {
System.out.println("Organization is Active");
}else {
System.out.println("Organization is closed");
}
CallDepartments cd = new CallDepartments();
System.out.println("\n");
cd.statusOfDepartment();
}
@Override
public  double salaryPerMonth(Employee employee) {
// TODO Auto-generated method stub

if(employee.getGrade()==IEmployee.gradeAEmployee) {

   employee.setSalary(IDepartments.gradeAEmployeeSalary * bonus);

}else if(employee.getGrade()==IEmployee.gradeBEmployee) {

employee.setSalary(IDepartments.gradeBEmployeeSalary * bonus);

}else {

employee.setSalary(IDepartments.gradeCEmployeeSalary * bonus);
}

return employee.getSalary();
}

@Override
public boolean jobStatus(int id) {
// TODO Auto-generated method stub
boolean status;

if(id==1) {

status = true;
}else{

status = false;
}

return status;
}

@Override
public char GradeOfEmployee(double salary) {
// TODO Auto-generated method stub
char grade;

if(salary == (20000 * bonus)) {

grade=IEmployee.gradeAEmployee;

}else if (salary == (10000 * bonus)) {

grade=IEmployee.gradeBEmployee;
}else {

grade = IEmployee.gradeCEmployee;
}

return grade;
}

@Override
public float revanuPerYear(List employees) {
// TODO Auto-generated method stub
int numberofemployees = 0;
float revanue=0;
for(int i =0; i<=employees.size(); i++) {

numberofemployees++;
}
if(numberofemployees>2) {

revanue= 200000f;
}
return revanue;
}

@Override
public char gradeOfOrganization(Organization organization) {
// TODO Auto-generated method stub
if(organization.getNumberOfEmployee()< 2) {

organization.setGrade(IEmployee.gradeBEmployee);
return IEmployee.gradeBEmployee ;

}else {
organization.setGrade(IEmployee.gradeAEmployee);
return IEmployee.gradeAEmployee;

}

}

@Override
public boolean statusOfCompany(Organization organization) {
// TODO Auto-generated method stub

if(organization.getGrade()==IEmployee.gradeAEmployee) {

organization.setStatus(true);

return true;
}else {

organization.setStatus(false);
return false;
}

}

@Override
public String nameOfDepartment(char grade) {
// TODO Auto-generated method stub

if(grade== IEmployee.gradeAEmployee) {

    return "Sales Department";

}else if(grade== IEmployee.gradeBEmployee) {


return "HR Department";

}else {

return "forth class employee";
}
}


}

For Complete explanation in Hindi please visit my Youtube Channel 


Thanks For Watching!!!!

    
Recommended Posts:


·       Overriding in Java
·       Overloading in Java
·       Interfaces in Java
·       Loops in Java
·       Variables in Java

Advanced Java Programming

         Abstraction in Java
·       Encapsulation in java
·       What is Java
·       Enabling Remote Debug


Comments

Popular posts from this blog

Spring Core