Java is an Object-Oriented Programming that James Gosling designed. It is a general-purpose programming language that is class-based and having concurrent programming features. It has multi-threading features too. It is a static, safe, and strongly typed programming language. It was developed and is maintained by Oracle Corporation (then Sun Corporation). Its’ file extension names are .java or .class. It first appeared in the year 1995. It is intended to develop applications that can be Written Once and Run Anywhere. It is most popular for the client-server kind of applications. It is licensed under GNU General Public License and Java Community Process. The latest version of Java is 10, which is released in March 2018.
The Java Programming Language is based on an Object-Oriented Programming Methodology or Paradigm that has different kinds of concepts such as Classes, Objects, Inheritance, Polymorphism, Encapsulation, and Abstraction which can be described as below:
ADVERTISEMENT Popular Course in this category PROGRAMMING LANGUAGES - Specialization | 54 Course Series | 4 Mock TestsThere are different applications of Object-Oriented Programming in Java and below are the examples in this conceptual area:
A class can be defined as below:
public class Employee { private int employeeId; private String employeeName; public int getSalary(int basicPay, int da, int hra) { int salary = basicPay + da + hra; return salary; } }
In the above class, employeeId, employee name and getSalary() method are the members of the class, whereas employeeId and employee name are the attributes or fields and getSalary() is the method where real work gets done.
An object can be created as below for the above class Employee.
Employee employeeObject = new Employee();
In the above line, an object is created using a new keyword, and Employee() is the empty arguments constructor used to create the object. The employee objects to the reference made to the class Employee.
This can be achieved by method overriding and overloading.
public int getSalary(int basicPay, int da, int hra) { int salary = basicPay + da + hra; return salary; }
In the above method, another argument can be added to the method getSalary() by adding into the parenthesis as below:
public int getSalary(int basicPay, int da, int hra, int bonus) { int salary = basicPay + da + hra + bonus; return salary; }
This can be achieved as below:
public class Employee { private int employeeId; private String employeeName; public int getEmployeeId() { return employeeId; } public void setEmployeeId(int employeeId) { this.employeeId = employeeId; } public String getEmployeeName() { return employeeName; } public void setEmployeeName(String employeeName) { this.employeeName = employeeName; } }
The above class Employee has two fields (private) and four methods (getters and setters) which will be used to access the above two private attributes.
This is the process of hiding the implementation functionality.
In the above method getSalary(), the internal function of the addition of all the components of a salary is hidden inside the method, and only this can be accessed by using the method name by passing the values as method arguments. In this way, the total salary will be obtained by passing the individual salary components to the method.
There are different and multiples areas of applications in the field of the Web world, Standalone, and many other areas for the Object-Oriented Programming in Java concept. The average utilization or application of object-oriented programming in Java has been in the top 5 positions for most of the enterprise applications and has been in almost every enterprise as of now is the most sought-after technology. There are huge numbers of tools available, such as IDEs, to develop applications using object-oriented programming in Java. Many companies are using Java-based applications for their requirements because of the ease of development and maintenance. The standalone apps developed in Java are mostly being used by many companies for their in-house tools They are developed based on Java Swing GUI toolkit and are now called Java FX in its recent version. The recent version of Java 8 provides great functional programming features and parallel processing capabilities with its Stream API.
This has been a guide to Object-Oriented Programming in Java. Here we have discussed the Different concepts and the applications of Object-Oriented Programming in Java. You may also look at the following article to learn more –
The above is the detailed content of Object Oriented Programming in Java. For more information, please follow other related articles on the PHP Chinese website!