Java 是 James Gosling 設計的物件導向程式設計。它是一種基於類別並具有並發程式設計功能的通用程式語言。它也具有多線程功能。它是一種靜態、安全、強型別的程式語言。它由 Oracle 公司(當時的 Sun 公司)開發和維護。其檔案副檔名是.java或.class。它首次出現於 1995 年。它的目的是開發可以編寫一次、隨處運行的應用程式。它在客戶端-伺服器類型的應用程式中最受歡迎。它根據 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中文網其他相關文章!