Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJordan Jim
1,421 PointsJava IDE question.
Hi guys,
I have had previous University experience in Java but I'm attempting to re-learn Java for more work opportunities and such. I'm used to using a Java IDE such as NetBeans and Eclipse.
I'm slowly coming to find out since these workspaces work like text editors and you're compiling the files yourself and certain functions such as "java.io.Console" do not function in such IDE's.
Should I just ignore IDE's for now since they only aid in Java development?
3 Answers
Seth Kroger
56,413 Pointsjava.io.Console is a nice convenience that gives you input and output in one object which makes it great for learning Java. However, it doesn't work with IDE's and is well know not to. With an IDE, just go the System.out/Scanner(or BufferedReader) route whenever you see console. Or use the Workspaces. Whichever you want to use is up to you but you will start using an IDE anyway in later courses (Local Development Environments and Java FX).
Craig Dennis
Treehouse TeacherIDEs often wrap the input and output methods of System.out
and System.in
in order to write to a window in the app. java.io.Console is final
so the IDE manufacturers can't override it. I used it, like Seth Kroger stated because of it's ease of use and lack of cognitive overload. It was intended to only be run from the console.
Feel free to write the code in your IDE, if you kick off your program from a command line it will work just fine, it's just with the normal IDE redirection that causes problems.
Jordan Jim
1,421 PointsThank you for the quick reply. It makes it sense. Using a Mac I would be able to run this from terminal correct? How would I make that happen?
Craig Dennis
Treehouse TeacherHi Jordan!
Yeah, so from your terminal navigate to where your project is located. At the root of the src directory, run
javac Example.java && java Example
Assuming your paths are setup correctly (and they probably are if NetBeans works) it should just happen. javac
compiles and the java
command takes a class name. It is expected that there will be a static
method named main
that takes an array of String arguments and returns nothing.
Hope it helps!
Christian Andersson
8,712 Pointsjava.io.Console
should work in any IDE. What did you try to make it work? Did you create an instance of System.console()
before using any console commands?
Personally, I think it's better to use IDEs' and get used to those, rather than something else. The courses here in treehouse that don't use any IDEs' are probably just intended to make the learning easier for beginners.
What I think you should do is try and learn the algorithmic ideas and logic behind the various problems presented in the courses, rather than trying to learn how each individual command is written, since the approach will be slightly different when you don't use the Console
class in an IDE environment.
Jordan Jim
1,421 PointsSo for example.
When building a simple io program.
And I would always create an instance such as:
"Console in = System.console();" "in.readLine("Enter your age");"
Would give me a pointer exception in Eclipse on the in.readLine line.
I'm used to the concept of Scanner such as the java.util.Scanner;
Christian Andersson
8,712 PointsIt gives you a pointer exception because System.console()
returns null
. This is a bug within Eclipse, but it should work in Netbeans and other IDEs'.