Tapatalk

What to configure for compilation and execution of a Java console application?

What to configure for compilation and execution of a Java console application?

5
NewbieNewbie
5

    Jun 25, 2011#1

    This exact program runs fine in other editors:

    Code: Select all

    import java.util.Scanner;
    
    public class AddingInt
    {
    	public static void main(String args[])
    	{
    		Scanner input = new Scanner(System.in);
    		
    		int x;
    		int y;
    		int sum;
    		
    		System.out.print("\nEnter first integer: ");
    		x = input.nextInt();
    		
    		System.out.print("Enter second integer: ");
    		y = input.nextInt();
    		
    		sum = x + y;
    		
    		System.out.println("The sum is: " + sum);
    	}
    }
    But when I run it in UEStudio I get this error that says "Exception in thread "main" java.util.NoSuchElementException
    at Java.util.Scanner.throwFor(Scanner.java:838)...
    and it says some other stuff...

    at AddingInt.main(AddingInt.java:16)

    I'm perplexed. Code which runs fine in other Java IDE's and editors does not run in UEStudio?

    6,685587
    Grand MasterGrand Master
    6,685587

      Jun 26, 2011#2

      Java source code can't be run in any editor. Editors are for editing text files and not for compiling and executing Java source code. You mean that it is possible to run this Java code from within the editor in other editors while this fails in UEStudio. I suppose that IDE's written especially for supporting Java there are lots of configuration settings preset which you have to define in UEStudio. I'm not a Java programmer, but the first line

      import java.util.Scanner;

      looks like a library reference. That means the Java compiler needs to know where this library is located on your hard disk. Usually compilers support a library path setting and IDE's developed especially for Java predefine the library path. UEStudio does that definitely not. So when you run Javac.exe, you better do not run it directly. You better call a batch file with "%f" as parameter and you define the entire environment Javac.exe requires inside the batch file.

      But I do not really know why you have created a user tool for compiling Java source code. UEStudio has predefined configurations for Java Console Applications and Java Windows Applications. But to use them, you have to create a UEStudio project and select Java Compiler - Console Application or Java Compiler - Windows Application. The next step after selecting the appropriate Java compiler configuration is to configure all the Compiler Options to your needs. Then you should be able to use the commands on the BUILD toolbar.

      It looks like you are setting up a Java compilation environment like UltraEdit users must do although UEStudio offers already more. Perhaps you should better start with looking what UEStudio offers by opening each menu and looking on the menu items. If you need more information about a menu item, open the appropriate help page. The Menu Commands on Content tab of the UEStudio is structured in the same ways as the menus.

      5
      NewbieNewbie
      5

        Jun 26, 2011#3

        You can compile and execute Java source code right from within Crimson Editor (which so far is my favorite editor). All you gotta do is go into Options and configure it. For Java, Crimson Editor will compile and execute and show the output right at the bottom. For C++, Crimson Editor will compile, and to execute you press F10 to bring up a command window and simply type in the name of your program and hit Enter and it runs.

        UltraEdit compiles and runs Java code fine from within the editor if you are not working with a program that requires keyboard input. But I noticed that as soon as you work with a program where you are inputting data from the keyboard, UltraEdit freaks out.

        6,685587
        Grand MasterGrand Master
        6,685587

          Jun 27, 2011#4

          Well, the problem is probably that you have configured to capture the output of the compiled console application to the output window. That can't be done if the console application requires user input. That is not possible on Windows. In this case the compiled executable must be called with a user tool with following set on Output tab:

          Show DOS Box: checked
          Capture Output: not checked
          No replace: selected

          The 4 radio options on top left side don't matter because capturing output is disabled.

          If you are using in UEStudio a project with Java set as compiler and console application set as config to use, you should be able to run the compiled application also with the Run App command in the BUILD toolbar (exclamation mark symbol). I don't have a Java project, but it looks like the default "Console Application" config defines [Execute] correct for a console application with showing console window and not capturing the output. I can see also a Class Paths variable appended to the command which you perhaps have to set in the compiler options dialog if the Windows wide CLASSPATH environment variable does not contain correct path for your Java application.

          5
          NewbieNewbie
          5

            Jun 29, 2011#5

            So I should be able to start a new project and pick console application and simply go into the Build menu and use the Build and Run Application items in there to compile and run my Java program? It's not that easy. Doesn't work. And I don't have a clue as to what I have to type into Compiler Options.

            6,685587
            Grand MasterGrand Master
            6,685587

              Jun 30, 2011#6

              357mag wrote:So I should be able to start a new project and pick console application ...
              Yes, and you have to add the source file(s) belonging to this Java project to the project. Just opening a *.java file while the project is opened is not enough. The file must be added to the project.
              357mag wrote:... and simply go into the Build menu and use the Build and Run Application items in there to compile and run my Java program?
              Yes, if all the compiler options are set correct that should work.
              357mag wrote:And I don't have a clue as to what I have to type into Compiler Options.
              Well, I'm not a Java developer and therefore have never read the manual of the Java compiler nor have I ever setup a Java project. Therefore I can't help you on this point. A developer using a compiler or interpreter should have knowledge about the used compiler / interpreter, how it works, what is required to compile / interpret source files and which options the compiler / interpreter offers. Using an IDE with preconfigured configurations does not mean that a developer don't need to read the manual of the compiler / interpreter. For every compiler option a short description is displayed in the dialog below the options area which should be enough help in combination with the manual of the Java compiler to configure the compiler to your needs.

              Perhaps there is another UEStudio user working with Java projects and visting the user-to-user forums regularly who can help you with the options. I can't help you on the Jave compiler options.