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

Link to this comment:

Share to:

All Comments (171)

Sign In or Sign Up now to post a comment!
  • So we had ifception, now it's catch 22

  • to Spielberg2Cents, why have you spelt, dividing as "diving", just saying...

  • @hashtit Cuz, in buckys tutorials, you go ahead and make sure you haue speleed everryting rong

  • only 66,000 people really liked java and tried to learn it... im one of em

  • I accidentally typed in a letter...the Loop is never stopping. Explain please...

  • Yaayyy atlast..a new and meaningful main class name

  • helpful

    

  • This is the first video in a while that I've had to watch only once to completely understand it :DDDD

  • I entered a letter and I got an infinite loop of

    You can't do that.

    Enter first number:

    You can't do that.

    Enter first number:

    Any suggestions?

    The rest works fine, if I try to divide by zero it catches the error normally.

  • @omg123596 what is your code?

  • @molle7397 I think I might of fixed it, I'll send you another reply if it doesn't work out.

  • @molle7397 It wont let me post the code, can I PM you my email?

  • @JSA19882007 thanks :)

  • I bet 80% of the 1.1 million people who stopped watching were here solely for minecraft.

  • what is the name of this compiler ??

    can anyone telme about this ??

  • @muazambce Eclipse

  • if you enter a letter for a number it spazzes out, how can you fix that?

  • try{ ... }catch(ArithmeticException e){ System.out.println("You can't divide by zero!") }catch(InputMismatchException e){ System.out.println("Wrong input type. Number expected.") }

    I think that works.

  • }catch(Exception e){ System.out.println("u r idiot))"); inp.next();

    }

    helps to escape infinite loop if wrong type of data entered

  • need help. while I'm inputing inegers all handling work fine, but when I entered string variable programm start internal loop, any ideas? code below

    Scanner inp = new Scanner(System.in); int x=1; do{ try{ System.out.println("input first num"); int n1= inp.nextInt(); System.out.println("input second num"); int n2 = inp.nextInt(); int result = n1/n2; System.out.println(result); x=2; }catch(Exception e){ System.out.println("this is wrong"); } }while (x==1);

  • This is good. I hope someday I could make a java tutorial.

  • An error occurred when you were talking about catching errors.

    THANKS!

  • For you guys that are getting infinite loops when entering an invalid character, such as a letter, you will need to call next() on your scanner inside the catch clause to clear the invalid data from the scanner, else, you will be looping over invalid data.

  • @tatersalad58 you dont, its gonna just read another num

    just at the start of the loop we need to clear wrong input data using

    input.reset();

  • no exception of type Exception can be thrown; an exception type must be of a subclass of Throwable

  • 1:06 I think you mean a scanner variable called input LOL.

  • Dont type 999999999999999999999999999999­999999999999999999999999999999­999999999999999999999999999999­9 for your first num -.-

  • @yourock129 i made an exception for that my calculator :)

  • I have you to thank for my degree! :)

  • THANK YOU!!!!

  • now try entering a letter XD

  • i tried to input 0.1 for d 2nd number,,,, and i think it failed on catching the error,,, but of course it could b resolved by applying what u hav learned from bucky's lessons combined wid ur analytical skills....

  • Actually, errors and exceptions are not the same thing according to Java's website. Error is supposed to be more serious, a fundamental break down in the Java virtual machine side of things while running the program whereas an exception takes place due to bad programming.

  • @DemocraWatch import Futurama.References;

    Shaddap square!

  • Why is your variable named sum when you're diving??? ;-) .. just saying.. :-D

  • Okay, why is my program so awesome? It divides by zero!!!!! It gives the answer of INFINITY!!!! Who else has a smart program? :D

  • @Arc72Productions oh! my program is like that cause I used doubles, since division can come up with rational numbers, not just whole ones.

  • This is fun! :):):):):

  • oh, now I've got how to make this run properly: create Scanner object INSIDE try code. I don't know why in other case it looks like last entered value is still assigned to input.nextInt()

  • why don't you start try block after print and scan statements ?

  • Booleans exist....

  • you saved my life

    

  • e.printStackTrace();

  • Epic glitch, when you insert letters (YES, ITS POSSIBLE) and press enter it keeps saying enter first num: You cant do that. really fast. lol it wont stop :(

  • @FreePKMNWalkthroughs

    It does it if you put there any letter or basically another type of data ( like 3,5)

  • the way you pronounce "num" sounds like saying "dick" in Tunisian.

  • A neat trick to use instead of the do-while loop is a infinite for loop:

    for(;;)

    {

    }

  • if u try to divide letters... u can't close the console..T___T

  • you can also say while(true){blabla,

    break; //cancels a loop

    }

    Great tutorials. I'm closing in on your game tutorials! =) 

  • BAM! Epic help _0_

  • BAM! we finally made it all the way, just awesome bucky

  • it's "pretty much" explained and got it finally : ) thanx

  • lol "I cant let you do that Dave"

  • some idiot did divide this by zero

  • o thought it needed a counter to keep check of how many times x has been used thats why it ran more that 2 times where in the try block i think x=2 should be x++ just saying

  • i tried to devide by + and it crashed, it sad You cant do that! over and over.

    lol XD

  • thank you so much for that x=1 and x=2 things. It really help out my project :) Keep doing your best!

  • i can't get multiple try&error-blocks to work properly.

    if i create one with lets say try{ int a = 5/0; } catch(Exception e){ /* do something */ }

    and then add another one which does pretty much the same thing, the second catch-block is called before java even tries do call the 2nd try-block (yes, the second Exception-Object is called different).

    what am i doing wrong?

  • it's funny cause in the earlier tutorials he started with num1 variable now he's gotten more lazy down to n1

  • Gave me infinity :D

  • can someone pllzzzz tell me how can i handle the context of a file? for example lets say taht i want to find someone whith his last name and print his age . :( plzzz

  • @Vlaxiti You do the exact same thing as what Bucky did and then in the while(x.hasNext()) loop you place a if statement which monitors if your a,b or c is what you're looking for, and if it is,then you make it print what you want it to.

  • @marsimil thank you very much ::)

  • In my version of this program I used a boolean variable for x.

  • @tyebillion Boolean in reality is not different than an integer. Boolean is just an integer that takes 1 or 0 as values. You would notice that(and a lot more) if you tryied learning C.

  • Thanks again man

  • hey bucky you did not continue on exception handling. :( thanks for your help so far! :)

  • I love the way Bucky simplifies the concepts instead of throwing in a bunch of other concepts at the same time, the way Deitel and Deitel does.

  • man you are the best

  • You really gotta watch out for those dumb users nowadays.

  • @thenewboston I tried what you said but it seems to retain the first number that the user put in and thus get stuck in a circle of saying

    You can't do that

    Enter first num:

    You can't do that

    Enter first num:

    etc etc. any tips?

  • @jmmycnnll Are you using ints or doubles?

  • thanx man...u did a gud job

  • LOL ... cause i'm lazy. That's funny.

  • if i divide it 20.5 or something it just keeping writing Enter first num: over and over again

  • @Muse94Muse that is cause the code needs a int number, 20.5 is a float number, since you din't put a int it gonna be asking for the first int. i'm just a begginer so please forgive me if i'm wrong.

  • I'm pretty sure he could write while(true) in the place of do, and in catch he could write continue and in try he could write break.

  • Errors and exceptions are not the same thing.

    An error causes the system to stop working, so you cannot recover.

    An exception means that a problem occur, but you can recover from it.

  • don't put a letter it just says enter first number: you can't do that for ever

  • If you're dividing by zero, you have no business in the stock market..

    Just saying x.x

  • why does it cause an infinite loop if you enter a character?

  • @gmorphis if you add a

    input.nextLine();

    in your catch it disregards the input so the user can try again

  • @gmorphis Thanks for that [nine months ago] any idea why the program crashes if you use input.nextInt instead of input.nextLine?

  • So pretty much we use loops whenever we want the program to not move on to the next line of code if it encounters an error?

  • Hey bucky, thanks for the videos, they help a lot.

    Does anyone know what IllegalArgumentException handles?

  • there's always a catch

  • please make a tutorial concerning throw exception plus looping and binary search? I'm sure you can do that.. LOL.. thnx

  • Hi, bucky, you're awesome!

    Can you make a tutorial about throw exception??

  • Thanks boss. It's very useful for me

  • Thanks boss. It's very useful for me

  • THANK YOU !

  • hey gud job bucky hope in India we get rid of all the stupid prof and we culd really use ur tutorials all the students will get clear off their subjects......lol....

  • hey gud job bucky hope in India we get rid of all the stupid prof and we culd really use ur tutorials all the students will get clear off their subjects......lol....

  • what if we built a huge program for analyzing the stock market.. and it was awesome...

    XD I LOLD!

  • YOU ARE GOD

  • almost done with the whole series!!!!!!!!! YOU ROCK SIR... YOU ROCK!!

  • dude you rock! great explanation... i'm doing some reviewing from my Senior lvl courses in Java =_=

  • Thanx! I have exam today, watching you tutorials for revision. So clear and understandable! =)

    you are awesome :-)

  • Comment removed

  • thank you very much. i have a question, is there a way to do system clear screen on java? i saw people saying mod the file or download a new java package etc...but is there a way to do system clear screen without moding the file or download java pack? or do u have a video of it? BTW UR AWSOME

  • Thank you so much.....

  • really easy , thank u so much

  • veryyyyyyyyyyyyyyyyyy  nice exampleeeeeeeeee

  • thanks alot sir your tutorials are great

  • Comment removed

  • 1:01 You said: "Now we have an input variable called scanner", I think you got that backwards ;)

  • veryyyyyyyyyyyyyyyyyyy goooooooooooooooooooood !!!!!

    u have explained this stuff in a nice and easy way,

    thanx budy!

  • veryyyyyyyyyyyyyyyyyyy goooooooooooooooooooood !!!!!

    u have explained this stuff in a nice and easy way,

    thanx budy!!

  • veryyyyyyyyyyyyyyyyyyyyyyyyy gooooooooooooooooooooooood !!!!!!!!!!

    u explained this stuff in a nice and easy way,

    thanks budy!

  • thx...

    

  • OH man ,, Thank you very much for this fantastic simple explanation ,,

    I have finally knew what is exception and do while for extra ,,

    Thank you .. kind regards :)

  • Exceptions and errors are NOT the exact same thing. Firstly, because errors are unchecked, and exceptions (beside RuntimeException) are checked. Then, errors are severe problems, like OutOfMemoryError.

  • Comment removed

  • The class name should have the first letter capitalized - like Sample

  • @ibogdank It's sample.java though, if he capitalized it without changing the actual file name it would error.

  • what is this editor that you are using?

  • @lediftuna Eclipse

  • For those who read my comment from yesterday by only adding input.next(); it only checks for the first token. And then each token after seperately. So if you add what I show above and then type in "one two three four" it will say You cant do that and then Enter first num: four times before letting you enter a new value. By adding input.nextLine(); it takes everything entered as one and lets you enter a new value.

  • For those of you wondering how to stop it from going into an infinit loop once you enter anything other than an integer. Insert input.next(); underneath System.out.println("You cant do that"); This will reset the value of input so that it will ask for you to input the first num again.

  • It didn't work if I entered something other than an int.

    If I enter a letter or double etc, it will run into an infinate loop of "You can't do that" 's.

    Why is that if the try/catch is there to catch all errors?

  • @haudace

    damn you youtube, you don't allow spacing or new lines

    System.out.println(); ffs!!!

  • you are the bessssssssssssssssssssssssssss­t

  • you are the bessssssssssssssssst. :)

  • to all the noobs you say this a good tutorial, go read a book, you are embarrassing yourselves.

    the "sum" is not a sum, but thats just bad style

    you dont need an arbitrary variable to break from the loop, use break.

    also, in 9 minutes you can teach people to catch specific exceptions.

  • @erjoalgo FINALLY SOME ONE AGREES WITH ME!

  • instead of creating an int to handle the loop, wouldnt it make more sense to use a boolean true/false?

  • This is great

  • Your tutorials are great man. I think I would have failed my exams without your help.

  • very interesting veido!

    I tried, it was working, untill I tried to devide with -1,23

    It gave me an endless loop wihout stopping at all! :) How could it be? :O

    thx

  • @kibaszottkurvajutub Lmao, I guess anything with . in it does that >.>

  • the do-while loop only works with number. i try a letter and it went crazy. lol it kept repeating nonstop

  • Extend this to multiple catch statements..thanks

  • thank you very much!!!

  • The BEST OF THE BEST TUTORIAL I've ever seen !

  • throws - throw eywords : extending the exception base class

    these topics are missing, u might want to extend the exception handling topic, bucky

  • thanks buck but I hope to complete Exception lessons

  • two weeks ago everything I new abt java is that it's a programming language , now thanks to you bucky AM STARTING TO PROGRAM.

  • try to type in 's' !

  • 2:52 "some idiot tried to divide by zero"

    ..funny

  • Java never looked so easy.Great tutorials.

  • good job

  • thanks bucky that was cool. good job

  • Curley brackets are called braces btw

  • I know each try MUST have a catch, but can a try have more than one catch? For example, if i wanted to have one message for one error, and another message for the another specific error?

    Thanks!

  • sure that is a perfect question--u just ve to have specific Exceptions in each catch block n their messages message to print.

  • *cough*python*cough*

  • tnank you booky

  • thanks bucky ol' pal

  • Thank You so much Bucky!

    Great job.

  • Thank you!!!

  • Comment removed

  • Thanks boss! This gives me a great start on solving my problem in my program. trying to throw a exception made by me to prompt the user to only input a, b, or y. But it says the code doesn't throw an exception.

  • 6th to comment! LOVE YOU TUTORIALS THEY ARE DA SHIT LOL

  • Well thank Einstein, you didn't need to announce it. Oh btw I just replied to you.

  • Thanks for this, i think i will start doing java :

  • @Mkalola Only took you 82 tutorials to decide this

  • Cool

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more