#65 What is Interface in Java

  Рет қаралды 271,916

Telusko

Telusko

Күн бұрын

Check out our courses:
Java Full Stack and Spring AI - go.telusko.com...
Coupon: TELUSKO10 (10% Discount)
DevOps with AWS: From Basics to Mastery : go.telusko.com...
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : go.telusko.com...
Coupon: TELUSKO20 (20% Discount)
Udemy Courses:
Java:- bit.ly/JavaUde...
Spring:- bit.ly/SpringU...
Java For Programmers:- bit.ly/javaPro...
For More Queries WhatsApp or Call on : +919008963671
website : courses.telusk...
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/nav...
Java:- bit.ly/JavaUde...
Spring:- bit.ly/SpringU...
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

Пікірлер: 52
@DeeperRed-of1gp
@DeeperRed-of1gp 10 ай бұрын
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 9 ай бұрын
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.
@thusith-tec307
@thusith-tec307 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
Amezing explination everyone saying only theory u are the only one following practical manner ur having great explanation
@obaldalmeida6308
@obaldalmeida6308 Жыл бұрын
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
@daulitech219
@daulitech219 11 ай бұрын
I read Interface through a book but I couldn't understand it, until I found your video. Thanks
@projyoti7489
@projyoti7489 9 ай бұрын
What a type of teaching skills ! Mind-blowing
@Arsun-77
@Arsun-77 3 ай бұрын
Me videos lo examples tho concept inka baga ardm aythundi anna...❤
@AmarGrg
@AmarGrg Жыл бұрын
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?
@iqbalsingh3848
@iqbalsingh3848 5 ай бұрын
your video just blow my mind.. its crazy ... thanks for a lot of information...
@naveenagrawal2298
@naveenagrawal2298 23 күн бұрын
thanks for these tutorials . these all are really cool
@rajeshwarijindam-dx3xz
@rajeshwarijindam-dx3xz Жыл бұрын
Anna mi teaching baa super undhi
@adityasrinivas3069
@adityasrinivas3069 6 ай бұрын
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 6 ай бұрын
Thanks for the correction
@sriemandi3978
@sriemandi3978 Жыл бұрын
Merry Christmas Naveen bro
@alwinvj6487
@alwinvj6487 Жыл бұрын
Thanks for this video🤗
@manas332
@manas332 7 ай бұрын
Excellent explanation
@roshanekka8293
@roshanekka8293 11 ай бұрын
nice explanation
@mangaraj45
@mangaraj45 8 ай бұрын
That's not my age 💀🌚😅
@mohitx3g
@mohitx3g 2 ай бұрын
Bro's age is 43, and he written 44 😂
@Programing-lo3og
@Programing-lo3og 9 ай бұрын
Thanks You Sir
@Hemanth83439
@Hemanth83439 Жыл бұрын
kollada mona 👌
@nila-333
@nila-333 Жыл бұрын
Thank you so much
@ajayghode3602
@ajayghode3602 Ай бұрын
when we create interface. In interface all methods are 'public abstract' by default. So, no need to write public abstract. we need to define those methods in the class. Otherwise that class will become abstract. Again we need to creat concrete class and define methods. In the interface, we can decleare varibles but those variable will be final and static. So, we have to define those variables like int age=32; String area="Mumbai". Interface don't have memories in the heap. we are doing implements(class implements interface) so we implements only methods NOT variables. As interface don't have memory how can we create non-final or non-static variables in the main class so, we can not be able to change variables ' values.
@chouaibakni2828
@chouaibakni2828 2 ай бұрын
Thanks
@raghavsood768
@raghavsood768 Жыл бұрын
Notes: All variables inside interface are static and final
@mohamedmurshid9794
@mohamedmurshid9794 Жыл бұрын
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.🤗
@Nothingtosaymore
@Nothingtosaymore 8 ай бұрын
Thank you
@Ambitious675
@Ambitious675 Жыл бұрын
Thank you so much sir :)
@adityamishra_11
@adityamishra_11 Жыл бұрын
Are we take scanner (input) at the time of declaring any variables inside the interface.?
@adityamishra_11
@adityamishra_11 Жыл бұрын
@Telusko.
@VishnuSai-u2e
@VishnuSai-u2e 3 ай бұрын
Without out main() we can i print any statement?
@109abdulakram3
@109abdulakram3 Ай бұрын
hello sir,u told that class b implements class a only methods ...but i can acess B.name its is showing the variable name
@naveenagrawal2298
@naveenagrawal2298 23 күн бұрын
what does you ment by saying you dont get access to variables in implements . As I tried on my own we get access to interface variables in subclasses, but there are just staic final and public.
@srimantamondal8769
@srimantamondal8769 Жыл бұрын
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 Жыл бұрын
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 7 ай бұрын
You can disable it by going to settings -> Java hints -> None
@filmbuzz9419
@filmbuzz9419 8 ай бұрын
Can i implement another method in class B
@rohitgundam2275
@rohitgundam2275 5 ай бұрын
How is he able to create an object A (since this has the same name as the interface?)
@DSASimplified-zs6ll
@DSASimplified-zs6ll Ай бұрын
Bro They have defined the object "obj" with type A which is class name Which is implemented by interface
@hirenkansara77
@hirenkansara77 2 ай бұрын
👌👌👌👌👌
@sushmithakn6003
@sushmithakn6003 11 ай бұрын
Why this error come - failed to resolve main method code lens :inter faceis not a valid java identifier
@sheikhnasir3437
@sheikhnasir3437 7 ай бұрын
6:13 Funniest part 😂
@TochukwuVictor-qe4xd
@TochukwuVictor-qe4xd 8 ай бұрын
❤❤
@AbuIshaqAlShafii
@AbuIshaqAlShafii 11 ай бұрын
5:12
@JulieJulie-x6t
@JulieJulie-x6t 5 ай бұрын
🎉❤
@Hawkai-ro2hx
@Hawkai-ro2hx 6 ай бұрын
That's not my age was personal
@abhi._77
@abhi._77 Жыл бұрын
Nipora
#66 Need of Interface in Java
8:32
Telusko
Рет қаралды 169 М.
#61 Abstract Keyword in Java
12:09
Telusko
Рет қаралды 199 М.
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН
Java interface 🦅
7:51
Bro Code
Рет қаралды 226 М.
#53 Packages in Java
12:20
Telusko
Рет қаралды 259 М.
API vs SDK: What’s the Difference?
3:42
Klippa
Рет қаралды 18 М.
Harsh Truth of Java in 2024! Ft. Ultimate Java Developer @Telusko
28:46
I Spent 100 Hours Inside The Pyramids!
21:43
MrBeast
Рет қаралды 42 МЛН
How to Stop Procrastinating and Finally Take Action
16:31
Ali Abdaal
Рет қаралды 126 М.
Abstract Classes and Methods in Java Explained in 7 Minutes
7:00
Coding with John
Рет қаралды 581 М.
Stream API in Java
26:04
Telusko
Рет қаралды 388 М.
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН