Throw And Throws In Java Tutorial #48

Поділитися
Вставка
  • Опубліковано 2 сер 2023
  • $1,000 OFF ANY Springboard Tech Bootcamps with my code ALEXLEE. See if you qualify for the JOB GUARANTEE! 👉 bit.ly/3HX970h
    In this video, I show you how to use throw and throws in java! The Java throws keyword goes at the top of a method and says what exceptions it might throw! Throw on the other hand, goes in the middle of a method and gives you the power to throw an exception manually!
    I hope you enjoyed this tutorial on throw and throws in java!
    Full Java Tutorial For Beginners Playlist: • Full Java Course by Al...
    Free Tips: bit.ly/3U6HXcb
    Disclosure: The Springboard link provided is linked to my affiliate account & supports the channel.
    ~
    Alex Lee

КОМЕНТАРІ • 80

  • @alexlorenlee
    @alexlorenlee  7 місяців тому +6

    If you’re new to programming but want a career in tech, I HIGHLY RECOMMEND applying to one of Springboard’s online coding bootcamps (use code ALEXLEE for $1,000 off): bit.ly/3HX970h

    • @javedsultan4830
      @javedsultan4830 4 місяці тому +2

      Are you making new videos or all finished??

  • @cxsey8587
    @cxsey8587 10 місяців тому +12

    These videos kept me in computer science, you made Objects make sense to me. Couldn’t understand them my whole sophomore year until I watched your videos. Very happy you’re making videos again to help people that are in the same situation as I was again.

    • @yur4953
      @yur4953 2 години тому

      Hey what advice would you give to a person who’s almost giving up on Cs😔 I’m currently in my second Semester and this is really tough

  • @ophix6951
    @ophix6951 2 місяці тому +1

    I’ve felt like giving up so many times but ur videos motivate me to push on, so thank u ❤️

  • @moreliasosa2358
    @moreliasosa2358 8 місяців тому +7

    I wouldn't have graduated from college if it wasn't for your videos! Thank you for all you help! 💛💛

    • @elishaokello
      @elishaokello 8 місяців тому +3

      This dude is great, I am a newbie in Java and he has really helped me

    • @elishaokello
      @elishaokello 8 місяців тому

      Are you currently working with an IT firm?

  • @creativeshakeeb7996
    @creativeshakeeb7996 2 дні тому

    your video is being used in my university to teach us.

  • @fredhutchinson5256
    @fredhutchinson5256 8 місяців тому +3

    Alex, I rarely write comment on any video, however your videos are amazing, you are explaining the Java concepts in the simplest way in whole world :) I appreciate your efforts and thank you very much for such a resourceful UA-cam channel. I hope you continue posting your amazing videos, maybe some Java web application projects. Love!

  • @adrianlocquiao4865
    @adrianlocquiao4865 10 місяців тому +1

    Hi Alex! Thanks for the throw/throws vid 🙏🙏😀

  • @khanhgiapham-mi4hg
    @khanhgiapham-mi4hg 10 місяців тому +6

    Very nice video. Carry on the good work sir.

  • @poorpanda9033
    @poorpanda9033 10 місяців тому

    Was waiting for this thank youuuu ❤🎉

  • @jusrene
    @jusrene 3 місяці тому

    Best programmer ever! thx alex 💗

  • @ravitejaedibilli9470
    @ravitejaedibilli9470 10 місяців тому

    The best channel for java in UA-cam▶️

  • @Arfifias
    @Arfifias 6 місяців тому

    Thank you alex for teaching me java you made me a better developer

  • @ridima7851
    @ridima7851 9 місяців тому

    thankyou so much , this helped me a lot for preparing for my school exam !!!

  • @ShuddhoDevDhali-xc4pv
    @ShuddhoDevDhali-xc4pv 25 днів тому +2

    BRO COME BACK MAN, I MISS YOUR TUTORIALS, ITS BEEN 9 MONTHS NOW

  • @pranavnikam5922
    @pranavnikam5922 9 місяців тому

    Thank you Alex😊

  • @user-px5pj7ux5k
    @user-px5pj7ux5k 9 місяців тому

    The things you teach are good, Sir, where you can quickly understand because it is direct to the point. I didn't go to a programming in college but I'm just learning on my own. I hope you can also make a tutorial on how to make an physics engine.Please🙏

  • @firepluto6128
    @firepluto6128 2 місяці тому

    Hey Alex please make springboot playlist
    It would be great
    Your teaching style is superb

  • @oshadhaedirisinghe1455
    @oshadhaedirisinghe1455 4 місяці тому

    Thank you

  • @salamibraheem3728
    @salamibraheem3728 10 місяців тому

    Thank you Alex

  • @aryankushwaha9306
    @aryankushwaha9306 3 місяці тому +3

    Hey, Alex I am aryan kushwaha from India, I just want to tell you that you should have to make some real project-based video just like you made on tick tac toe but something in advance so that it helps us to learn more. can you plz make videos on Java projects for beginners it helps us a lot to understand Java This is a huge request. and love from India.♥♥

  • @sad2006
    @sad2006 9 місяців тому

    Can you make more videos you helped me get an a+ on my CS tests

  • @dcamcan
    @dcamcan 8 місяців тому

    Love the keyboard!

  • @kumuthusandeepa8045
    @kumuthusandeepa8045 9 місяців тому

    nice Explanation sir

  • @Sijo2
    @Sijo2 4 місяці тому

    Hi, Alex. I really enjoy your channel and content. I am currently going to a coding bootcamp and i want to know what is a typical day like as a coder. I enjoy coding and find it fun , but sometimes challenging. I know there is a bunch of youtuber film their daily code life but they really don't tell us what they do. Is it possible you could make a video about what you do and what a typical day would be like?

  • @merrilystudy6642
    @merrilystudy6642 7 місяців тому

    @alexlorenlee In case of ArrayIndexOutOfBoundsException we didn't needed to add throws in arrayPractice method is because ArrayIndexOutOfBoundsException is an Unchecked exception. That means, compiler doesn't force you to handle it using throws or try catch.
    In case of Exception class, Exception class itself is a checked exception. Hence when you used throw new Exception, it made it mandatory for you to handle it using throws Exception in arrayPractice method and further using try catch block in main method or by throws in main method.
    Also wanted to let you know that your videos are simple and helpful🙂👍

  • @frufrumeep
    @frufrumeep 9 місяців тому +1

    you're still making videos?? I just learned about you and recently watched your "I'm not doing java videos anymore videos." Didn't check the date though. I'm an adult learner in my second programming class and it is a huge struggle. I'm looking forward to binging your videos to learn, thank you!!!

  • @mahdikhairddine
    @mahdikhairddine 13 днів тому

    Weeeee need you comeee backkk

  • @tribungnativevlog4306
    @tribungnativevlog4306 8 місяців тому

    hello alex i just visit your channel so sorry for late quite busy lately.❤

  • @aryankushwaha9306
    @aryankushwaha9306 3 місяці тому

    please upload more videos

  • @amoghnigam8311
    @amoghnigam8311 4 місяці тому +1

    can u create the video for printing series through java loop day after tom is my exam ? can u plz sir?

  • @carol00210
    @carol00210 7 місяців тому

    Hey, could you make a video about Threads? :)

  • @ophix6951
    @ophix6951 2 місяці тому

    I LOVE UR NEW KEYBOARD ITS ADORABLE 🥹

  • @cry4025
    @cry4025 8 місяців тому

    Do you think you could go over comparable and comparator?

  • @osamabinlagging36ty99
    @osamabinlagging36ty99 8 місяців тому +1

    Make video on File, iostream and generics too

  • @justyourlocalprogrammer
    @justyourlocalprogrammer 9 місяців тому

    Are you going to make a Video on Bubble and Insertion Sort?

  • @outpyked2733
    @outpyked2733 6 місяців тому

    Hey Alex!
    I have a request to make for the whole Java Series you have. It could be helpful to 1. make the playlists again (theyre all bunched up into one big one now) 2. maybe make a little task for each of the series? That takes all the things from the basics course and combines it into a project to work on. With a little stopper saying: "okay now do it yourself" and right after resuming the video you have the answer?
    Does that make sense?
    I just love you videos man

  • @vivvv-dinonugs
    @vivvv-dinonugs 9 місяців тому

    Please make a video about bit manipulation and bitwise operators in java!!!!

  • @Jackolantirn
    @Jackolantirn 9 місяців тому

    What is this program he is using to create these new java projects? It looks so sick

  • @lofo_
    @lofo_ 6 місяців тому

    hi do you know any good websites to practice what I have learned

  • @user-px5pj7ux5k
    @user-px5pj7ux5k 8 місяців тому

    Hi sir alex, how to initialize the array without typing value manually but by using for loop?😢

  • @Shelby_itachi
    @Shelby_itachi 10 місяців тому

    Java king 🤴 🙌

  • @dianaalmanza524
    @dianaalmanza524 8 місяців тому

    what keyboard is that?? so nice

  • @onlyzombiees7931
    @onlyzombiees7931 3 місяці тому

    Why did it prompt for add throws exception while you were throwing throw new arrayindexout of bound exception
    But it was asking you to explicitly add throws Exception to the method when you canged from through new aiob exception to throw new exception!?

  • @pravithrav7596
    @pravithrav7596 Місяць тому

    Can you make collections and spring spring boot java vedios please

  • @aly9165
    @aly9165 Місяць тому +1

    i miss u alex lee

  • @gamewiz1079
    @gamewiz1079 10 місяців тому

    Can you give us a junit and mockito tutorial

  • @keirgordon8646
    @keirgordon8646 10 місяців тому

    nice keyboard

  • @elishaokello
    @elishaokello 8 місяців тому

    Hey Alex and Java lovers, are there projects that one can do to make him or her perfect and sharpen his skills in java?

  • @kcsiddhartha
    @kcsiddhartha 4 місяці тому +1

    Wait is he back?

  • @bigheaddanny3377
    @bigheaddanny3377 8 місяців тому +2

    please use dark mode, my eyes are burning

  • @kotlinnn
    @kotlinnn 2 місяці тому +1

    you should leetcode problems

  • @golden5976
    @golden5976 8 місяців тому

    Do you make good money? I hope you do thank you

  • @glasses4180
    @glasses4180 9 місяців тому

    Wait you returned on making tutorials? I thought we lost you.

  • @Firestar0910
    @Firestar0910 6 місяців тому

    Here we are don't turn away now!!!

  • @xomnionProgrammingAndChess
    @xomnionProgrammingAndChess 10 місяців тому +1

    Okay, I mean, I loved your tutorial, but the title is a tongue twister lol

  • @OKrazianth
    @OKrazianth 3 місяці тому

    import java.util.Scanner;
    public class TwoHalves {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (true) {
    System.out.println("Enter a string (type 'exit' to quit):");
    String input = scanner.nextLine();
    if (input.equalsIgnoreCase("exit")) {
    break;
    }
    printTwoHalves(input);
    }
    scanner.close();
    }
    private static void printTwoHalves(String input) {
    System.out.println("Original string: " + input);
    System.out.println("(" + input.length() + " letters - " + (input.length() % 2 == 0 ? "Even" : "Odd") + ")");
    if (input.length() % 2 == 0) {
    String firstHalf = input.substring(0, input.length() / 2);
    String secondHalf = input.substring(input.length() / 2);
    System.out.println("= loveUTOO" + firstHalf);
    System.out.println("= love" + secondHalf);
    System.out.println("= Utoo" + firstHalf.toUpperCase());
    System.out.println("Original string");
    System.out.print("1st half: " + firstHalf);
    System.out.println();
    System.out.print("2nd half: " + secondHalf);
    System.out.println();
    if (firstHalf.equals(secondHalf)) {
    System.out.println("2 halves are the same");
    } else {
    System.out.println("2 halves are not the same");
    }
    } else {
    System.out.println("(Odd number of letters - cannot be split evenly)");
    }
    System.out.println("------------------------------");
    }
    }

  • @user-co2ry4qq1f
    @user-co2ry4qq1f 3 місяці тому

    import java.util.Scanner;
    public class Quiz2 {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter a 5 letter string: ");
    String input = scanner.nextLine();
    if (input.length() != 5) {
    System.out.println("Error: Please enter a 5-letter string.");
    return;
    }
    StringBuilder manipulatedString = new StringBuilder();
    manipulatedString.append(input.charAt(4));
    manipulatedString.append("-");
    manipulatedString.append(input.charAt(1));
    manipulatedString.append(input.charAt(2));
    manipulatedString.append(input.charAt(3));
    manipulatedString.append("-");
    manipulatedString.append(input.charAt(0));
    System.out.println(manipulatedString.toString());
    }
    }

  • @user-co2ry4qq1f
    @user-co2ry4qq1f 3 місяці тому

    import java.util.Scanner;
    public class Quiz3 {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (true) {
    System.out.print("Enter a string: ");
    String input = scanner.nextLine();
    if (input.equalsIgnoreCase("quit")) {
    break;
    }
    analyzeString(input);
    }
    System.out.println("Goodbye!");
    }
    private static void analyzeString(String input) {
    if (input.length() < 2) {
    System.out.println("Result: Too short.");
    return;
    }
    System.out.println("Result:");
    System.out.println("Original String: " + input);
    boolean isEven = input.length() % 2 == 0;
    StringBuilder firstHalf = new StringBuilder();
    StringBuilder secondHalf = new StringBuilder();
    if (isEven) {
    int halfLength = input.length() / 2;
    firstHalf.append(input, 0, halfLength);
    secondHalf.append(input, halfLength, input.length());
    System.out.println("1st half: " + firstHalf);
    System.out.println("2nd half: " + secondHalf);
    System.out.println("2 halves are the same: " + firstHalf.toString().equals(secondHalf.toString()));
    if (firstHalf.toString().equals(secondHalf.toString())) {
    System.out.println("= " + modifyString(firstHalf.toString()));
    } else {
    System.out.println("= " + modifyString(firstHalf.toString()) + " " + modifyString(secondHalf.toString()));
    }
    } else {
    int halfLength = input.length() / 2;
    firstHalf.append(input, 0, halfLength);
    secondHalf.append(input, halfLength + 1, input.length());
    System.out.println("1st half: " + firstHalf);
    System.out.println("2nd half: " + secondHalf);
    System.out.println("2 halves are the same: " + firstHalf.toString().equals(secondHalf.toString()));
    System.out.println("|--|--");
    }
    System.out.println("(" + input.length() + " letters " + (isEven ? "Even" : "Odd") + ")");
    }
    private static String modifyString(String input) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < input.length(); i++) {
    if (i == 0) {
    sb.append(Character.toUpperCase(input.charAt(i)));
    } else {
    sb.append(input.charAt(i));
    }
    }
    sb.append("oO");
    return sb.toString();
    }
    }

  • @kaylotierre6165
    @kaylotierre6165 2 місяці тому

    Alex, do you have instagram?

  • @OKrazianth
    @OKrazianth 3 місяці тому

    import java.util.Scanner;
    public class TwoHalves {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (true) {
    System.out.println("Enter a string (type 'exit' to quit):");
    String input = scanner.nextLine();
    if (input.equalsIgnoreCase("exit")) {
    break;
    }
    printTwoHalves(input);
    }
    scanner.close();
    }
    private static void printTwoHalves(String input) {
    System.out.println("Original string: " + input);
    if (input.length() % 2 == 0) {
    String firstHalf = input.substring(0, input.length() / 2);
    String secondHalf = input.substring(input.length() / 2);
    System.out.println("1st half: " + firstHalf);
    System.out.println("2nd half: " + secondHalf);
    if (firstHalf.equals(secondHalf)) {
    System.out.println("2 halves are the same");
    } else {
    System.out.println("2 halves are not the same");
    }
    } else {
    System.out.println("(Odd number of letters - cannot be split evenly)");
    }
    System.out.println("---");
    }
    }

    • @OKrazianth
      @OKrazianth 3 місяці тому

      Mago

    • @OKrazianth
      @OKrazianth 3 місяці тому

      import java.util.Scanner;
      public class TwoHalves {
      public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      while (true) {
      System.out.println("Enter a string (type 'exit' to quit):");
      String input = scanner.nextLine();
      if (input.equalsIgnoreCase("exit")) {
      break;
      }
      printTwoHalves(input);
      }
      scanner.close();
      }
      private static void printTwoHalves(String input) {
      System.out.println("Original string: " + input);
      System.out.println("(" + input.length() + " letters - " + (input.length() % 2 == 0 ? "Even" : "Odd") + ")");
      if (input.length() % 2 == 0) {
      String firstHalf = input.substring(0, input.length() / 2);
      String secondHalf = input.substring(input.length() / 2);
      System.out.println("= loveUTOO" + firstHalf);
      System.out.println("= love" + secondHalf);
      System.out.println("= Utoo" + firstHalf.toUpperCase());
      System.out.println("Original string");
      System.out.print("1st half: " + firstHalf);
      System.out.println();
      System.out.print("2nd half: " + secondHalf);
      System.out.println();
      if (firstHalf.equals(secondHalf)) {
      System.out.println("2 halves are the same");
      } else {
      System.out.println("2 halves are not the same");
      }
      } else {
      System.out.println("(Odd number of letters - cannot be split evenly)");
      }
      System.out.println("------------------------------");
      }
      }