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 trial
Chris Perrett
2,958 PointsPlease help me with my confusion. Compare and contrast sumblime text to treehouse workspaces.
I am trying to copy and paste my workspace into sublime text to try apply what I've learned. I would always use console with workspaces but I can't do anything in the sublime text console and I'm thoroughly confused.
1 Answer
Christopher Augg
21,223 PointsChris,
I had never used sublime before until now. So, thanks for introducing it to me. It is pretty amazing! It works great as a text editor. I typed up some java code, saved it as a java file, and then brought up terminal (OSX) to use the javac and java commands. That works fine for me that way. However, when I went to show console within sublime, I ran into what I think are the same issue as you. Therefore, I needed to do some research to see if we could run our java code here somehow.
Things I found:
1) It is documented that java.io.Console will not work within Sublime 2. The same goes for IDE's anyhow though, so it is a good practice to use System.out.print/println/printf & Scanner(System.in) anyhow. You can still go through the entire java track and just change console to them.
2) It is also documented that sublime 2 console will not work with any code that requires input like console.readLine or Scanner(System.in)
3) I found a way to alter the preferences so that you can use the Command + B shortcut to compile and run my java within sublime. However, considering issue number 2, it will not run anything that uses input. Rather pointless in my opinion.
Check out :
http://stackoverflow.com/search?q=sublime+text+input&s=adbf5600-c2ee-43ae-94e0-eb7bbcc5781d
Therefore, I recommend just using Terminal on OSX or CMD Prompt on Windows. You can have Sublime 2 and the Terminal up side by side and work quickly between them. Furthermore, the console code works when done in terminal. You can use console with the java tracks or switch to System.out etc.
Sublime should automatically detect that you are writing java code for syntax highlighting etc and you still get all the features for snippets and shortcuts. However, if it doesn't, you can go to view -> syntax -> java -> java.
If you want to try out the build/run yourself, you can do the following:
By default, you should be able to use the Command + B shortcut to build it. However, it will not run it.
With sublime running: Move your cursor to the top left of your screen over 'Sublime Text 2' and left-click.
Move cursor over preferences and left-click on 'Browse Packages'
Left-click on the Java folder
Scroll through the files until you find 'javaC.sublime-build'
Drag and drop that file into sublime for editing.
Replace what is there with the following:
{
"cmd": ["javac \"$file_name\" && java \"$file_base_name\""],
"shell": true,
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java"
}
Command + S to save
Close out of sublime completely and restart it.
You should now be able to build and run java within sublime as long as it is not using java.io.Console or any input. Again, I recommend using terminal with Sublime2. However, if anyone else finds a solution for the known input issue, that would great too.
Regards,
Chris