Java 是 James Gosling 设计的面向对象编程。它是一种基于类并具有并发编程功能的通用编程语言。它也具有多线程功能。它是一种静态、安全、强类型的编程语言。它由 Oracle 公司(当时的 Sun 公司)开发和维护。其文件扩展名是.java或.class。它首次出现于 1995 年。它的目的是开发可Written Once and Run Anywhere 的应用程序。它在客户端-服务器类型的应用程序中最流行。它根据 GNU 通用公共许可证和 Java 社区进程获得许可。 Java 的最新版本是 10,于 2018 年 3 月发布。
Java 编程语言基于面向对象的编程方法或范式,具有不同类型的概念,例如类、对象、继承、多态性、封装和抽象,可描述如下:
广告 该类别中的热门课程 编程语言 - 专业化 | 54 课程系列 | 4 次模拟测试Java 中面向对象编程有不同的应用,以下是该概念领域的示例:
类可以定义如下:
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; } }
在上面的类中,employeeId、employee name 和 getSalary() 方法是类的成员,而 employeeId 和 employee name 是属性或字段,getSalary() 是完成实际工作的方法。
可以如下为上述 Employee 类创建一个对象。
Employee employeeObject = new Employee();
在上面的行中,使用 new 关键字创建了一个对象,而 Employee() 是用于创建该对象的空参数构造函数。员工反对对 Employee 类的引用。
这可以通过方法重写和重载来实现。
public int getSalary(int basicPay, int da, int hra) { int salary = basicPay + da + hra; return salary; }
在上面的方法中,可以通过添加到括号中来将另一个参数添加到方法 getSalary() 中,如下所示:
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 –
以上是Java 中的面向对象编程的详细内容。更多信息请关注PHP中文网其他相关文章!