#65 What is Interface in Java

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ม.ค. 2023
  • Check out our courses:
    Enterprise Java Spring Microservices: go.telusko.com/enterpriseJava
    Coupon: TELUSKO10 (10% Discount)
    Master Java Spring Development : bit.ly/java-spring-cloud
    Coupon: TELUSKO20 (20% Discount)
    Udemy Courses:
    Java:- bit.ly/JavaUdemyTelusko
    Spring:- bit.ly/SpringUdemyTelusko
    Java For Programmers:- bit.ly/javaProgrammers
    For More Queries WhatsApp or Call on : +919008963671
    website : courses.telusko.com/
    In this lecture we will learn:
    - What is an interface in java?
    - Use of interface
    - implements keyword in an interface
    - Variables in an interface
    #1
    Interface:-
    In an abstract class, we can have both abstract methods as well as normal or concrete methods.
    - If your class has only abstract methods then instead of using class, you can simply use an interface in place of it.
    - Interface is not any class.
    - Every method in an interface is public and abstract by default.
    - Even if you do not use two keywords (public and abstract) with methods then also it will not give an error in an interface. By default, it will consider all methods as public and abstract.
    - We cannot instantiate an interface.
    - Interface only shows the design and it does not provide any implementation.
    - To provide an implementation of methods, you need to create a class and instantiate it also.
    e.g,
    interface A
    {
    methods()----
    }
    #2
    implements keyword:-
    To implement an interface, we use the keyword - implements.
    - If you use the implements keyword with class, then it is compulsory to give an implementation of all the methods that are defined in an interface.
    - If you do not give an implementation of all methods then it will make your class an abstract class by default.
    - So, to make a concrete class, you have to give the implementation of all methods present in an interface.
    e.g.,
    class B implements A
    {
    methods() {
    statement;
    }
    ------
    }
    #3
    Variables in an interface:-
    - We can call the methods of an interface by creating an object of the class that implements an interface.
    - We can also declare variables in an interface.
    - All the variables in an interface are final and static by default.
    - So, we first have to initialize the variables in an interface.
    - As a variable is static in an interface, then you do not need to create an object for it. You can directly call the variable by using the interface name.
    e.g., A.area; (here, area is a variable initialized in an interface)
    - As the variable is final, you can not change the value of that variable after initializing it once.
    -Interface does not have its own memory in the heap.
    Github repo : github.com/navinreddy20/Javac...
    Java:- bit.ly/JavaUdemyTelusko
    Spring:- bit.ly/SpringUdemyTelusko
    More Learning :
    Java :- bit.ly/3x6rr0N
    Python :- bit.ly/3GRc7JX
    Django :- bit.ly/3MmoJK6
    JavaScript :- bit.ly/3tiAlHo
    Node JS :- bit.ly/3GT4liq
    Rest Api :-bit.ly/3MjhZwt
    Servlet :- bit.ly/3Q7eA7k
    Spring Framework :- bit.ly/3xi7buh
    Design Patterns in Java :- bit.ly/3MocXiq
    Docker :- bit.ly/3xjWzLA
    Blockchain Tutorial :- bit.ly/3NSbOkc
    Corda Tutorial:- bit.ly/3thbUKa
    Hyperledger Fabric :- bit.ly/38RZCRB
    NoSQL Tutorial :- bit.ly/3aJpRuc
    Mysql Tutorial :- bit.ly/3thpr4L
    Data Structures using Java :- bit.ly/3MuJa7S
    Git Tutorial :- bit.ly/3NXyCPu
    Donation:
    PayPal Id : navinreddy20
    www.telusko.com
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 39

  • @thusith-tec307
    @thusith-tec307 ปีที่แล้ว +25

    Today I subscribed you after watching this video. Your explanation and English pronouncing are better than others. I respect you my new Teacher ❤. Love from Sri Lanka

  • @jibonjibon8231
    @jibonjibon8231 ปีที่แล้ว +9

    Your Process of explaining and the step by step developed example is just blowing my minds. Tomorrow is my java final exam. I have regrate that why I didn't follow you from before! Your teaching system is well pre-planed, clear.
    I have a request, plz don't stop making tutorial. Keep doing by this way of explaining. Need Python ,framework, Algorithm from you.

  • @ramyapinapothu9901
    @ramyapinapothu9901 11 หลายเดือนก่อน +2

    Amezing explination everyone saying only theory u are the only one following practical manner ur having great explanation

  • @DeeperRed-of1gp
    @DeeperRed-of1gp 3 หลายเดือนก่อน +4

    At 7:26 it is said that "we are doing implement not extends so only methods are available and variables are not available". Actually, regardless of what we do implementation of interface or extends of parent class, the variables also gets passed on in child. When we do Subclass obj = new Subclass(); we can see that variables are accessible. The thing with interface is that as the variables are final, so we can't change it. But it is available in child class! Maybe it was just Slip of tongue by Telusko!
    Enjoying the series so much! Thank you for posting it!❤

    • @DeeperRed-of1gp
      @DeeperRed-of1gp 3 หลายเดือนก่อน +1

      Actually according to GPT , In Java, static fields declared in interfaces are accessible through the implementing class, not inherited. When we access B.age in above example in main method, it's not due to inheritance, but rather because interface fields are implicitly public, static, and final.
      In our case, age is a static field of the A interface, which means it can be accessed using the interface name itself (A.age) or through any class that implements the interface (B.age).
      So, while it may seem like the field is inherited, it's actually being accessed through the interface.
      This behavior allows for constants and other shared data to be accessed consistently through the interface, regardless of the implementing class.

  • @rapidken
    @rapidken ปีที่แล้ว +7

    Great playlist! There are some other videos in this course playlist that explain the terms used in this one. Feel free to give them a look if you're in need of a quick refresh!
    - Abstract and Anonymous class: th-cam.com/video/4YnGBOyA2Q4/w-d-xo.html
    - Static Variable: th-cam.com/video/7HYaQOyvw7Q/w-d-xo.html
    - Static variable Example: th-cam.com/video/7HYaQOyvw7Q/w-d-xo.html
    - Heap: th-cam.com/video/_GK3WoFFKUE/w-d-xo.html
    - Heap memory: th-cam.com/video/cV-sOpOgof8/w-d-xo.html

  • @obaldalmeida6308
    @obaldalmeida6308 ปีที่แล้ว +1

    I have been watching Navin sirs old vedios and found this gem ....good to know you are doing well....looking fresh sir ✨ with an upgrade

  • @AmarGrg
    @AmarGrg ปีที่แล้ว +4

    Hi @Telusko thank you very much for all those wonderful videos. Just started learning java and I am already learning alot. Have a quick question for you, while doing PHP we used to write interfaces for the model entity class, what do you think about it? what might be the pros and cons?

  • @projyoti7489
    @projyoti7489 2 หลายเดือนก่อน

    What a type of teaching skills ! Mind-blowing

  • @alwinvj6487
    @alwinvj6487 ปีที่แล้ว +1

    Thanks for this video🤗

  • @mangarajmohanty12
    @mangarajmohanty12 หลายเดือนก่อน +11

    That's not my age 💀🌚😅

  • @daulitech219
    @daulitech219 4 หลายเดือนก่อน +1

    I read Interface through a book but I couldn't understand it, until I found your video. Thanks

  • @manas332
    @manas332 หลายเดือนก่อน

    Excellent explanation

  • @Programing-lo3og
    @Programing-lo3og 3 หลายเดือนก่อน +1

    Thanks You Sir

  • @rajeshwarijindam-dx3xz
    @rajeshwarijindam-dx3xz ปีที่แล้ว +2

    Anna mi teaching baa super undhi

  • @roshanekka8293
    @roshanekka8293 5 หลายเดือนก่อน +1

    nice explanation

  • @edgbaston149
    @edgbaston149 ปีที่แล้ว +1

    Thank you so much

  • @sriemandi3978
    @sriemandi3978 7 หลายเดือนก่อน +1

    Merry Christmas Naveen bro

  • @Nothingtosaymore
    @Nothingtosaymore 2 หลายเดือนก่อน

    Thank you

  • @Hemanth83439
    @Hemanth83439 ปีที่แล้ว +2

    kollada mona 👌

  • @Ambitious675
    @Ambitious675 ปีที่แล้ว +2

    Thank you so much sir :)

  • @srimantamondal8769
    @srimantamondal8769 ปีที่แล้ว +3

    Can someone tell me why inside println(), "x:" is used. This variable "x" is not declared anywhere and is not giving any error. Also if it is not a variable then let me know what it is.

    • @santhosh-benz7
      @santhosh-benz7 ปีที่แล้ว +4

      Here inside the println(), "x:" is used , it is provided by the IDE ( here VS code ) , which means it remains you to code here or pass the parameter , which makes you aware about the line of code . It needs some thing based on the code . I think you can Understand 😅

    • @shubhrajit2117
      @shubhrajit2117 หลายเดือนก่อน +1

      You can disable it by going to settings -> Java hints -> None

  • @adityamishra_11
    @adityamishra_11 6 หลายเดือนก่อน

    Are we take scanner (input) at the time of declaring any variables inside the interface.?

  • @sushmithakn6003
    @sushmithakn6003 5 หลายเดือนก่อน

    Why this error come - failed to resolve main method code lens :inter faceis not a valid java identifier

  • @adityasrinivas3069
    @adityasrinivas3069 5 วันที่ผ่านมา

    Video #66. and #65 should be interchanged, i.e, explain what is an interface and then explain why it is important. It will be easier to understand.

    • @Telusko
      @Telusko  5 วันที่ผ่านมา

      Thanks for the correction

  • @AYANCSE-pg7zu
    @AYANCSE-pg7zu ปีที่แล้ว

    Thanks

  • @TochukwuVictor-qe4xd
    @TochukwuVictor-qe4xd 2 หลายเดือนก่อน

    ❤❤

  • @filmbuzz9419
    @filmbuzz9419 หลายเดือนก่อน

    Can i implement another method in class B

  • @raghavsood768
    @raghavsood768 ปีที่แล้ว +2

    Notes:
    All variables inside interface are static and final

    • @mohamedmurshid9794
      @mohamedmurshid9794 ปีที่แล้ว +1

      and public by default too. all the methods inside interface are public and abstract.

    • @mehakfatima6531
      @mehakfatima6531 ปีที่แล้ว

      ​@@mohamedmurshid9794 well they have to be public so that the abstract methods inside it can be used further in derived classes or the whole point of creating a interface will be nothing

    • @mohamedmurshid9794
      @mohamedmurshid9794 ปีที่แล้ว

      @@mehakfatima6531 yep true. But i just added those are public too. Not only static and final. Thank you for this comment.🤗

  • @sheikhnasir3437
    @sheikhnasir3437 หลายเดือนก่อน

    6:13 Funniest part 😂

  • @AbuIshaqAlShafii
    @AbuIshaqAlShafii 4 หลายเดือนก่อน

    5:12

  • @abhi._77
    @abhi._77 ปีที่แล้ว

    Nipora