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
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.
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.
/*
* 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
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
How to make a console application in Eclipse.
System.out.println("hello");
to main()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.