Java Programming Tutorial - 46 - Static

Поділитися
Вставка
  • Опубліковано 12 гру 2024

КОМЕНТАРІ • 449

  • @huseyinfadullahgungor4207
    @huseyinfadullahgungor4207 7 років тому +137

    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.

    • @BarbersFind
      @BarbersFind 6 років тому

      thanks

    • @maynardaquino6592
      @maynardaquino6592 6 років тому

      thanks man.. I didn't understand it until I read this. :)

    • @ameymakarand5429
      @ameymakarand5429 6 років тому

      thank you

    • @vathsan3906
      @vathsan3906 4 роки тому +1

      basically, the static keyword retains the value from previous function.. right..?

    • @anubhavbhura13
      @anubhavbhura13 4 роки тому

      @@vathsan3906 previous object

  • @mulimotola44
    @mulimotola44 9 років тому +647

    he's literally objectifying women in this video :P

    • @atiyan.7372
      @atiyan.7372 9 років тому +41

      PIneapple29 and pot pies. Can't forget the pot pies.

    • @MrEueu89
      @MrEueu89 9 років тому +36

      and calling them tunas

    • @Robostate
      @Robostate 9 років тому +28

      +PIneapple29 Only Bucky could get away with objectifying women like that.

    • @LittleBabyWheeler
      @LittleBabyWheeler 9 років тому +5

      +PIneapple29 Damn, I wanted to make that joke. Meh, thumbs up anyway.

    • @mikegeezee7
      @mikegeezee7 8 років тому +34

      +PIneapple29 : Well, it is an Object Oriented Program

  • @rifatazim8879
    @rifatazim8879 10 років тому +38

    To anyone whos struggling static members belong to a class rather than a specific instance(aka object) of the class.

    • @LazizbekYusupov92
      @LazizbekYusupov92 3 роки тому +1

      You forgot to put commas and dots in your sentence. It makes difficult to understand it.

  • @somebody8875
    @somebody8875 6 років тому +3

    I love the comments starting with "For those who doesn't understand". I always searching for them. That kind of people are a bless.

  • @Thepostmanbaby
    @Thepostmanbaby 11 років тому +332

    Treating women as objects!

  • @Born2EditHD
    @Born2EditHD 8 років тому +206

    Half of the reason i watch these is to laugh

  • @nicolaspicolas1988
    @nicolaspicolas1988 8 років тому +18

    These are the best tutorials on youtube for learning java

  • @appleomax
    @appleomax 13 років тому

    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

  • @abidhasan3243
    @abidhasan3243 6 років тому +14

    "Hotty with the body, cuty with the booty!!" I laughed way too hard for this 😂😂😂

  • @VEGETADTX
    @VEGETADTX 12 років тому +5

    "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 :)

  • @Chandler890
    @Chandler890 7 років тому +2

    love how you incorporate humor into coding

  • @PerreRust
    @PerreRust 7 років тому +1

    You have the same humor as casually explained...I love it!

  • @dang81
    @dang81 14 років тому

    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.

  • @arkadiuszjandylewski152
    @arkadiuszjandylewski152 8 років тому +3

    For anyone who does not know this. %d is for at integer value, and %s is for a string value.

    • @DS-Pakaemon
      @DS-Pakaemon 8 років тому

      Thanks a lot!! Needed it!!!

  • @FLy1nRabBit
    @FLy1nRabBit 8 років тому +97

    "Make sure you spelled it wrong."
    > lmao

  • @Ultimatum12345678910
    @Ultimatum12345678910 6 років тому +10

    "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.

  • @josephjohn5492
    @josephjohn5492 9 років тому +28

    thumbs up bucky the comedian

  • @shizyninjarocks
    @shizyninjarocks 7 років тому

    This is the first explanation that actually makes sense. THANKY SPANKY!!!

  • @DRSteveo44
    @DRSteveo44 12 років тому

    Im hoping its safe to assume that after 46 tutorials mostly everyone has subscribed :D :D :D, thanks bucky!

  • @sandy1995
    @sandy1995 11 років тому +3

    Επιτέλους! Κάποιος που εξηγεί το Static με απλά λόγια. Μακάρι να το εξηγούσε έτσι και ο καθηγητής μας.

    • @Victor92NeaSanta
      @Victor92NeaSanta 10 років тому +1

      Θεούλης ο Μπάκυ! Έχω καταλάβει την c++ και την java χάρη στα tutorials τ!

    • @sandy1995
      @sandy1995 10 років тому +1

      Ναι μακάρι να είχε και σε άλλες γλώσσες που δεν είναι τόσο συνηθισμένες. Ψάχνω βίντεο για assembly και δεν υπάρχει πολύ υλικό σε βίντεο.

    • @hetaeramancer
      @hetaeramancer 2 роки тому +1

      What the fuck did you just say? I don't speak Socrates language.

  • @skylarlynnedits56
    @skylarlynnedits56 8 років тому +84

    If you want to date Megan Fox, Natalie Portman, or Taylor Swift. It might me be useful not to call them "Tuna"

  • @deedit4666
    @deedit4666 8 років тому

    I like how he just does all of those tutorials in like one single week

  • @EvilTurt
    @EvilTurt 13 років тому

    Finally I know what a static is... well explained

  • @SeanPencil
    @SeanPencil 9 років тому +9

    I love you btw. Your tutorials are the best on UA-cam.

    • @thewewguy8t88
      @thewewguy8t88 5 років тому +1

      they really are even though its taken me years to get this far and be able to follow along and understand whats happening.

  • @Permafrostrock
    @Permafrostrock 11 років тому

    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")

  • @josephkreifelsii6596
    @josephkreifelsii6596 8 років тому +96

    Does Taylor Swift know how to program with Swift?

    • @the.droetker
      @the.droetker 6 років тому +3

      maybe Apple is just a big fan since she joined apple music

  • @jhdoubleoseven
    @jhdoubleoseven 13 років тому

    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

  • @DrGecko1
    @DrGecko1 12 років тому

    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.

  • @MrWhoadudewhoa
    @MrWhoadudewhoa 6 років тому

    Damn dude. You are good. You give me hope. Thanks. I really appreciate it.

  • @bigkinguk
    @bigkinguk 10 років тому

    Grate Tutor. He have full grip what he want to Teach.Thanks for all your hard work

  • @jameeztherandomguy5418
    @jameeztherandomguy5418 4 роки тому

    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.

  • @Permafrostrock
    @Permafrostrock 11 років тому

    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.

  • @Spooce199
    @Spooce199 11 років тому

    Best Java tutor ever.

  • @Permafrostrock
    @Permafrostrock 11 років тому

    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".

  • @OreoYoo
    @OreoYoo 6 років тому

    wow. first place that actually explained static good! thnx!

  • @Permafrostrock
    @Permafrostrock 11 років тому

    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.

  • @xqnp7
    @xqnp7 13 років тому

    This video...is the only thing that finally explained static to me. ROFL.

  • @cruzrogelio09
    @cruzrogelio09 11 років тому

    Thanks,
    I finally understood what static means.

  • @Permafrostrock
    @Permafrostrock 11 років тому

    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.

  • @helicopter5644
    @helicopter5644 7 років тому

    Arigato Roberts-Sensei!

  • @engelet4626
    @engelet4626 6 років тому

    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 !

  • @BlazingStreak
    @BlazingStreak 11 років тому

    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.

  • @2CloseShave
    @2CloseShave 11 років тому

    From what I've gathered from the last 40 tutorials, you really like tuna.

  • @Permafrostrock
    @Permafrostrock 11 років тому

    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.

  • @Permafrostrock
    @Permafrostrock 11 років тому

    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.

  • @DUBSTEPx5PRO
    @DUBSTEPx5PRO 10 років тому

    Java is the best programming language i have ever seen.I hava so many ideeas,but first let`s finish the tutorials.

    • @Claymore2408
      @Claymore2408 10 років тому +4

      lol... I guess you have never used C++ or haskell.

    • @criticalmoorhen
      @criticalmoorhen 10 років тому

      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++)

    • @johnbernhardsson4963
      @johnbernhardsson4963 10 років тому

      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.

    • @Claymore2408
      @Claymore2408 10 років тому

      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.

    • @Xiler6969
      @Xiler6969 10 років тому

      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.

  • @Permafrostrock
    @Permafrostrock 11 років тому

    You are right and I should have seen your answer before creating mine :)

  • @che-andregordon348
    @che-andregordon348 11 років тому

    i'm from jamaica and i must say bucky u rock!

  • @gavinpeterson1973
    @gavinpeterson1973 9 років тому

    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.

  • @henrik123321
    @henrik123321 11 років тому

    Thanks alot, greg :) You make it very easy to understand.

  • @FixDaily
    @FixDaily 5 років тому

    What a simple explanation all i needed thank you friend for your time :)

  • @sammarbagh
    @sammarbagh 14 років тому

    You are awsome man.. this one really solved my problem.. bunch of thanks

  • @tangsan9313
    @tangsan9313 5 років тому +1

    Super class,I like your tutorials sir

  • @amikawi
    @amikawi 9 років тому +13

    "M-E-M-B-E-R-S members, members" so catchy

  • @waqqas_the_wicked
    @waqqas_the_wicked 14 років тому

    Basically, A Static kind of data is one that is the same for all objects.
    It saves memory.

  • @2A9D8F
    @2A9D8F 5 років тому

    Man, you sound like the sane version of Terry Davis. I really like it

  • @krcn00b
    @krcn00b 9 років тому +39

    i think 46 is quite late for static..

  • @dole4589
    @dole4589 8 років тому +5

    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

    • @Conqueror1807
      @Conqueror1807 4 роки тому +3

      So it's been 4 years you commented,Mastered Java?
      If you know any trick then share please :)

  • @awgyd9
    @awgyd9 12 років тому

    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.

  • @MrMetemer
    @MrMetemer 12 років тому

    4:07 that was... just.. so beautiful! :")

  • @camilo.antonio
    @camilo.antonio 7 років тому

    Really good video, thank you !

  • @dtgonzalez1
    @dtgonzalez1 13 років тому

    I'm not giving up i will master this language!

  • @megachuck
    @megachuck 12 років тому

    Bucky, you're awesome.

  • @karatuccar
    @karatuccar 15 років тому

    Great Tutorial, Bucky.

  • @melodygriesen5708
    @melodygriesen5708 11 років тому

    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.

  • @raducamman
    @raducamman 8 років тому +28

    OMG! He just gave 3 objects women names. How come feminists haven't brought hell to him?

    • @moyashimugiwara3661
      @moyashimugiwara3661 8 років тому +34

      Cos he sets everything to private. No way for feminists to find out.

    • @raducamman
      @raducamman 8 років тому +4

      Go get yourself a cookie :))

    • @javierguerrero9486
      @javierguerrero9486 8 років тому +11

      This was in 2009 when being a professional victim wasn't popular yet.

  • @MrHeaventrack
    @MrHeaventrack 9 років тому

    thumbs up for bucky! thx a lot man

  • @fckingmronhwgoodRU
    @fckingmronhwgoodRU 8 років тому

    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!

  • @tonystarx3060
    @tonystarx3060 9 років тому +12

    I am sure he made Taylor popular. :P

    • @DS-Pakaemon
      @DS-Pakaemon 8 років тому +1

      Yeah among us, nerdy programmers!!

  • @Permafrostrock
    @Permafrostrock 11 років тому

    Some people learn the basics by themselves and watching the videos to clarify a "more advanced" point (whatevery that means in each case).

  • @donaldslayer
    @donaldslayer 12 років тому

    Sub'd I didn't know much about statics, arrays, for loops and I'm going to be learning about while loops. Thanks br0ski

  • @midnightcarsintokyo
    @midnightcarsintokyo 13 років тому

    @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.

  • @saidsel-lam2300
    @saidsel-lam2300 8 років тому

    dont give up Bucky! one day you will go out with a famous one

  • @marcorivera4776
    @marcorivera4776 9 років тому

    Very helpful, thank you.

  • @cbwavy
    @cbwavy 13 років тому

    I appreciate this.. i really wish you wouldve went over static methods as well. Ur hilarious btw.

  • @chaostroll1267
    @chaostroll1267 13 років тому +2

    @AdmiralBazooka
    "Episode 45 has 46,000 views.
    Episode 46 has 57,900 views."
    "Difficulty goes up, views go down."
    This does not make sense.

  • @the_basement_files
    @the_basement_files 10 років тому

    great explanation…thanks

  • @naveedasgari8415
    @naveedasgari8415 3 роки тому

    Love this guy

  • @bebarshossny5766
    @bebarshossny5766 5 років тому

    This guy man
    I fucking love you bro

  • @ninistories
    @ninistories 6 років тому

    u made this a joke and I'm living for it thanks anyway

  • @DavidDolynny
    @DavidDolynny 9 років тому +24

    make sure you spell it wrong - makes me laugh :D

  • @kamilbolka
    @kamilbolka 8 років тому

    Good explanation mate

  • @DMurdock
    @DMurdock 13 років тому

    @ArIGD182
    %s is String, %d is long
    Useful for printing variables that change over time

  • @M4JIN7
    @M4JIN7 13 років тому

    Really useful tutorial!

  • @knockknocktwin
    @knockknocktwin 11 років тому

    static is a key-word used in a method declaration

  • @Permafrostrock
    @Permafrostrock 11 років тому

    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.

  • @PrinceNnamdi
    @PrinceNnamdi 14 років тому

    nice tutorial....keep up the good work

  • @lampposteffect
    @lampposteffect 13 років тому

    M-e-m-b-e-r-s! Members Members Members! That's a pretty catchy tune. Oh gosh you're funny.

  • @somerandomjedi
    @somerandomjedi 13 років тому

    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

  • @lwandiso7149
    @lwandiso7149 3 роки тому

    “Taylor swift she is babe, pretty voice, Hollywood body, cutie with booty”😂😂 I understand static but I came back for that line.

  • @SO-dl2pv
    @SO-dl2pv 8 років тому +10

    You should (must) always declare the first letter of class as UPPERCASE

    • @CoolRainbowDash100
      @CoolRainbowDash100 8 років тому +3

      Its not necessary but its better to do so

    • @SO-dl2pv
      @SO-dl2pv 8 років тому +3

      For a good programmer it's necessary

    • @josephkreifelsii6596
      @josephkreifelsii6596 8 років тому

      @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.

    • @ajay000003
      @ajay000003 7 років тому +1

      It's just convention, not a rule.

    • @hetaeramancer
      @hetaeramancer 2 роки тому

      And why the fuck is that?

  • @SuperGreenMiner
    @SuperGreenMiner 13 років тому

    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.

  • @ilikemykebab
    @ilikemykebab 13 років тому

    @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).

  • @yosrienface8876
    @yosrienface8876 10 років тому +3

    "and magan fox,this object...." xD

  • @paininmydroid4526
    @paininmydroid4526 6 років тому

    @Pineapple29 you're the best. :)

  • @tjiscoolkeepsitreal23
    @tjiscoolkeepsitreal23 4 роки тому

    Bucky the stand-up comedian 😂😂

  • @Alavistaven2012
    @Alavistaven2012 13 років тому

    Woo sticking out as difficulty rises

  • @Permafrostrock
    @Permafrostrock 11 років тому

    If you initialze only 2 objects of the same class, the member variable will be 2 of course ;)

  • @iKostanCom
    @iKostanCom 7 років тому

    Wow, this is awesome tutorials, just listen to 5:47 ... :-)

  • @garciasamsonify
    @garciasamsonify 15 років тому

    i like all ur vids man! I downloaded everyone of them...1 to 35...pls move on to intermediate...tnx alot