Java variable scope 🌍

Поделиться
HTML-код
  • Опубликовано: 22 окт 2024

Комментарии • 108

  • @BroCodez
    @BroCodez  4 года назад +28

    //**********************************************
    public class Main {
    public static void main(String[] args) {

    //local = declared inside a method
    // visible only to that method

    //global = declared outside a method, but within a class
    // visible to all parts of a class

    DiceRoller diceRoller = new DiceRoller();

    }
    }
    //**********************************************
    import java.util.Random;
    public class DiceRoller {

    Random random;
    int number;

    DiceRoller(){
    random = new Random();
    roll();
    }

    void roll() {
    number = random.nextInt(6)+1;
    System.out.println(number);
    }
    }
    //**********************************************

    • @IshmaelDoe
      @IshmaelDoe 2 года назад +1

      hi bro, may I know why you created a constructor that didn't instantiated any value? Is it for the purpose for easy demonstration? In standard practice should we do something like this, and if so what do we us it for? Thank!

    • @bittertruthnr1
      @bittertruthnr1 Год назад +1

      understood nothing

  • @kemann3815
    @kemann3815 2 года назад +36

    I study in software engineering major, ive had the program language and advanced program language classes before, which is about the c++ language, and all they taught me was the if statements and the for loops and printing stuff out and taking stuff from the user input. So far ive watched your java course and ive already learned like 10 times more than what they taught me in university. You have no idea how thankful i am for this course. Thanks for real. ❤

    • @T0ra99
      @T0ra99 2 года назад

      Interesting, at our University's CS program, variable scope is one of the major content for our first 2 intro courses.

    • @vocodeex
      @vocodeex 10 месяцев назад

      how is it possible that a university software engineering couse does not teach variable scope

    • @z1nai
      @z1nai 9 месяцев назад

      @@vocodeex you'd be surprised, my university hasn't taught me anything that I haven't already learned in high school. I can learn more in 5 minutes from youtube than what I'd learn in a year on my course.

    • @vocodeex
      @vocodeex 9 месяцев назад

      @@z1nai i can do that too but variable scope is important for programming. Its interesting.

  • @GeoffreyofCastille
    @GeoffreyofCastille 3 года назад +21

    I've learned more from even just your first twenty eight videos in this playlist than I did in the entire semester Java class I just finished taking....thanks! Definitely will be working my way thru your whole series

  • @AdrianTregoning
    @AdrianTregoning 2 года назад +4

    I've completed the Codecademy Java course, I'm well into a Udemy course too and by watching the first 28 of your videos I've probably learnt more, in possibly less time. One could say it's reinforcement of what I've learnt but I have no doubt I've picked up a huge amount through your videos. Thanks so much for the effort you went to.

  • @paulinewachira5839
    @paulinewachira5839 9 месяцев назад +1

    well explained,thank you for sharing

  • @brucedebona6018
    @brucedebona6018 2 года назад +1

    A really great aid in learning Java with clear, simple examples illustrating each topic, and an in-depth, engaging presentation by the instructor. One very helpful feature is the code samples accompanying each video. I copy these into Eclipse and play around with making changes and learning from them. For a free "course" in Java, BroCode Java is the best among all others I have tried. I give it an A+. Thank you "Bro".

  • @john81487
    @john81487 2 года назад +2

    Thanks for getting me started on my developer journey

  • @dianamilenaarchilacordoba4632
    @dianamilenaarchilacordoba4632 Месяц назад

    great video!!! I'm infinitely grateful for your dedication and big heart to share this knowledge with the world. Thank you soo much

  • @bharathpavurala7817
    @bharathpavurala7817 2 года назад +4

    You are a great teacher of all time... 🥰

  • @unalysuf
    @unalysuf Год назад

    I am still watching your videos and I am very glad that I found your channel. I am generally leaving a comment under your videos to support your channel. have a good luck

  • @EaglesOps24
    @EaglesOps24 Год назад +3

    IF anyone is confused why he did not assign number in the DiceRoller constructor to 0 its because in java when you intitialize an int it is automatically assigned 0.

  • @LanusSaye
    @LanusSaye 2 месяца назад

    It,s greate to be here with Bro Code, I've learned a lot 👍

  • @EaintChuuThaw-q8w
    @EaintChuuThaw-q8w Год назад +1

    thank you so much all of your lessons.

  • @DiaborMagics
    @DiaborMagics Месяц назад

    This is very clear, thank you. The problem I ran into is that a method could not change a global variable (or to be precise, 3). This was probably a problem with how they were declared then. The method was public static and so were the variables. They were all within the main class, though.
    But a return statement could only give back 1 result and any others, or if i did not use a return statement, it wouldnt change them outside of the method's scope. I think that is how you call that.
    Sorry if it is a little vague. I ran into the issue a couple days ago and I have since rewritten that part of the code I was practising with, but my mind is still half working on that issue. I'm just confused about why it did not work. Since it's been some days and I don't have the original code block anymore though, I may even be misremembering it. Super helpful, I know.
    EDIT: I realise I sometimes pass global variables as a parameter as well... it being useless aside, can it cause issues?

  • @formlessavatar5220
    @formlessavatar5220 3 года назад +5

    Thanks so much bro. Just wondering if there's actually any difference between the 2 approaches shown (declaring locally and passing as arguments to a method vs. creating global variables that can be accessed anywhere), in terms of memory use and/or any other practical considerations? Are there certain common situations/use-cases I could run into that may warrant using one way over the other, or do we just decide based on individual applications each time? Cheers, much love

  • @makankosappo8381
    @makankosappo8381 2 года назад

    im learning coding by my self thanks to ur videos, thanks a lot. i've accomplished so much in just few weeks and it makes me hope i'll be able to work in this field "soon". u made me fall in love with coding and i cant wait to learn c, c++ and other lenguages. thank you so much for your work and your passion

  • @maziarheidari9797
    @maziarheidari9797 Год назад +1

    Thanks

  • @mayankgupta9277
    @mayankgupta9277 Год назад +2

    Java like other language such as C and C++ doesn't have the concept of Local and Global variables as Java is a strictly Object Oriented Language.
    There are 2 scope defined by Java, one defined by the class and another defined inside the method.
    P.S - I am not pointing out, I have learnt a great deal from you and love all your videos.

  • @Muhammadfaisal-kd9kx
    @Muhammadfaisal-kd9kx 11 месяцев назад +1

    thankyou so much

  • @PoorwayTraning
    @PoorwayTraning Год назад +1

    thanks

  • @mohamedelfadli3125
    @mohamedelfadli3125 Год назад +1

    I understand the point about the global and local variables, but I need to rewatch the video to gatch the idea of your program. I am not a native speaker like you LOL😜.

  • @ahasanhabibrafy8092
    @ahasanhabibrafy8092 2 года назад +1

    Droping a comment as a prayer to youtube algorithm.

  • @najmulislam9658
    @najmulislam9658 3 года назад +1

    I like your video Bro..
    I am From
    (Bangladesh)

  • @jimmyberry945
    @jimmyberry945 3 месяца назад +1

    you make java easy🎉🎉thanks

  • @tonystark6664
    @tonystark6664 10 месяцев назад +1

    thank you very much bro

  • @dllm3tommy741
    @dllm3tommy741 Год назад +1

    Thanks for the video

  • @salvadego7834
    @salvadego7834 2 года назад +1

    nice

  • @pushankarmakar1783
    @pushankarmakar1783 2 года назад +2

    best playlist on java

  • @pavelkvasnicka6856
    @pavelkvasnicka6856 Год назад

    This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro

  • @NVM7771
    @NVM7771 4 месяца назад

    Should we use this.random like it was told in the previous video?

  • @saranyadaimer
    @saranyadaimer 3 месяца назад

    Great video 🎉

  • @percivalgebashe4376
    @percivalgebashe4376 Год назад +1

    Nice

  • @lamias7712
    @lamias7712 2 года назад +1

    Done

  • @Khair_ullah
    @Khair_ullah 4 дня назад

    Thanks alot

  • @lulupapaya3504
    @lulupapaya3504 Год назад +1

    my bro

  • @javierpesaresi311
    @javierpesaresi311 Год назад +1

    Capo!!!

  • @olivezoo
    @olivezoo Год назад

    would be good if these lessons could be named by number...

  • @bobera21000
    @bobera21000 Год назад +1

    you man are a legend

  • @NebaDan-ug3kp
    @NebaDan-ug3kp Месяц назад

    ❤❤

  • @erniewhite7875
    @erniewhite7875 Год назад

    great videos

  • @mohammadreza1414
    @mohammadreza1414 9 месяцев назад

    Thanks, bro.

  • @JuliHoffman
    @JuliHoffman 2 года назад +1

    So helpful! Thank you!!

  • @saidsallah7643
    @saidsallah7643 Год назад

    nice video loved it

  • @huuloc8719
    @huuloc8719 3 года назад

    NIce.

  • @joshbenjamin1100
    @joshbenjamin1100 Год назад

    How can I now use the result of the dice roll? I created a SecondDiceRoller class that extends DiceRoller and only use that object in the Main class (i.e., SecondDiceRoller diceRoller2 = new SecondDiceRoller(); ), giving back two numbers. But what if I want to add those numbers together and use that result to compare against subsequent rolls (if you haven't guessed, I'm trying to make a craps game!).

  • @adityaalshi7081
    @adityaalshi7081 2 года назад

    great🙌

  • @nicolasarcelin3220
    @nicolasarcelin3220 Год назад

    Haven't seen a single one of your videos yet but had to subscribe as soon as I read the username.

  • @Nikkhil492
    @Nikkhil492 3 года назад

    thank you so much bro. it's very helpful

  • @dalv8749
    @dalv8749 Год назад

    ty

  • @ardcodelover
    @ardcodelover Год назад

    Liked

  • @曾毓哲-b1t
    @曾毓哲-b1t Год назад

    Thank you very much!! Bro

  • @AdityaSingh-bw4wg
    @AdityaSingh-bw4wg 20 дней назад

    done

  • @msmisra1976
    @msmisra1976 2 года назад

    thank you sir

  • @_Anna_Nass_
    @_Anna_Nass_ 3 года назад +1

    Hey you, you are saving my grade. Thanks 🙏

  • @danielmilewski7659
    @danielmilewski7659 2 года назад

    awesome course! comment for stats.

  • @danieltambunan9717
    @danieltambunan9717 4 месяца назад

    why do we need to call roll method in our constructor?

  • @minhtetpaing1695
    @minhtetpaing1695 3 года назад

    Thank you so much sir

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 2 года назад

    thanks bro

  • @mamunabdullah191
    @mamunabdullah191 2 года назад

    thanks a lot bro

  • @alexyakoveno4682
    @alexyakoveno4682 2 года назад

  • @nikitassouvatzis1928
    @nikitassouvatzis1928 2 года назад

    Ένα ακόμα σημαντικό θέμα για την εκμάθηση της γλώσσας Java, είναι η εμβέλεια (scope) των μεταβλητών (variables).

  • @TheEvertonDias
    @TheEvertonDias Год назад

    Thanks, Bro!

  • @johan-oe9kz
    @johan-oe9kz 2 года назад

    👍

  • @sanjaykumar-uy5jp
    @sanjaykumar-uy5jp 3 года назад

    that is Brosome broooo.....

  • @danny.3036
    @danny.3036 3 года назад

    Thanks, Bro! ☕ You're awesome!

  • @bekturasanbekov1979
    @bekturasanbekov1979 Год назад

    thx 4 vid bro !

  • @cesara9747
    @cesara9747 2 года назад

    thanks!!

  • @pa-305
    @pa-305 3 года назад

    best brio

  • @greeneggsandmushrooms9855
    @greeneggsandmushrooms9855 3 года назад +1

    360 bro scope

  • @venkatasrikarkavuri2089
    @venkatasrikarkavuri2089 2 года назад

    You don't get them girls loose, loose
    You don't get the world loose, loose
    You don't get money, move, move
    But I do, I do
    I said, y'all having a good time out there?
    Yeah, yeah, yeah, que no pare la fiesta
    Don't stop the party

  • @quanlam1437
    @quanlam1437 2 месяца назад

    Hello, I can't find the video it's about break and continue

  • @alyymibeal5485
    @alyymibeal5485 3 года назад

    Thanks Bro :)

  • @Simis999
    @Simis999 2 года назад

    When I subscribe I become local

  • @omersond4891
    @omersond4891 3 года назад

    like

  • @wallstreetbets7741
    @wallstreetbets7741 2 года назад

    learm

  • @alialhussain4139
    @alialhussain4139 4 месяца назад

    Thanks Bro, 06/07/2024

  • @meggieelo
    @meggieelo 2 года назад

  • @efril802
    @efril802 3 года назад

    lets defeat the algorithm

  • @Mustaux
    @Mustaux 3 года назад

    defeat the algorithm!

  • @hegelbacor7624
    @hegelbacor7624 Год назад

    Hi Sir Can ask a copy of code for all project? Thank you in advance.

    • @shalty554
      @shalty554 Год назад

      it is already in the video's decription

  • @MrMorale386
    @MrMorale386 Месяц назад

    man it's giving main method public static void main error, how do i fix it?

  • @eugenezuev7349
    @eugenezuev7349 6 месяцев назад

  • @ethanalkout949
    @ethanalkout949 3 года назад +1

    Still a confusing topic to me but what ever

  • @adityalochan5482
    @adityalochan5482 2 года назад

    Have you tasted Bro Code

  • @NileshYadav-rg8bf
    @NileshYadav-rg8bf 3 года назад

    I am getting an error that symbol not found on the code:
    DiceRoller diceRoller = new DiceRoller();
    Help me out.

    • @abisarwan20
      @abisarwan20 3 года назад +1

      u have to create new fille as class with name DiceRoller

  • @AARTIKUMARI-fe8wx
    @AARTIKUMARI-fe8wx Год назад

    vedio 27

  • @TWVVermin
    @TWVVermin 2 года назад

    almost forgot thank you

  • @muhammadmushfiqurrahman1653
    @muhammadmushfiqurrahman1653 2 года назад

    Hey bro, please verify your channel to brave creator so I can give you some tip.

  • @maciejkaminski8535
    @maciejkaminski8535 3 года назад

    comment

  • @paulhetherington3854
    @paulhetherington3854 3 месяца назад

    /ech Wn parm by: 2''x avpxn x 4''x fos vk hlf mrk thrm~tmp array eml floch op lk buoy/
    /othr hlv mrk IC mol |avpn| IC''x < vk chrtz HUD/s ech~mrkr buoy ~ i.e. tmp array/
    /kolmn parm mol 8''xfrch orb kntrol < buoy thrm 2''x hlvsz vk [tdT(x''~tmpr R floch run op)]/
    /krch spdy wb mrkx i.e. array Wn eml~bwlch stapach < paavlow avpxn chrk lokon/
    /4''x rwch vk flsh ray~tmp Lt up < fos kolmn < parm jrrpx floch op buoy insrt - frch skop/

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 года назад

    Thanks

  • @salvadego7834
    @salvadego7834 2 года назад

    nice

  • @matinmonshizadeh
    @matinmonshizadeh 2 года назад

    thanks bro

  • @yeliza2350
    @yeliza2350 2 года назад

  • @developerjunior446
    @developerjunior446 3 года назад

    👍

  • @anjapietralla5767
    @anjapietralla5767 9 месяцев назад

  • @baubaudinamo
    @baubaudinamo 4 года назад +1

    nice