For those who doesn't understand why we used static term::: Everytime we call constructor we want to member increase. If we don't put static in front of it, first time we call it it will be 1 before printing so it will say member=1, but when we create second object. Member will be again 0, then when it goes to constructor in it, it will increase to 1 again, so it doesn't count how we want. It starts from zero, but we want number increase from where we left. I hope this helps.
If you don't understand something watch this tutorial ten or hundred times until you finaly understood. Bucky, your turorials is correctly and very helpful
"What's up guys, welcome to your 46th Jafh tutorial :)" Bucky, your tutorials rock so much! :) I wish schools were as awesome as your tutorial videos, maybe then people would actually learn something in school :)
"Hottie with body, cutie with booty", said it so calm. I was laughing my ass off, you're awesome. You're video actually helped me a lot as I was struggling with object.
What he does is good java programming practice. He hides away the variables from direct access via "private" which is almost always good. He initializes the important variables in the "tuna"-class-scope, then he makes sure to assign values to them via the constructor which is always called when an object is created. The parameter names of the contructor are different from the more global ones for convenience: You could alsocall them like the global ones but then you need to "this.first= first")
The further we get into the tutorials, less and less people are watching them. I see lots of people are dropping out. Not me though. I am in it to win it! Gonna move on to your intermediate tutorials after this
no, ill try to explain, the class "tuna" is a constructor for objects, when you make objects in your main ("apples") each object get's his own variables, but when you put "static" on a variable, it relates to all object made from "tuna", meaning it's more related to the class tuna than a specific object.
for those who don't understand why static is useful here, here's what happens if I do "private int members": First "members" is 0. Then "members++" says 0 + 1 = 1. On the second object, the same thing happens: members resets back to 0, and then adds 1 again to get 1. It resets because it isn't static. Static fixes this issue. Without Static, it would say "1 member in the club" for each person.
The static member-variable only increments when an object of this specific class is created. Furthermore, you don't need to initialize the object directly in your main method. You could initialze it in the global variables of the class which contains the main method or another static class or another object of a non-static class. If you are into concurrent programming, you might find out that "static" is not always enough to guarantee the variable manipulation, but first things first.
You still have to keep in mind that a static variable inside a class still belongs to that class. A "member" variable of class "tuna", which has a scope of the whole program, is not the same as the "member" variable of another class. So, consider you have objects of the class "tuna" and objects of an almost identical class called "salmon". Accessing both member variables from outside their class-members makes it obvious that they are different: "tuna.member", "salmon.member".
You could do that without a static variable but it has to be outside the objects of the class "tuna". So, whenever your initiualize another "tuna"-object you might increment a predefined member variable which is is positioned somewhere else. You might as well write an handler that creates new objects of the "tuna"-class automatically and increments them in the same way.
So you want to keep the number of members till the next program run? You have to save the member variable to a file either at the end of your program or whenever the member variable is altered. To make your program "remind" itself of the saved variables content in the next run, you have to load the file content with your member value into the member variable. Lookup i/o-streams (input and output streams and file handling) for ways to accomplish this.
from PR-Brazil.. awesome man.. thanks !!! .. "globlalizando conhecimento.. ESSAS VIDEOS AULAS VINDAS DE TODA PARTE DO MUNDO.. EH MUITO LEGAL ISSO" !! i liked tuna´s names :) simple example.. GREAT TUTORIAL !
If it wasn't static you would need to create an object of whatever class the main method is in (apples in this case). Since the main method is the first bit of code that runs, it's not possible to create an object before entering the main method. If it is static, it allows you to use the method without an object. Your comment was 7 months ago and nobody replied to you, so I don't know if you got an answer yet but at the very least this could help other people if they don't understand.
You can do it either way. I've once asked a the programmer community on stackoverflow if you should stick to "this." everytime or just in special cases. It was a lively discussion. However, more people preferred to use something like "firstName = fn" but only for methods beside the constructor. It depends on your preferences.
This is possible of course. You have to either use the command line argument (it's a variable too) and extract the user information or you have other means by user input like Keyevents or text inputted into Swing-GUI-components.
It's one of the slowest programming languages, but very good to learn first. Soem people say that C is the best to learn first, bet the problem is that this is useless (unless you are linux user, but still u can use C++)
Erikas Rudinskas Late reply but, you should consider learning C++ before C C++ is like a updated version of C it has more efficient funtions and more stuff.
John Bernhardsson C is procedural, its mostly used for embedded systems and functional programming. C++ is object oriented, they are completely different but some of the syntaxes are similar.
C was like hell to me. It may be the industry standard but it is boring as it gets and so time consuming. Although it does teach alot about how computers work.
when it makes sense to have the same name for a class variable and local variable one can specify the class variable by using 'this'. for example you could have still used first and last (as oppose to fn and ln which are less descriptive) for the constructor arguments, and simply wrote 'this.first = first;' and 'this.last = last;' int the body of the constructor.
Here's a question: How do I know when to put static in my methods? thanks to my IDE showing me error messages when i forget it i manage, but it'd be nice to know if there are any specific things to remember or any tricks. Thx for any advice :D
you could in fact do that. that practice is a key part of a programming technique called singleton class. Which is where you instantiate one and only one instance of a class using static methods and and variables to obtain a reference to the singleton class. There is also more that you could do but that is one of the more interesting techniques.
@xVerbati To study this stuff, I make programs of my own that incorporate all of the previous methods included. I just take notes and then make one big program that does everything he taught us to do. I also like to erase everything he typed out that I copied and type it on my own again, that really helps.
Because there can only be one main function in a java program and it is surrounding all components of that function, except for being part of a class as well (because of the object-oriented concept of Java). If you start a program, you start one and only one program of this type.
@sohaeb rehan He said "SHOULD", not "SHALL". It's optional, but if you want a job, you better do things right. Using Uppercase to begin a class name might just give you the edge for getting hired.
I don't know why he didnt show you but take out the static and leave it as "private int members = 0" and see what happens. it will give you a better understanding of what the was talking about.
@lNUMPUN I'm no pro but I think it's because the values of the arguments only last as long as it's method is running, and when that method is over, the values are lost. So he stores them in a instance variable or whatever it's called. I might be wrong (probably am).
For those who doesn't understand why we used static term::: Everytime we call constructor we want to member increase. If we don't put static in front of it, first time we call it it will be 1 before printing so it will say member=1, but when we create second object. Member will be again 0, then when it goes to constructor in it, it will increase to 1 again, so it doesn't count how we want. It starts from zero, but we want number increase from where we left.
I hope this helps.
thanks
thanks man.. I didn't understand it until I read this. :)
thank you
basically, the static keyword retains the value from previous function.. right..?
@@vathsan3906 previous object
he's literally objectifying women in this video :P
PIneapple29 and pot pies. Can't forget the pot pies.
and calling them tunas
+PIneapple29 Only Bucky could get away with objectifying women like that.
+PIneapple29 Damn, I wanted to make that joke. Meh, thumbs up anyway.
+PIneapple29 : Well, it is an Object Oriented Program
To anyone whos struggling static members belong to a class rather than a specific instance(aka object) of the class.
You forgot to put commas and dots in your sentence. It makes difficult to understand it.
I love the comments starting with "For those who doesn't understand". I always searching for them. That kind of people are a bless.
Treating women as objects!
Hahaha
... I dunno whether to laugh my ass off or look at you like you just made a bad joke.
both
Well women tend to treat men as object of type ,,wallet" all the time.
tuna objects haha!
Half of the reason i watch these is to laugh
*your mom
These are the best tutorials on youtube for learning java
If you don't understand something watch this tutorial ten or hundred times until you finaly understood. Bucky, your turorials is correctly and very helpful
"Hotty with the body, cuty with the booty!!" I laughed way too hard for this 😂😂😂
"What's up guys, welcome to your 46th Jafh tutorial :)"
Bucky, your tutorials rock so much! :) I wish schools were as awesome as your tutorial videos, maybe then people would actually learn something in school :)
love how you incorporate humor into coding
You have the same humor as casually explained...I love it!
So, I've learned more in one day from you than all semester from a professor. Glad i found this the day before finals. Thank you.
For anyone who does not know this. %d is for at integer value, and %s is for a string value.
Thanks a lot!! Needed it!!!
"Make sure you spelled it wrong."
> lmao
"Hottie with body, cutie with booty", said it so calm. I was laughing my ass off, you're awesome. You're video actually helped me a lot as I was struggling with object.
thumbs up bucky the comedian
This is the first explanation that actually makes sense. THANKY SPANKY!!!
Im hoping its safe to assume that after 46 tutorials mostly everyone has subscribed :D :D :D, thanks bucky!
Επιτέλους! Κάποιος που εξηγεί το Static με απλά λόγια. Μακάρι να το εξηγούσε έτσι και ο καθηγητής μας.
Θεούλης ο Μπάκυ! Έχω καταλάβει την c++ και την java χάρη στα tutorials τ!
Ναι μακάρι να είχε και σε άλλες γλώσσες που δεν είναι τόσο συνηθισμένες. Ψάχνω βίντεο για assembly και δεν υπάρχει πολύ υλικό σε βίντεο.
What the fuck did you just say? I don't speak Socrates language.
If you want to date Megan Fox, Natalie Portman, or Taylor Swift. It might me be useful not to call them "Tuna"
Or "objects"
I like how he just does all of those tutorials in like one single week
Finally I know what a static is... well explained
I love you btw. Your tutorials are the best on UA-cam.
they really are even though its taken me years to get this far and be able to follow along and understand whats happening.
What he does is good java programming practice. He hides away the variables from direct access via "private" which is almost always good. He initializes the important variables in the "tuna"-class-scope, then he makes sure to assign values to them via the constructor which is always called when an object is created. The parameter names of the contructor are different from the more global ones for convenience: You could alsocall them like the global ones but then you need to "this.first= first")
Does Taylor Swift know how to program with Swift?
maybe Apple is just a big fan since she joined apple music
The further we get into the tutorials, less and less people are watching them. I see lots of people are dropping out. Not me though. I am in it to win it! Gonna move on to your intermediate tutorials after this
no, ill try to explain, the class "tuna" is a constructor for objects, when you make objects in your main ("apples") each object get's his own variables, but when you put "static" on a variable, it relates to all object made from "tuna", meaning it's more related to the class tuna than a specific object.
Damn dude. You are good. You give me hope. Thanks. I really appreciate it.
Grate Tutor. He have full grip what he want to Teach.Thanks for all your hard work
for those who don't understand why static is useful here, here's what happens if I do "private int members":
First "members" is 0. Then "members++" says 0 + 1 = 1.
On the second object, the same thing happens: members resets back to 0, and then adds 1 again to get 1. It resets because it isn't static. Static fixes this issue.
Without Static, it would say "1 member in the club" for each person.
The static member-variable only increments when an object of this specific class is created. Furthermore, you don't need to initialize the object directly in your main method. You could initialze it in the global variables of the class which contains the main method or another static class or another object of a non-static class. If you are into concurrent programming, you might find out that "static" is not always enough to guarantee the variable manipulation, but first things first.
Best Java tutor ever.
You still have to keep in mind that a static variable inside a class still belongs to that class. A "member" variable of class "tuna", which has a scope of the whole program, is not the same as the "member" variable of another class. So, consider you have objects of the class "tuna" and objects of an almost identical class called "salmon". Accessing both member variables from outside their class-members makes it obvious that they are different: "tuna.member", "salmon.member".
wow. first place that actually explained static good! thnx!
You could do that without a static variable but it has to be outside the objects of the class "tuna". So, whenever your initiualize another "tuna"-object you might increment a predefined member variable which is is positioned somewhere else. You might as well write an handler that creates new objects of the "tuna"-class automatically and increments them in the same way.
This video...is the only thing that finally explained static to me. ROFL.
Thanks,
I finally understood what static means.
So you want to keep the number of members till the next program run? You have to save the member variable to a file either at the end of your program or whenever the member variable is altered. To make your program "remind" itself of the saved variables content in the next run, you have to load the file content with your member value into the member variable. Lookup i/o-streams (input and output streams and file handling) for ways to accomplish this.
Arigato Roberts-Sensei!
from PR-Brazil.. awesome man.. thanks !!!
.. "globlalizando conhecimento.. ESSAS VIDEOS AULAS VINDAS DE TODA PARTE DO MUNDO.. EH MUITO LEGAL ISSO" !!
i liked tuna´s names :)
simple example.. GREAT TUTORIAL !
If it wasn't static you would need to create an object of whatever class the main method is in (apples in this case). Since the main method is the first bit of code that runs, it's not possible to create an object before entering the main method. If it is static, it allows you to use the method without an object.
Your comment was 7 months ago and nobody replied to you, so I don't know if you got an answer yet but at the very least this could help other people if they don't understand.
From what I've gathered from the last 40 tutorials, you really like tuna.
You can do it either way. I've once asked a the programmer community on stackoverflow if you should stick to "this." everytime or just in special cases. It was a lively discussion. However, more people preferred to use something like "firstName = fn" but only for methods beside the constructor. It depends on your preferences.
This is possible of course. You have to either use the command line argument (it's a variable too) and extract the user information or you have other means by user input like Keyevents or text inputted into Swing-GUI-components.
Java is the best programming language i have ever seen.I hava so many ideeas,but first let`s finish the tutorials.
lol... I guess you have never used C++ or haskell.
It's one of the slowest programming languages, but very good to learn first. Soem people say that C is the best to learn first, bet the problem is that this is useless (unless you are linux user, but still u can use C++)
Erikas Rudinskas Late reply but, you should consider learning C++ before C
C++ is like a updated version of C it has more efficient funtions and more stuff.
John Bernhardsson C is procedural, its mostly used for embedded systems and functional programming. C++ is object oriented, they are completely different but some of the syntaxes are similar.
C was like hell to me. It may be the industry standard but it is boring as it gets and so time consuming. Although it does teach alot about how computers work.
You are right and I should have seen your answer before creating mine :)
i'm from jamaica and i must say bucky u rock!
when it makes sense to have the same name for a class variable and local variable one can specify the class variable by using 'this'. for example you could have still used first and last (as oppose to fn and ln which are less descriptive) for the constructor arguments, and simply wrote 'this.first = first;' and 'this.last = last;' int the body of the constructor.
Thanks alot, greg :) You make it very easy to understand.
What a simple explanation all i needed thank you friend for your time :)
You are awsome man.. this one really solved my problem.. bunch of thanks
Super class,I like your tutorials sir
"M-E-M-B-E-R-S members, members" so catchy
Basically, A Static kind of data is one that is the same for all objects.
It saves memory.
Man, you sound like the sane version of Terry Davis. I really like it
i think 46 is quite late for static..
Lol, so true.
Here's a question: How do I know when to put static in my methods? thanks to my IDE showing me error messages when i forget it i manage, but it'd be nice to know if there are any specific things to remember or any tricks. Thx for any advice :D
So it's been 4 years you commented,Mastered Java?
If you know any trick then share please :)
you could in fact do that. that practice is a key part of a programming technique called singleton class. Which is where you instantiate one and only one instance of a class using static methods and and variables to obtain a reference to the singleton class. There is also more that you could do but that is one of the more interesting techniques.
4:07 that was... just.. so beautiful! :")
Really good video, thank you !
I'm not giving up i will master this language!
Bucky, you're awesome.
Great Tutorial, Bucky.
It means that you don't have to make a 'tuna' object to use a method in the tuna class, it can be run all by itself.
OMG! He just gave 3 objects women names. How come feminists haven't brought hell to him?
Cos he sets everything to private. No way for feminists to find out.
Go get yourself a cookie :))
This was in 2009 when being a professional victim wasn't popular yet.
thumbs up for bucky! thx a lot man
For anyone who is confused why we should use the static... just remove the static keyword and run it as a normal private global variable - cheers!
I am sure he made Taylor popular. :P
Yeah among us, nerdy programmers!!
Some people learn the basics by themselves and watching the videos to clarify a "more advanced" point (whatevery that means in each case).
Sub'd I didn't know much about statics, arrays, for loops and I'm going to be learning about while loops. Thanks br0ski
@xVerbati To study this stuff, I make programs of my own that incorporate all of the previous methods included. I just take notes and then make one big program that does everything he taught us to do. I also like to erase everything he typed out that I copied and type it on my own again, that really helps.
dont give up Bucky! one day you will go out with a famous one
Very helpful, thank you.
I appreciate this.. i really wish you wouldve went over static methods as well. Ur hilarious btw.
@AdmiralBazooka
"Episode 45 has 46,000 views.
Episode 46 has 57,900 views."
"Difficulty goes up, views go down."
This does not make sense.
great explanation…thanks
Love this guy
This guy man
I fucking love you bro
u made this a joke and I'm living for it thanks anyway
make sure you spell it wrong - makes me laugh :D
Good explanation mate
@ArIGD182
%s is String, %d is long
Useful for printing variables that change over time
Really useful tutorial!
static is a key-word used in a method declaration
Because there can only be one main function in a java program and it is surrounding all components of that function, except for being part of a class as well (because of the object-oriented concept of Java). If you start a program, you start one and only one program of this type.
nice tutorial....keep up the good work
M-e-m-b-e-r-s! Members Members Members! That's a pretty catchy tune. Oh gosh you're funny.
To study this stuff I make a screen recording and then revew it a bit later in the day. also it helps if you are away from the internet for awhile
“Taylor swift she is babe, pretty voice, Hollywood body, cutie with booty”😂😂 I understand static but I came back for that line.
You should (must) always declare the first letter of class as UPPERCASE
Its not necessary but its better to do so
For a good programmer it's necessary
@sohaeb rehan
He said "SHOULD", not "SHALL".
It's optional, but if you want a job, you better do things right. Using Uppercase to begin a class name might just give you the edge for getting hired.
It's just convention, not a rule.
And why the fuck is that?
I don't know why he didnt show you but take out the static and leave it as "private int members = 0" and see what happens. it will give you a better understanding of what the was talking about.
@lNUMPUN I'm no pro but I think it's because the values of the arguments only last as long as it's method is running, and when that method is over, the values are lost. So he stores them in a instance variable or whatever it's called. I might be wrong (probably am).
"and magan fox,this object...." xD
@Pineapple29 you're the best. :)
Bucky the stand-up comedian 😂😂
Woo sticking out as difficulty rises
If you initialze only 2 objects of the same class, the member variable will be 2 of course ;)
Wow, this is awesome tutorials, just listen to 5:47 ... :-)
i like all ur vids man! I downloaded everyone of them...1 to 35...pls move on to intermediate...tnx alot