How to Create an executable JAR file in NetBeans IDE (Java Source Code)

How to Create an executable JAR file in NetBeans IDE (Java Tutorial with Source Code Example).

👨‍💻 Here is my online course: Visual Basic .NET (VB.NET), Access Database and Crystal Reports Course.
🎯 Enroll now (Full lifetime access): http://bit.ly/2YRy99d

Screenshot EP.5: Creating executable JAR file.


Related videos:
🚀 4K Java Tutorial Episode 4: Accepting User Input using Scanner class (while loop).

[FREE SOURCE CODE by iBASSKUNG]

Note: Updated Source Code

#BEGIN

package javauserinput;

import java.io.IOException;
import java.util.Scanner;
import java.util.Calendar;
import java.util.InputMismatchException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author iBasskung
 */

public class JavaUserInput {

    private static String appTitle = "\nHello, Welcome to User Input App (Scanner Class).\n";
    private static String fullName = "";
    private static int currentYear = 0;
    private static int yearYouBorn = 0;
    private static int yourAge = 0;
 
    // Method
    private static void printSummary(){
     
        try {
         
            System.out.println("Summary of user input:");
            // Formatting string.
            System.out.printf("- Name: %s.%n- Born in: %d.%n- Age: %d.%n%n", fullName, yearYouBorn, yourAge);
         
            System.out.println("Thank you so much for watching my video.");
            System.out.println("Please like and subscribe to my channel.\n"); // \n = new line.
         
            System.out.print("Press Enter key to continue...");
            System.in.read();
            System.exit(0);
         
        } catch (IOException ex) {
            Logger.getLogger(JavaUserInput.class.getName()).log(Level.SEVERE, null, ex);
        }
     
     
    }
 
    public static void main(String[] args) {
     
        System.out.println(appTitle); // Well done :)
     
        Scanner input = new Scanner(System.in);
     
     
        // infinite while loop
        while (true) {
         
            System.out.print("Press c to continue, press E to exit: ");
         
            String enteredByUser = input.nextLine();
         
            if(enteredByUser.equals("E")){
             
                try {
                 
                    System.out.println("\nYou pressed: \'E\' : Upper case (Exit app). Have a good day!\n");
                 
                    System.out.print("Press Enter key to continue...");
                    System.in.read();
                    System.exit(0);
                 
                    // return; // Exit function.
                 
                } catch (IOException ex) {
                    Logger.getLogger(JavaUserInput.class.getName()).log(Level.SEVERE, null, ex);
                }
         
            }else if(enteredByUser.toLowerCase().equals("c")){
                System.out.println("\nYou pressed: \'c/C\' : Ignore case (Continue).\n");
             
                System.out.print("Please input your full name: ");
                fullName = input.nextLine();
                // print
                // Nothing was entered.
                if(fullName.isEmpty()){
                    System.out.println("Full name is empty. Please try again.\n");
                    continue;
                    // To skip the rest of the instructions in the while loop
                    // and begin the next iteration, use a continue statement.
                }
             
                System.out.printf("\nHello, %s!%n", fullName);
                System.out.println(""); // Empty line.
             
                System.out.print("What year were you born?: ");
             
                try{
                 
                    currentYear = Calendar.getInstance().get(Calendar.YEAR);
                    yearYouBorn = input.nextInt();
                    yourAge = currentYear - yearYouBorn;
                 
                    if(yearYouBorn > currentYear){
                        System.out.printf("\n(%d) greater than current year. Please try again.\n\n", yearYouBorn);
                        input.nextLine();
                        continue;
                    }else if(yourAge < 1 || yourAge > 100){ // 2020 1919 etc.
                        input.nextLine();
                        System.out.printf("\nYou were born in: %d, Your age is: %d!\n", yearYouBorn, yourAge);
                        System.out.println("\nInvalid Age! Age must be between 1 and 100.\n");
                        continue;
                    }else if(yourAge < 18){ // 2003 = 17 etc.
                        input.nextLine();
                        System.out.printf("\nYou were born in: %d, Your age is: %d!\n", yearYouBorn, yourAge);
                        System.out.println("\nSorry, you are underage for this application.\n");
                        continue;
                    }else{ // <= 2002 = 18, 2001 = 19, 2000, 1999, 1998 etc.
                     
                        System.out.printf("\nYou were born in: %d, Your age is: %d!\n", yearYouBorn, yourAge);
                        System.out.println("\n*** The mission has been comleted ***\n");
                     
                        printSummary(); // Method.
                     
                        break; // Exit while loop.
                     
                    }
                 
                }catch(InputMismatchException e){
                    System.out.println("\nAn error occurred: You did not input an integer.\n");
                    // clear
                    input.nextLine();
                }catch(Exception e){
                    System.out.println("\nAn error occurred: " + e.getMessage() + ".\n");
                    input.nextLine();
                }finally{
                    // The finally block always executes.
                    // System.out.println("The finally block executed.");
                }
             
            }
         
        }
     
    }
 
}

#END

Follow me around
✔ Want to get updates on new courses or other cool free stuff? Just follow me on social media if that's your thing!

📺 Pages:
📍 https://www.facebook.com/CodeAMinute
📍 https://www.facebook.com/IbasskungTutorial
📍 https://www.facebook.com/codewithibasskung

📺 YouTube:
📍 https://www.youtube.com/c/iBasskung

📺 Udemy (Online Courses):
📍 https://www.udemy.com/vbnet-crystal-reports

📺 Twitter:
📍 https://twitter.com/#!/IBasskung

📺 Blogger:
📍 .NET: https://codeaminute.blogspot.com
📍 JAVA: https://javacodeminutes.blogspot.com

💯 THANK YOU SO MUCH 💯

#Java #JDK #NetBeans #ExecutableFile #AcceptingUserInput #ScannerClass #WhileLoop

Comments

Post a Comment

Popular posts from this blog

How to Create a Super Hello World Program in Java with Source Code

Accepting User Input using Scanner class (Java Source Code)