Qhov txawv ntawm Pob thiab Interface hauv Java

Cov txheej txheem:

Qhov txawv ntawm Pob thiab Interface hauv Java
Qhov txawv ntawm Pob thiab Interface hauv Java

Video: Qhov txawv ntawm Pob thiab Interface hauv Java

Video: Qhov txawv ntawm Pob thiab Interface hauv Java
Video: Hmong New Song 2019 Xy Lee feat. SuabNag Yaj - Koj Yog Kuv Lub Neej (Official MV - 4K) 2024, Kaum ib hlis
Anonim

Qhov sib txawv tseem ceeb ntawm Pob thiab Interface hauv Java yog pob pab txhawm rau txheeb xyuas cov chav kawm kom nkag mus tau yooj yim thiab tswj tau yooj yim thaum Interface pab siv ntau yam qub txeeg qub teg thiab ua tiav kev paub daws teeb meem.

Java yog ib hom lus nrov tshaj plaws. Lub ntsiab kom zoo dua ntawm Java yog tias nws txhawb Object Oriented Programming. Cov txheej txheem no tso cai rau ua qauv rau cov khoom ntiaj teb tiag tiag hauv software. Ib chav kawm yog ib daim phiaj los tsim ib yam khoom. Txhua yam khoom muaj cov ntaub ntawv lossis cov teb los piav qhia cov yam ntxwv lossis cov khoom thiab cov txheej txheem los piav qhia tus cwj pwm. Kab lus no tham txog ob lub ntsiab lus ntsig txog OOP hauv Java hauv Java uas yog Pob thiab Interface.

pob hauv Java yog dab tsi?

Java muab ntau chav kawm. Khaws tag nrho cov chav kawm hauv ib lub nplaub tshev yuav nyuaj vim nws nyuaj rau kev nkag. Qhov no tuaj yeem cuam tshuam rau kev tswj hwm qhov program. Java siv tej pob khoom los npaj cov chav kawm. Nws zoo ib yam li daim ntawv tais ceev tseg. Java API pab pawg hauv cov pob ntawv sib txawv raws li kev ua haujlwm. Yog li ntawd, txhua lub pob muaj cov chav kawm sib xws.

Piv txwv pob hauv Java

Ib yam piv txwv pob muaj raws li hauv qab no. Lub pob java.io muaj cov tswv yim, tso zis txhawb cov chav kawm. Nws suav nrog Cov Ntaub Ntawv, PrintStream, BufferInputStream thiab lwm yam. Lub pob java.net muaj cov chav kawm sib txuas lus. Qee qhov piv txwv yog URL, Socket, ServerSocket. Lub pob java.awt muaj tag nrho cov chav kawm uas yuav tsum tau tsim kom muaj Graphical User Interfaces. Cov no yog ob peb Java API pob.

Thaum tus programmer xav siv ib chav kawm hauv qhov program, nws yuav tsum tau xa cov pob ntawd. Yog tias tus programmer xav siv BufferInputStream chav kawm hauv java.io pob, nws yuav tsum sau cov ntawv xa tawm raws li hauv qab no.

import java.util. BufferInoutStream;

nqe lus hauv qab no yuav import tag nrho cov chav kawm hauv pob khoom siv.

import java.util.;

Nws tseem ua tau los tsim cov neeg siv cov pob khoom.

pob neeg ua haujlwm;

public class Employee {

}

Raws li cov piv txwv saum toj no, tus neeg ua haujlwm yog lub npe pob. Chav Kawm Ua Haujlwm yog ib feem ntawm cov neeg ua haujlwm pob. Cov ntaub ntawv no txuag li Employee.java rau cov neeg ua haujlwm pob.

Tsis tas li ntawd, nws tuaj yeem xa cov chav kawm pej xeem los ntawm ib pob mus rau lwm qhov. Saib cov piv txwv hauv qab no.

Qhov txawv ntawm Pob thiab Interface hauv Java
Qhov txawv ntawm Pob thiab Interface hauv Java
Qhov txawv ntawm Pob thiab Interface hauv Java
Qhov txawv ntawm Pob thiab Interface hauv Java

Daim duab 01: Chav A

Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 2
Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 2
Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 2
Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 2

Daim duab 02: Chav B

Class A yog nyob rau hauv pob 1, thiab nws muaj cov txheej txheem pej xeem hu ua zaub. Chav B yog nyob rau hauv pob 2, thiab nws muaj cov txheej txheem tseem ceeb. Txawm tias lawv nyob hauv cov pob khoom sib cais; chav kawm B tuaj yeem tsim cov khoom ntawm chav kawm A los ntawm kev xa cov pob 1. Tom qab importing pob 1, chav kawm B tau nkag mus rau cov ntaub ntawv thiab cov txheej txheem ntawm chav kawm A.

Zuag qhia tag nrho, Pob hauv Java pab npaj cov ntaub ntawv qhov project. Qhov no yog qhov tseem ceeb heev thaum tsim cov kab ke loj vim tias nws tso cai rau khaws tag nrho cov ntaub ntawv hauv txoj hauv kev. Ntxiv rau qhov ntawd, cov pob khoom Java API tso cai rau cov programmer siv cov chav kawm uas twb muaj lawm.

Dab tsi yog Interface hauv Java?

Qee zaum tus programmer yuav tsis paub lub ntsiab lus ntawm txoj kev. Hauv qhov xwm txheej no, tus programmer tsuas tuaj yeem tshaj tawm txoj hauv kev. Ib txoj kev paub daws teeb meem yog ib txoj kev uas tsis muaj kev txhais. Nws tsuas muaj kev tshaj tawm xwb. Thaum muaj tsawg kawg yog ib txoj kev paub daws teeb meem, chav kawm ntawd dhau los ua chav kawm paub daws teeb meem. Ntxiv mus, chav kawm paub daws teeb meem tuaj yeem muaj cov kev paub daws teeb meem nrog rau cov txheej txheem tsis paub daws teeb. Tus programmer tsis tuaj yeem tsim cov khoom tawm ntawm cov chav kawm paub daws teeb meem.

Thaum ib chav kawm txuas ntxiv chav kawm paub daws teeb, chav kawm tshiab yuav tsum txhais tag nrho cov kev paub daws teeb meem hauv chav kawm paub daws teeb. Hauv lwm lo lus, xav tias chav kawm paub daws teeb meem A muaj ib txoj kev paub daws teeb meem hu ua zaub. Chav B txuas ntxiv chav A. Ces chav B yuav tsum txhais cov qauv qhia.

Piv txwv ntawm Interface hauv Java

Xav tias ob qho A thiab B yog cov chav kawm paub daws teeb meem. Yog tias chav kawm C txuas ntxiv A thiab B, chav kawm C yuav tsum tau txhais cov kev paub daws teeb meem ntawm ob chav kawm. Qhov no yog ntau yam qub txeeg qub teg. Java tsis txhawb nqa ntau yam qub txeeg qub teg. Txhawm rau siv nws, tus programmer yuav tsum siv interfaces. Yog tias A thiab B yog qhov sib txuas, ces chav kawm C tuaj yeem siv lawv. Saib cov piv txwv hauv qab no.

Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 3
Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 3
Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 3
Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 3

Daim duab 03: Interface A

Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 4
Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 4
Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 4
Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 4

Daim duab 04: Interface B

Tus interface A muaj cov qauv qhia txog kev paub daws teeb meem, thiab interface B muaj cov qauv kev paub daws teeb meem.

Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 5
Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 5
Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 5
Qhov txawv ntawm Pob thiab Interface hauv Java_Figure 5

Daim duab 05: Chav Kawm C

Class C siv ob qho tib si A thiab B interfaces. Yog li, nws yuav tsum txhais ob txoj hauv kev.

Qhov tseem ceeb sib txawv ntawm pob thiab Interface hauv Java
Qhov tseem ceeb sib txawv ntawm pob thiab Interface hauv Java
Qhov tseem ceeb sib txawv ntawm pob thiab Interface hauv Java
Qhov tseem ceeb sib txawv ntawm pob thiab Interface hauv Java

Daim duab 06: Txoj Kev Tseem Ceeb

Tam sim no nyob rau hauv txoj kev tseem ceeb, nws muaj peev xwm tsim ib qho khoom ntawm C thiab hu rau ob txoj kev. Ib yam li ntawd, kev sib cuam tshuam pab siv ntau yam qub txeeg qub teg hauv Java.

Lwm yam tsis yog ntau yam qub txeeg qub teg, kev sib cuam tshuam pab kom ua tiav qhov kev xav paub. Nws yog ib lub tswv yim loj hauv OOP. Abstraction tso cai rau nkaum cov ntsiab lus ntawm kev siv thiab qhia tsuas yog kev ua haujlwm rau tus neeg siv. Tsis tas li ntawd, nws tso cai rau tsom mus rau qhov khoom ua dab tsi es tsis yog nws ua li cas. Raws li ib qho kev sib txuas muaj cov kev paub daws teeb meem, nws pab khaws cov ntaub ntawv abstraction.

Qhov txawv ntawm Pob thiab Interface hauv Java yog dab tsi?

Pob yog ib pawg ntawm cov chav kawm muaj feem xyuam nrog kev tiv thaiv kev nkag mus thiab kev tswj hwm lub npe. Interface yog ib hom kev siv zoo ib yam li cov chav kawm uas yog sau los ntawm kev paub daws teeb meem. Pob pab kom categorize cov chav kawm methodically nkag mus thiab tswj tau yooj yim. Ntawm qhov tod tes, Interface pab ua ntau yam qub txeeg qub teg thiab ua kom tiav abstraction. Qhov no yog qhov sib txawv tseem ceeb ntawm Pob thiab Interface hauv Java. Tsis tas li ntawd, txoj hauv kev los sau ib pob yog nyob rau hauv cov ntawv me xws li java.util, java.awt. Yog hais tias lub npe ntawm lub interface yog Area, ces nws yog sau nyob rau hauv, interface Area.

Qhov txawv ntawm Pob thiab Interface hauv Java hauv Tabular Form
Qhov txawv ntawm Pob thiab Interface hauv Java hauv Tabular Form
Qhov txawv ntawm Pob thiab Interface hauv Java hauv Tabular Form
Qhov txawv ntawm Pob thiab Interface hauv Java hauv Tabular Form

Summary – Pob vs Interface hauv Java

Qhov txawv ntawm Pob thiab Interface hauv Java yog pob pab txhawm rau txheeb xyuas cov chav kawm kom nkag mus tau yooj yim thiab tswj tau yooj yim thaum Interface pab ua ntau yam qub txeeg qub teg thiab ua kom tiav abstraction.

Pom zoo: