I want to use sublime as development tool instead of eclipse, but although sublime enables to highlight the code, but how to detect the errors and compile the java code as eclipse does?
Thanks!
Sublime Text is a text editor, not an IDE. You'll need to compile it from command line using javac File.java. And it won't highlight errors for you.
If you want a simpler text editor how Java, consider jGrasp or NetBeans.
All the answers above are totally correct: Sublime Text is a text editor, not an IDE. So you'll either use an IDE for your projects (for the ease) or use Sublime + cmd line (with a little bit of pain)
However, I personally kinda like it too, especially Sublime Text 3. So I use both: intellij for real/big projects and SBT3 for small things/Code Snippets(when I read books for example) (+ quick & repeatable unit tests to assert results, no need of a bare main()) that I want to try. And this can go very fast if you're used to SBT3 shortcuts (because it is a very lightweight and fast editor) instead of launching a full blown intellij instance + gradle + etc. just for those dimple things.
Another reason for using SBT for these simple things (especially when you are learning) is that you get rid of auto completion, auto import, etc. It forces you type everything and you learn a lot!
To enable highlighting + error check on SBT3, you need to install:
Package Control
SublimeLinter + SublimeLinter-javac from Package Control (https://packagecontrol.io/packages/SublimeLinter-javac )
Seti_UX theme from Package Control (for great highlighting)
You can refer to this as an example:
How to use JUnit with Sublime Text 3
Sublime is not really ideal (imo) for Java development. If you don't want to use eclipse, you can take a look at intellij, my favorite IDE for Java and web projects.
Of course, you can use sublime for you Java projects. But you have to compile the java files. The way you do that is from terminal/dos is to write:
javac myJavaFile.java
and then you run the javac file:
java myJavaFile
If you want all the multiple selection and other cool stuff in sublime for your java development then Intellij IDEA is your choise, you'll have more cool features that are just not possible with text editor.
I love sublime but that is not the case with compilable languages like java or C++...
There you can see Intellij in action http://tv.jetbrains.net/videocontent/refactoring-in-intellij-idea-live-by-robert-c-martin-uncle-bob
Related
I want to format code in my project. First of all I want to make consistent indentation in all the java files.
I know there is CTRL+ALT+L option, but it also formats other things - spacing in braces and so on.
CTRL+ALT+I is what I want to do, but automatically on all classes in project.
I checked Eclipse plugin, JIndent tool and none of those tool meet the requirements.
What do I expect is having all java files in a consistent indentation style (2 spaces) and all other aspects of formatting not changed.
Thanks for any suggestions.
I would suggest to use Google Java code formatter which brings uniformity in both Eclipse and Intellij Idea IDE. I provide below the link.
https://github.com/google/google-java-format
You can install the plugin in eclipse and make changes in Eclipse Preference page. In case of Eclipse, you have to use the key command as CTRL+SHIFT+F
In case of Intellij IDE, you have to use the key command as CTRL+ALT+L to format the code.
You can see the screen shot for Eclipse preference Page below.
You can see the screen shot for Intellij Idea setting page below.
So i have tried to find an answer but didn't manage to do it yet. What I'm trying to do is to write a Java code for example in Atom editor, and compile it on Atom itself, without the need of an integrated development environment. Same goes with adding classes to a project.
Is that possible?
Yes. That is how they wrote the first Integrated Development Environments. Although the compilation step is typically performed externally from the editor, if the editor can execute external programs then you can "integrate" compilation. Adding "classes" is a little more involved, in that it requires your "editor" to understand the packaging and structure of the files composing the classes - at that point you have an integrated development environment.
Yes it's possible with atom package build. To install the package Edit-->Preferences-->Install and type build and hit Enter. Then you should configure your custom build command as mentioned in official package website. You may just fill cmd: javac in yml file for example
You need to install a package that will compile. Atom is a hackable text editor but not really an IDE as you pointed out. That said there are a lot of packages for compiling and for working with java.
You can look at Build Tools Package for compiling. It looks like it will work for Java but there are many compilers in the package list.
I would search on their package site for the keyword "Java" to see what java packages you might want to use. Then do another search for "Compile" to see what compiler you might want to use if the build tool above doesn't work for you. You can search atom packages at https://atom.io/packages.
I wonder if I can get the Java Sublime Text snippets working on Eclipse IDE (Kepler) because I think that auto completion is better in ST then in eclipse.
Thank you.
--Sangimed.
I'm not sure which way around you meant to ask that question, but here is my try at answering it.
Sublime Text snippets are store in the Packages directory. If you were in Sublime Text 2 and went to the File menu -> Preferences -> Browse Packages...
It will open the local packages for your installation of ST. If you look under "Java" you will find all the local information for Java that is built into ST by default. Which should include all of the ST snippets you are looking for... they are files with the extension .sublime-snippet
However, here is the tricky bit. ST snippets are stored in an xml format designed for ST, so you will need to grab the data out of the "content" node in that XML file, here is an example:
<content><![CDATA[assert ${1:test}${2/(.+)/(?1: \: ")/}${2:Failure message}${2/(.+)/(?1:")/};$0]]></content>
What you need is the content inside of the CDATA:
assert ${1:test}${2/(.+)/(?1: \: ")/}${2:Failure message}${2/(.+)/(?1:")/};$0
However, this won't make sense to Eclipse right away you'll need to replace the sublime annotations with Eclipse ones, see the Eclipse documentation for more details and the Sublime Text documentation on snippet details.
But perhaps you meant you want the best of both world, Eclipse and Sublime Text together... in that case you should look at the project Subclim, which allows you to integrate the power of Eclipse inside of ST.
I am trying to begin writing a Java program in Xcode 4.4 but, At the moment, I am stuck with the file extension .cpp, which I believe is for C++. Can some please tell me how to set up a .java file (or project, or whatever the term is)...? I am extremely new to programming, and to Xcode, so please keep all instructions /very/ simple.
I have created some Xcode Templates for Xcode 4 here
http://www.2shared.com/file/hExLjJ1X/Java_Xcode4_template2.html
To install the template in Mac, use Terminal command
mkdir -p ~/Library/Developer/Xcode/Templates/
unzip ~/Downloads/Java_Xcode4_template2.zip -d ~/Library/Developer/Xcode/Templates/
You can use command-B to build. To Run, you should use "Edit Scheme..." and change the Executable for the "Run" Scheme
If you're new to programming you might want to try this in a different way.
Better IDEs for Java are Netbeans and Eclipse. I've used Netbeans for Java and PHP as well. It behaves as you could expect from a modern IDE with a lot of possibilities for customizing it to your needs/preferences.
Xcode is great and has many useful tools but it's focused on objective-c and iOS environment.
Good luck!
I am using XCode currently.
Open a new project.
Click External Build System.
Name your file, using the extension .java.
Write $(TARGETNAME).java next to $(ACTION).
Open a new file (empty style).
Start writing your program.
XCode is not the best place for Java, but I use it since it is a developer tool for Apple and it has great syntax coloring and auto-indentation, etc.
TextEdit is another app (probably already there if you use Apple Mac), but no syntax coloring and fancy features. It is simpler to use, and always use Terminal (try to avoid using the XCode Build - the errors are hard to decipher and the process is complicated, also if you have any questions, few can answer it because most do not use XCode).
Good luck!
I have many Java files from a project which have not been formatted properly. Also due to enforcement of a common style many people have introduced their own coding style. I want to bring all this code to one consistent format. Are there any auto-formatters available which I can run as script on all the files. I would like to rethink and fine tune following options:
Number of spaces used for indentation.
Spaces around operators like + - * / etc.
Separation between parentheses.
etc.
I was looking at Netbeans auto format and looked cool. Moreover the parameters can be set from the option dialog. However I am not able to completely grasp how to use the API
You can use the Eclipse JavaCodeFormatter from the command line:
The following example runs the formatting of code specified by the
configuration file D:/formatter.prefs on the files Java belonging
(directly or indirectly) to the directory D:/tmp/src :
eclipse -application org.eclipse.jdt.core.JavaCodeFormatter -config D:/formatter.prefs D:/tmp/src
See http://wiyoo.blogspot.com/2007/05/batch-formatting-java-source-code-with.html for details.
Why use the API? Bring it in as a NetBeans project. Same with Eclipse or IntelliJ; they can all format all source files in a project.
For standalone, try Jalopy. It can also be set up to run as part of a build, as a commit hook, etc.
Try JIndent. Or here're a bunch of open source code formatters for Java, some of them can be run as standalone products, others as plugins inside an IDE (Eclipse, NetBeans).
Well I don't know if you use eclipse, but to do spacing and parenthasis you just press ctrl + shift + f and to do auto indentation is ctrl + i