Java console program

前端 未结 6 1840
花落未央
花落未央 2021-02-01 15:30

I was wondering how to make a Java console program. I use Eclipse as IDE. Looking for something similar to C#\'s version of a console program.

Tried Google but only foun

相关标签:
6条回答
  • 2021-02-01 16:07

    You can run a "console program" inside Eclipse.

    Given a simple program, e.g.

    public static void main (String[] args) {
        System.out.println("hello world");
    }
    

    Open the Eclipse console (Window -> Show View -> Console), and run this program. You should see hello world in the console.

    0 讨论(0)
  • 2021-02-01 16:12

    I would recommend using a variant of Eclipse Java IDE when working with jar development.

    File > New > Java Project
    
    Right Click "src" > New > Package > Name your package pack1.projectname.
    
    Right Click "pack1.projectname" > New > Class > projectname as class name.
    

    Write all the code your heart desires for this project. Java is a very interesting language. Always use packages with your class files, especially when you are sure that you will be importing your own code in other files. So you can do import pack1.projectname.handler.EventHandler;

    File > Export > Java > JAR file, or Runnable JAR file > Next > export destination
    

    This will package your jar file, appropriately with a META-INF manifest, also if you are developing an application or plugin, for anything like Minecraft. You will want a plugin.yml and config.yml file. You right click the project folder not "src" in the project explorer. Do New > File > plugin.yml and config.yml. Just a side note.

    The reason I always use pack1 as my toplevel package identifier is of course so I can tell which pack I am working with as I update my project. I always do this to easily compare files I have updated, why I updated them, etc. etc. So initial distribution would be pack1.projectname. Next version pack2.projectname. Also, when not updating code in an entire file, you can just import pack1.projectname.handler.EventHandler; import pack2.projectname.builder.RandomFile; pack3.projectname.init.init; These is a very organized way to develop in Java using Eclipse.

    Hope this helped you on your quest to beginning your projects in Java. I will not write Java code on stackoverflow unless the person asking shows a snippet of his own project, and just cannot break through his coders block. Practice makes perfect.

    0 讨论(0)
  • 2021-02-01 16:23
    /*
     * put this in a file named CommandLineExample.java
     *
     */
    
    class CommandLineExample
    {
        public static void main ( String [] arguments )
        {
            System.out.println("Hello, world");
        }
    }
    

    type the following from the command line to compile it:

    $ javac CommandLineExample.java
    

    then you can run it from the command line like this:

    $ java CommandLineExample
    
    0 讨论(0)
  • 2021-02-01 16:26

    there is nothing special that makes it console, just use the standard output and standard input, no swing or awt and that's it.

    once you have the jar file just issue

    java -jar file.jar
    

    or if you don't have jars just

    java package.name.ClassName
    

    withouth the trailing.class

    0 讨论(0)
  • 2021-02-01 16:28

    How to make a console application in Eclipse.

    1. File - New - Project
    2. Select "Java Project"
    3. Name it "MyApp"
    4. Right click on MyApp/src
    5. New - Class
      • package name, like "com.sample"
      • Class name "MainClass"
      • check box "public static void main()"
    6. add this line System.out.println("hello"); to main()
    7. Right click "MyApp", Run As - Java Application.
    0 讨论(0)
  • 2021-02-01 16:28

    What you could do is create a JFrame with a text box at the bottom. This will be where you type. You could then add a jlabel any time you press enter. Also, it will move all other existing jlabel output up by the height of the new jlabel. This gives kind of a terminal type window.

    0 讨论(0)
提交回复
热议问题