Java variable scope 🌍

preview_player
Показать описание
Java variable scope

#Java #variable #scope

//**********************************************
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();

}
}
//**********************************************

public class DiceRoller {

Random random;
int number;

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

void roll() {
}
}
//**********************************************
Рекомендации по теме
Комментарии
Автор


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);
}
}

BroCodez
Автор

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

kemann
Автор

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

GeoffreyofCastille
Автор

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.

AdrianTregoning
Автор

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

bharathpavurala
Автор

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

LanusSaye
Автор

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

najmulislam
Автор

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

brucedebona
Автор

Thanks for getting me started on my developer journey

john
Автор

Droping a comment as a prayer to youtube algorithm.

ahasanhabibrafy
Автор

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

pavelkvasnicka
Автор

thank you so much all of your lessons.

lkrflku
Автор

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

makankosappo
Автор

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.

EaglesOps
Автор

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 <3

formlessavatar
Автор

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.

mayankgupta
Автор

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

unalysuf
Автор

Hey you, you are saving my grade. Thanks 🙏

_Anna_Nass_