Added: 2 years ago
From: thenewboston
Views: 130,916
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (277)

Sign In or Sign Up now to post a comment!
  • Are you male or female? (m/f) asdgfdasfdghkfdghfdyugiyftyyyy­yyyyyysdzzzzzzhjvnnnnnbmnmnmnm­bgfsdfs Response: a Are you male or female? (m/f) asdfffffffgh Response: a Are you male or female? (m/f) sffffffff Response: s Are you male or female? (m/f) f Response: f So i see you are a woman... take 2 Are you male or female? (m/f) dasdklasldk Response: d Are you male or female? (m/f) male Response: m So you are a man...
  • and then a little bit more but youtube wont let me paste it.

    if you have trouble with scanner letter input to a managable variable ask meh :D this example is a male female prompt that never ends till you type wither m or f.. or any word begining with m or f. dosent matter. here is an example

  • import java.util.Scanner;

    public class genderdatatest { public static void main(String[] args){ Scanner input = new Scanner(System.in); String finish = "no"; char genderdata = 'n'; do{ System.out.println("Are you male or female? (m/f)"); genderdata = input.nextLine().charAt(0); System.out.println("Response: "+ genderdata); if(genderdata == 'm'){ finish = "yes"; System.out.println("So you are a man...");

  • i finnaly fixed my java problem

    answer=

  • Wait I'm a bit confused. How did the "x" in the change method edit the bucky string. I thought they would be apart?

  • Ive got a sugestion, make a compelation file that kan be downloaded (prevrably torrent) so that we kan keep it as a manual

  • I see that x is bucky but how became bucky same as x

  • Hey Bucky :D

    I have been following these lessons over the weekend and I gotta say you are great, I tried learning java a few months back but stopped as it seemed kinda hard, but you nail it!

    I know these vids are years old, but still, I felt I had to express my gratitude.

    Thanks alot man!

  • Can a method return an array by any chance?

  • Comment removed

  • Does anyone actually need to get good at it?

    Like I know everything you have said ^-^

    Anyways,

    Never gonna give you up,

    never gonna let you down!

  • Must not give up... o.O

  • how to Input a list of numbers and sort it in ascending order???

  • @yaazimti there's a lot of different sorting algorithms, you can google "sorting algorithms". The easier one (easy bcuz it's the only one actually understand) for me to implement is called "counting sort": wiki -> Algorithm_Implementation/Sorti­ng/Counting_sort

  • next 3 tutorials are for arrays too

  • I mean if I have A[][] and B[][] and I invoke x() method and gave two arguments to that x() method...the arguments for the x() method should be for example xx[][],yy[][] .... but the return how should I return that and use it in the main method ?

  • Guys, this video for invoking one array 1D...how about if I want to return two diminutional array after I invoked them in the main method().

  • @thenewbostom y u no just

    for(int y: bucky);

    y+=1;

    System.out.println(y);

    Optimization... thank for everything though, i need to learn the syntax of java it differs a bit from the languages i know already and i need to learn it for my course so this helps me alot.

    also when you copy and paste you can just use the key combinations you don't have to use the selection menu (from one lazy person to another)

  • Comment removed

  • Shouldn't there be a return statement in the method?

  • @Lucke189

    The method itself is not returning anything. It is just taking the array and editing the values. At least that's what I think is happening.

  • Comment removed

  • hey yo... thanx for the new for loop..... i hope i will be able to use it.... :)

  • Had to watch it twice, but finally got the logic. Even then, I wouldn't worry about it to much, just keep grinding on it. I write a little code a day to bake it all in. Its working.

  • The only part I dont get about this, is how the statement changes the array bucky since there is no return statement. Its a void function- so how does it pass the values back to the main method.

  • @KawallaBair even when void the method can still alter information within the class. the return statement is only data displayed back to the user.........does that help?

  • I get it, it's just how am I supposed to remember this?

  • Maybe I'm getting too far ahead of myself here, but I tried doing the same thing again and created another change (named changealso), and did y[counter]+=10;

    I wanted to print one the first change, then print out the 2nd after adding 10 more on another line. (Like the Index\tTable) we did back a few episodes ago)

    .. Here is what I have (minus all the obvious)

    --

    for(int p: widow) System.out.println(p); for(int w: widow) System.out.println(w);

    I know I'm missing something...

  • And by the way, there is a return after the first print line. not sure why youtube didnt see that

  • @falkills you're missing another object. Bucky1 and bBucky2 containing the same value.

    int[] bucky1 = {};

    int[] bucky2 = {};

    You are trying to add 5 and 10 at the same time to only one array.Which is impossible without implementing treads.You will learn about threads later.

  • The only thing I don´t get is the for(int y:bucky)

    What is happening here?

  • @zaeroxe It is called an enhanced for-loop. Enhanced for loops are pretty much used for shorthand in use in conjunction with arrays. What an enhanced for-loop does is this:

    1.It takes an arbitrary integer and sets it to 0 (Bucky used int y for this)

    2.It then takes an array you want to iterate (Bucky used Bucky[] for this)

    SO we have for(int y:bucky[])

    3. it then starts at zero and iterates up from 0 to the end of the array, and since bucky told it to print out; it will then print out for

  • @zaeroxe PARTII.

    all the values of y that coordinate with the array. For instance; it is shorthand for this for loop:

    for(int y = 0, y>bucky[].length, y++)

    {

    }

    Understand? if not contact me.

  • @zaeroxe

    enhanced for loop

  • @zaeroxe enhanced for loop

  • @zaeroxe its taking the contence of the array and storing them in x as and integer (int), the bucky bit is telling the loop from which array to gather the information

  • @Cobezzz as an* integer

  • @zaeroxe

    Please check out the chapter31, It must help

  • why does he put void, is the method not returning an arrat list of the new values?? And when do you put an array as the return data type?

  • @skkk90 The reason he marks the value as void is because it is not returning a value; rather changing a value. These are called "mutators" in java. The mutator merely alters the values within the array; no return type is necessary since a simple calculation and alteration is performed.

    Understand?

    If not; contact me.

  • Thanks for pointing out that this tutorial is actually about ITERATORS Kachoosi.

    Bucky why can't you mention to people that what we are actually dealing with is ITERATORS? I think you miss out stuff sometimes for the sake of simplicity.

  • I don't think that arrays are hard. I think it's one of the things that makes programming so much easier!

  • Thanks for getting me unstuck.

  • public static void main(String [] args){

    change(schoolteacher);

    }

  • What the fuck did he just dooo ugh i wnat to learn java but this is so hard

  • IM SLOWLING GETTING LOST AS FUCK AHHHHH

  • rewinded a million times and finally got it

  • is the code in the parenthesis for the method called "change" just pre creating a array that can be used by a different method?

  • Comment removed

  • glad i know most general c++ its helps alot with java arrays. almost identical code

  • the only thing i can't understand is how the change method actually changes the bucky array. From my limited knowledge, the method created a separate copy of the bucky array, and named it x. Somehow java recognizes the x array the same as the bucky array, and when he tells it to print out bucky, even though he only changed the separate x array, it also changed bucky. Are the parameters you pass into a method somehow linked to it outcome?

  • @Gam3r979 Yes. The bucky array's values are passed by reference, meaning that changes to x will be applied to the bucky array.

  • @CamdawgzXXX thank you!

  • So... I accidentally typed "public static void change(int[] x)" but it still seems to work.

    1) why? and 2) is this a bad thing to do?

  • @amydfu its the same thing, dont worry. You remember the first time we allocated an array dynamically ? we typed int bla[] = new int[10]; , where u actually have the syntax u used.

  • Omg guyz as Java gets more complicated, these videos are getting more complicated, and I am so stupid! Guys I'm so stuuupid :(

  • arrays suck and are confusing

  • @MrStropwen arrays are immensely useful, and are worth learning. as java gets harder, it gets more useful.

    [3][4][5][6][7] 0 1  2 3 4

  • for(int y : bucky)...I don't get the 'int y' variable.. the for statement is meant to read "for every integer data type of the name y in bucky print it out". Well you haven't even initialized or defined what 'y' is so how can you print it out?

  • @forexdragon y is actually an iterrator. it iterrates thru the array and takes the value of the current array element starting at index=0 and running until index=array.length . example: you have an array called Test[3] with 3 values Test[0] = 4 Test[1] = 3 Test[2] = 10 if youd write now: for(int x: Test) { System.out.println(x+", "); } it'd output: 4, 3, 10 its the same as for(int i=0; i<Test.length; i++) { System.out.println(Test[i]+ ", "); } but shorter. hope this helped
  • thank you !!

  • never seen for(int var: something){} looks great

  • what is that word at 1:29 premedor? pramdor?

    what does that mean?

  • @tsigarete its parameter

    

  • @eilzandra0023 thank you ;)

  • Comment removed

  • @tsigarete

    Haha. Maybe 'premador' is the Spanish equivalent of the word 'parameter'.

  • @forexdragon No, the spanish of 'parameter' is 'parametro'.

  • Lol @ tuna.java...I love tuna :D, brilliant videos btw, very helpful. I've learnt in 10 mins what my teacher tries to teach in 2 hours, not that he doesn't make sense..just takes too long.

  • arrays is very difficult!

  • What does the Line 6 means? (y:bucky)

  • @MrEmil20 Watch the previous tutorial?

  • How could this be useful when programming games? :L

  • @SPlRO Storing information(like item IDs) in an array can be useful.

  • DR RABIE RAMADAN EXPLAIN BETTER THAN THIS VIDS

  • THERE'S NO SCOPE AND VISIBILITY IN JAVA!!! I'm coming from c++ and I am in programming heaven right now! No scope! That means no pointers, no refrences! YYYES!!!

  • there's 100,000 views but probably on 10,000 viewers replayed x10 because they cant understand. :P

  • @Meanbean1992 SCREW YOU ! don't let us down <_<

  • @Meanbean1992

    I totally agree. Everything is getting more and more complex. Everything is interchangeable with everything else. Parameters are no longer just simple variables, but they can be arrays or objects or God knows what else and the same with types...not only just data types, they too can be objects/classes and arrays etc... Too bad you need to learn java to make money cuz it blows. I do not agree that learning a programming language is the same as learning a spoken one.

  • @Meanbean1992

    Let us never forget that logic does not necessarily imply simplicity or common sense, certainly in the case of java. How logical is it that when you 'assign' or declare a value to a variable, sometimes you read from left to right and other times right to left? Example: int x=0; is read left to right and yet x=x+1 is read right to left? Is it because of math calculation involved you go from right to left? Nobody has ever explained this to me.

  • @forexdragon x=x+1 IS read from left to right. It means, "Add 1 to x and assign the resulting value to x."

  • @Meanbean1992 I understood fine, I'm ten years old.

  • @HTMLMINECRAFTGUYJAVA Good 4 ya :P, you dont need to tell your age as java is for everyone who understands. ^^

  • @Meanbean1992 lolz... true that....

  • instead of counter, he should use i

  • Can somebody explain how are the arrays returned from a method if it is needed? i mean, instead of void in the method declaration, should there be an int [] or something like that?

    Thanks

  • Am I the only one having trouble understanding arrays? 1-15 was really easy, now it's difficult to understand these tutorials :(

  • @Peldans same, i have no idea what he's saying now, I just try to follow along, and when I'm done I'll watch them all over again.

  • @redjr242 arrays are just a way to store multiple variables of the same value into one variable, so instead of making bucky1, bucky2, bucky3.... bucky2000, you just make bucky[], and it can store values from 0 to 1999. the for loop is just a way to go through the array modifying each number it has, when you put the counter inside the brackets, you are refering to a position on the array. i think you should make sure you understand everything well before going further on the tutorials.

  • @Xeinnex1 yes, I understand that, it's just certain things he types, I don't feel like he fully explains why he does type it and I'm just left confused by the end. I appreciate your comment though.

  • @redjr242 well i like helping people so if you need anything just msg me, also keep in mind all what he types without explaining is because he already explained it before, so you might want to look for it in the past tutorials maybe you missed it :)

  • @Peldans i thought it was really hard, so i watched all the array tutorials one more time, and now i understand it much better :)

  • @Peldans

    I am with you friend.

  • @Peldans

    That is java for you. Lesson 1 Hello world. Lesson 20 O.0

  • @Peldans yes tell me about it it is getting harder and harder

  • @Peldans No u suck

  • @xJustas You mad?

  • @Peldans programming isnt something that you can just pick up and do right away. it takes years of practice just to be somewhat good at it. there are a few who pick it up and run with it, but for the rest of us, weve been studying and practicing. its like baseball, despite how people who have never played it says its easy, it takes practice day after day for a lifetime to catch, throw, and hit like they do in the majors. do as bucky says at the end of his tutorials "play around with it"

  • @Peldans Im with you i did array list in my programming 1 class and seem to be getting the hang of how arrays right now to some extent but for me the most difficult thing i have is making a actually around it .

  • @Peldans Wow lol i am 13 and i have no trouble with this. I am i did have a little problem but i am doing pretty good!

  • @TheOverseer96 Actually no that i look at the comments lots of people are having trouble..? so i guess i am a genius? :D

  • Hey when I run the program, I get this error printed: Exception in thread "main" java.lang.ArrayIndexOutOfBound­sException: 8 at apples.main(apples.java:8)

    What does this mean and how could I fix it?

  • Excellent series.

  • @xaxjx88 When he uses the change-method on the array called bucky, then the array called x will have the same numbers and the same length as bucky. And since there are 5 numbers in bucky, the length is 5.

  • Comment removed

  • Can array be passed onto a non static function? Because when i tried a non static it doesn't work.

  • not going to use a foreach loop?

    for ( int i : x){ i+=5;

    }

    would this not be better?

  • @JeBuSv20

    No, you can't use an enchanced for-loop in the change-method.

    If you do, you create a variable i, and set its value equal to each number in the array, respectively. When you add 5 to the number i, the numbers in the array will be left unchanged.

    That's because i is not the same variable as those numbers. It only has the same value as them.

    It's like two people having the same amount of money, then one of them gets 5 more coins.

  • I tried to make this work, but I couldn't :( public static void change(int x[]) { for(int z:x) x[z]+=5;

  • i have one question that when method change( ) was of type void how can u return changed array?i.e it is out of scope of main method.isnt it?

  • @worloxi Thank you so much, you just saved me a world of butthurt.

  • my teacher teach us this for almost 3 months ! and i took all of it with just 3 hours Can u be my teacher !

  • Comment removed

  • anyone else notice that he is doing this at 4 am in the morning. I didnt realize that until his words started slurring lol..

  • you should get paid for this, quite useful

  • @DarkBlueHated go to thenewboston(.)com and click on the ads on the right.. thats the one way you can pay buck.. :)

  • @silverwing1221 Thanks for that info! Ima randomly click his ads, i might even bake him a cake and send it to him too.

  • @DarkBlueHated he gets paid from his partner ship (the videos you see before and the ads on the right. He also has a donate link on his channel.)

  • Why doesn't it work...

  • why is it not

    counter<=x.length

    and just

    counter<x.length?????

  • Comment removed

  • @frostshadow5 Because counting starts at 0, so an array that has seven things in it (length seven) occupies spaces 0,1,2,3,4,5 and 6, for example. Therefore x[x.length] doesn't exist, only elements up to x[x.length-1] (or counter < x.length), so if counter went up to x.length (counter<= x.length) you would get back an error for trying to access something that doesn't exist. Hope that makes sense :).

  • also I would give the code I made but like bucky said you can't put code on!!! Curses....is there ways u can message people? I'll try

  • Ah sweet I'm doin the same as you. I read ints are NOT assigned pointers so this will only work with arrays because he is manipulating the object through the 'copied' pointer but this is not the case with an int. It's interesting because you can manipulate the copied pointer but not the original. try making a method to take two arrays swap the pointers and then change the object through the swapped pointer. you will change the "other" object. I tried it and it worked so now I understand :)

  • you forgot to talk about if it is only one line it doesn't need brackets when you did the for loop

  • How does it change the array? I thought it was pass by value not pass by reference in Java. Someone please explain what I'm missing...

  • Hey I am likewise confused but I think it has something to do with the pointers used. Apparently the "pointer" or "reference" is passed by value so if you do a data manipulation using the pointer it will change the object. I hope that makes sense, I'm not very good at explaining but pointers are quite a good computing concept to have so just reply to this if you want me to go through that. But interestingly enough try the code without an array and just an int. It WONT change the object. WHY?

  • @matthewdoucette Hey I am likewise confused but I think it has something to do with the pointers used. Apparently the "pointer" or "reference" is passed by value so if you do a data manipulation using the pointer it will change the object. I hope that makes sense, I'm not very good at explaining but pointers are quite a good computing concept to have so just reply to this if you want me to go through that. But interestingly enough try the code without an array and just an int. It WONT change.

  • @Ubercool29 I am well versed in C++ and pointers and all of this, and passing by value and reference. So really I just need to know whatever rules are followed in Java and then memorize them, as I understand the concepts perfectly. So, I guess, my real wonder was why is the rule different for a variable and an array? I'm not sure, but, as you said, it's obvious the array is passed in via its pointer (likely as by value but it doesn't matter) and variables are not. Thanks for replying!

  • Bucky is simply superb,thanks for making learning so easy! :)

  • bucky this is serious, please create a video tutorials for sale! with more and more examples etc... I study programming and I understand you more from you that my asshole teacher

    maybe do it with lynda dot com? I can pay for more of your tutorials

  • also, why should the method be static?

  • oh nevermind. Why can't this method exist within the main method? That's why I was getting an error. It has to be outside of the main method....I guess that makes sense...

  • Comment removed

  • why are there no {command bracets} following the enhanced for loop?

  • @rustondust notice he didn't put a semi colon at the end of the for line. That means the program will execute the next block of code for x times. since he is only using one line of code after his for loop, brackets aren't necissary

  • my dream is to reach bucky's knowledge, he is absolute programming animal

  • when you said "welcome to your thirty-second java tutorial", i thought the tutorial was going to be thirty seconds long for a second

  • How did the script know bucky = int x when you made the change class? Because the change class have an empty array called x that adds to 5 everytime in a for counter loop and then Bucky is called into this one and the change class automatically sets the empty array int x to bucky??

    I thought you had to declare it, or am I totally lost?

  • why it doesnt work to do that "for(int x:bucky)" in the 2nd method?

    like for(int i:x) {

    i+=5;

    } ?

  • @asdFRap because when you add 5, your only changing the variable holding the numbers, and not the array itself. for example the integer "i" was only holding the values of the array, and is not the array itself, so when you change the "i" value... your not even changing the array at all

  • @Gam3r979 oh i see. thanks buddy

  • you are the only one who can teach me with ease

  • Just to make things clear, if i am getting this right.

    int x[ ] is supposed to take bucky [3,4,5,6,7],

    counter<x.length, the length is 4 (starting from 0 from bucky[3,4,5,6,7]),

    x[counter] +=5, works like x[0] +=5 where x[0] is 3., x[1] is 5, x[2] is 6 etc

    

  • @360felix yeah!

  • how to make all field is private > sorry-im new in java..please help me..

  • looking at the comments now make me feel like im about to get my mind blown...:/ wish me luck

  • THANK YOU SOOOOO MUCH THESE JAVA VIDEOS HELPED SOO MUCH! CONSIDERING MY TEACHER DOES NOT EXPLAIN ANYTING NOBODY IN THE CLASS GETS IT.

  • I was like 30 second tutorial? What its 6 minutes!

    then oooohhhh 32nd...

  • why do i have to make a new variable( y )?

  • @ahhashim While looping through the array bucky , it stores all the value in y

  • This tutorial is getting hard.

  • @Arluness Thats what she said

  • Why doesn't an enhanced for loop work in the change method? The values don't change. If I want to print the changed values, I have to print from within the change() method.

    private static void change(int x[]) { for (int counter:x){ counter += 5; System.out.println(counter); //this will print the new value }

    } 

  • @riprescot I was wondering the same thing :(

  • @riprescot

    An enchanced for loop will increment your counter variable for you. You are probably getting an error because you are manually trying to increase it.

  • Since i knew C++ before this i know most but all of thenewbostons tutorials always help me:))

  • MY BRAIN!!!!!!!!!!!!!!!! 

  • Oy! my head, gonna have to look at it again later

  • why wont you just declare the array as an instance variable?

  • This tutorial is wayyyy longer than 30 seconds!

  • @CloseButton of course

  • good job. Is there a video you have on here that would teach me how to modify the array program so it takes inputs of digits from the keyboard and displays which digits is missing?

  • Okay, so now I've watched 32 of you vids.

    First of all, thanks for the great turtorials! Keep up the great work!

    You're actually a more thorough teacher than the one I have at my university... scary thought.

    Here's a tip for you though: You can type Syso and then hit ctrl+Spacebar to autotype System.out.println(); - might make things easier for you ;)

  • @warloxi better than my lecturer too by a long shot