Launching the program

Hi!

So Im in the process of learning Java. I’ve made some very simple programs in jGrasp but I have no idea how to actually save it as a launchable program and see it in action. Please help!

import java.util.Scanner;

public class Project1
{

   public static void main (String [] args)
   
   {
   
      Scanner in = new
    Scanner (System.in);
      String action = ("");
      
               System.out.println("What would you like to do?");
         in.nextLine();
                
         if (action.equals("Tell me Im pretty"))
         {
               System.out.println("You're gorgeous!");
         System.exit(0);
         }
         else if (action.equals("Read me my file"));
         {
            System.out.println("You're over 40, work long hours and you regret giving birth to your kids.");
            
            in.nextLine();
               System.out.println("I'm so sorry, that was your mothers file!");
                  System.out.println("It seems like I've accidentaly erased your file, can we fill it out again?");
                  
         String answer1 = ("");
            answer1 = in.nextLine();
            
               if (answer1.equals("Sure"))
               {
                   System.out.println("Okay! How old are you?");
               }
               else if (answer1.equals("Yes"));
               {
                  System.out.println("Okay! How old are you?");
               }
               
               int age =(0);
                  age = in.nextInt();
                     System.out.println("Alright, so youre " + age);
                  
         }  
           
   
   }
  
   
}

@felixjohnsson
If you want us to help, can you print out your current code and what you want to do precisely.
P.-S. This category is used for JavaScript not Java (please don’t get confused between these two languages). If this isn’t any related to Codeacademy’s platform course, please post it in the corner bar category in the community category.

1 Like

@miniapple8888 Alright! I changed that and put in the code.

Put your code in a file named Project1.java, then run in a terminal:

javac Project1.java
java Project1

This requires you to have jdk installed, and if you’re on windows you might need to do some extra steps to add java and javac to your PATH

Here’s one tutorial for installing: https://docs.oracle.com/javase/7/docs/webnotes/install/windows/jdk-installation-windows.html#install
there are certainly many more to be found by googling.

You can also run it in here:
https://www.codecademy.com/en/courses/learn-the-command-line/lessons/navigation/exercises/your-first-command (use nano to create a file, paste, save and exit nano and then run the above commands)

jGrasp is some sort of IDE so it might have buttons for compiling and running the program for you. I’d still recommend cutting out the middle man though, I’m not a fan of IDE’s for educational purposes.