Is there any Python-like interactive console for Java? - java

I spent a lot of time programming in Java recently, and one thing I miss from scripting languages was the ability to test them in a console.
To quickly test a java program, I have to edit a file, then turn it to bytecode and execute it. Even using an IDE, it loses its fun after the 372 th time.
I would like to know if there is a product out there that features anything like an interactive console (I bet you need a JIT compiler) and some autocompletion (with relexivity, I suppose it's possible).
Maybe that's something very common that I just don't know about or something completely impossible, but its worst asking :-)

Yes; jshell, and before that some close approximations are Groovy, Clojure, Scala, and the Bean Shell.

Funnily enough, you get an interactive console with Jython ! You don't get much more Python-like.

Java REPL
http://www.javarepl.com/term.html
with an intellij plugin:
http://plugins.jetbrains.com/plugin/7215?pr=

Try Dr Java's "Interaction Pane".

JShell is now standard in Java 9.
JShell introduction

An approach that I have used to some degree of success is to debug in Eclipse and use the display view. What the display view gives you is the ability to manipulate the code currently running in the JVM through executing Java statements. Any object available at the particular break point you are stopped at is in scope within the display view. While this isn't exactly what you are looking for it does provide some of the features that a REPL provides for other programming environments. See Debugging with the Eclipse Platform for more information.

You can execute Scala interactive interpreter too.

You may be interested in Groovy.

You can use BeanShell to run arbitrary Java code. If you want Eclipse integration, EclipseShell has BeanShell support.

Jgrasp IDE have a interactive console where you can test in,
i use it a lot, and there is alos a debug view showing variabel etc
efter you have deklare them.
It is opensoruce and you can get a copy att
http://www.jgrasp.org/
// Anders

I've occasionally run into the same problem and have a partial solution. I keep around a file (as Charlie Martin said, Java needs its class contexts) that is little more than a test program. In a second window - a console - I have a script that I run that just checks the modification time of the source file every second or two. When it sees the source change, it re-compiles it (I'm usually fiddling in C, but I've done this with Java, as well) and executes the result.
It's not a great solution, but its a fast one-off and I've found it to be very useful.

Related

If Java is truly platform independent, why is there no one-for-all clearConsoleOutput libraryMethod?

I wanted to write an application for windows/mac/linux and I chose java because a java developer friend told me Java is platform independent.
I came to a problem where I wanted to clear the console (to make the reading easier on the user).
I've tried System.out.flush(); and Runtime.getRuntime().exec("cls");.
It seems the only real solution is to use a hack (and smelly code is bad) - Java: Clear the console (check "Dyndrilliac" answer).
The reason using this hack is bad, as other users have commented on "Dyndrilliac" answer, what happens when Microsoft or Apple changes the command name from "cls" or "clear" to something different? It pretty much breaks your application and you get an error (such as "command not recognized") from the OS Company.
So my question is: did Java decide not to implement a library that handles clearing console outputs due to keeping it up to date whenever Windows/Macs/Linux decides to change it's command names? Or did Java implement a library for handling this, and I just can't find it?
Java is independent in the way that it's not run directly on your OS. java run on jvm (java virtual machine) and because of that it should work the same in all OS. But the console that you print to it's the specific OS console and therefore, every OS will have it's own clear console command (because it's not the same console). You can build program with UI (using swing or other library) And control your output, or use some technics like in the post you linked to, it should work fine.
A) because there are many many more platforms java is running on that might have extremely different views on what a console is.
B) in order to give decent tooling for console based applications, you need much more than simple "clear" commands (think nurses here!)
And finally: when Java came into existence, anything was about applets and ui. Probably nobody wanted to invest much energy in supporting "legacy style" command line programming. (that last point is probably closer to an opinion than a hard fact).

Is writing Intellij plugin in Go possible?

I'd like to write Intellij plugin and I wonder is it possible to do it in Go language? If so, what are my options; as pure go? as compiled to bytecode program acting as service and incorporated in plugin jar? Maybe something else? I want this to be fast and I hope it's not limited to JVM languages.
I'd like to write Intellij plugin and I wonder is it possible to do it in Go language?
As long as the language supports working with JVM it will be possible to do it. Otherwise no. As Go does not support this for now, the answer is no, you cannot.
So far I know of plugins written in Java, Kotlin, Scala.
I want this to be fast and I hope it's not limited to JVM languages.
In many many cases Java / JVM is just as fast if not faster then Go code. Keep in mind that the IDE is meant for being opened hours at a time and that gives the JVM a fairly good chance to optimize the code on-the-fly which can make it even faster than before.
For example the Go plugin for IntelliJ had a long standing problem with Delve (the Go debugger) as it was sending requests too fast to be handled in-order by Go and a special RPC implementation was needed in Delve. No other editors were this fast.

debugger for C/C++ and Java

I mainly use vim, but I really like the debuggers used in modern IDEs such as Netbeans, Visual C++, and Eclipse and I am wondering if there were any debuggers like those except in a standalone program? I tried using gdb, but it seems that debugging will take a lot longer using a command line. I also tried ddd, but it was a little frustrating to use since it would not display some complex structures with arrays. I really like how the debuggers in the modern IDEs allow me to just click on the down arrow to view what are in my arrays something which I do not know how to do in gdb or ddd.
You could have a look at:
http://code.google.com/p/jswat/
It's a standalone java debugger. I'm afraid it doesn't support C++ debugging.
Try Nemiver, which is a standalone graphical debugger for C and C++. It is openly developed as part of the GNOME project and uses gdb underneath.
http://projects.gnome.org/nemiver/
For windows you can use windbg. It is very good.
Don't know about Java, but for C++ you don't need an IDE to use a debugger. It is perfectly possible to code with vim and use a standalone debugger, such as windbg or gdb. In fact, that's what I do all the time.
Use Eclipse. You can easily create an Eclipse project around existing code, and still use VIM to edit your files while using Eclipse to debug.
IntelliJ is free now so it should be a good choice, I've found it to be easier to use than Eclipse but I haven't used Eclipse too much. A few features like smart complete (Ctrl+Shift+Space that lets you import/complete constructors), independent run/debug consoles that can be viewed at the same time, hotswap debugging and autosave help me save time on day-to-day programming tasks. However, there's a lot of support and plug-ins for Eclipse since it's always been open source so it really depends on what you want to do.

What are some good plugins for developing Java in VIM?

I love vim, but not having things like IntelliSense/Code completion from Eclipse makes it pretty difficult. I know, I know, I should be able to look at method signatures and java docs for the API I am interested in using. I'd love to, but I'd like it to be accessible from my fingertips instead of having to browse the source tree manually or have a JDK reference handy.
What plugins would make this easier?
I tried eclim for a while. It was pretty good, basically it uses eclipse in the background as a kind of engine and provides a plugin to let you use all of eclipses goodness through vim.
http://eclim.org/
Don't write Java in Vim — put Vim inside a Java IDE:
IdeaVIM for IntelliJ
viPlugin or Eclim for Eclipse
jVi or ViEx for NetBeans
I love Vim, but using an IDE for Java is the only way to stay sane. A decent Java IDE will:
Show invalid syntax or type errors
Show missing JavaDoc
Manage import statements for you
Highlight unused methods and variables
Safely perform powerful refactorings such as moving methods or renaming classes -- (no, search and replace doesn't cut it, I promise)
Reformat your code automatically or on-demand
Vim can't do the above, but you can use all the Vim keybindings in a program which does.
I use Eclipse + Vrapper. Enables the vi dual mode editing we all know and love. <ESC>
Completely free and lightweight. The goal is to have the comfort and ease which comes with the different modes, complex commands and count/operator/motion combinations which are the key features behind editing with Vim, while preserving the powerful features of the different Eclipse text editors, like code generation and refactoring.
While eclim is another alternative, I feel eclim takes over Eclipse and vrapper doesn't.
Check out the JDE plugin for Vim. It provides Java omni-completion and a documentation viewer (among other things).
I use the javacomplete.vim plugin for omni-completion for java. It's a very nice script: it also shows the method signatures on top of the omni-completion. The downside is that it is a bit slow, but it has worked fine for me otherwise. Eclim might be better ut I haven't tried it yet so I can't comment on it.
I've also used the jcommenter.vim plugin for generating javadoc comments. It can parse method signatures and automatically add the relevant #param foo fields and such.
For the API searching I would suggest on overriding the K key on normal mode. It searches man pages for the keyword under the cursor, but the behavior can be overriden by setting the keywordprg variable. See this thread for an example.
Other scripts which I've found very useful (not specific to Java development): NERDCommenter, AutoClose, snipMate, Align.
There's an IntelliJ VIM plugin as well. Plus, IntelliJ is released an open-source, free version.
Vim is not an IDE replacement. But very specific additional tool. With Vim you should only do small-fast tweaks while the main development is going under Netbeans/Eclipse/IDEA.
One more time. It is a Bad Bad Bad idea to turn Vim into Full IDE. Why? It won't be so fast. And thus won't be so pretty.
Here is scenario. You have opened Eclipse or whatever to edit your current task. And in 10 minutes you have to switch to another Task which is kind of urgent. The task is to tweak a little a maven or an ant built script and/or some deployment perl/python/groovy scripts.
How much time will it take to reload Eclipse to work on a new 5 minutes task and switch back?
But if you are Vim guru you can handle this in seconds. You can change one file and run Ant/Mvn within Vim.
And this is the power of Vim. You can change and check one file in no time no matter which extension it has: java, groovy, c++, makefile, bash, c#, etc.
This will be an uphill battle. There is so much knowledge about your program built into Eclipse, that I expect you will eventually have to reimplement it all to be happy.
Any particular reason you cannot just decide you like the built-in editor in Eclipse?

Good Java Practices in Ubuntu

Hey all, my Computational Science course this semester is entirely in Java. I was wondering if there was a good/preferred set of tools to use in ubuntu. Currently I use gedit with a terminal running in the bottom, but I'd like an API browser.
I've considered Eclipse, but it seems to bloated and unfriendly for quick programs.
Java editing tends to go one of two ways; people either stick with a simple editor and use a terminal to compile/run their programs, or they use a big IDE with a zillion features.
I usually go the simple route and just use a plain text editor and terminal, but there's still a lot to be said for IDEs. This is especially true when learning the language, since hitting "spam." brings up a dropdown with all of the fields and methods of the spam object. And this is not just useful to a beginner; it remains useful later on when using unfamiliar libraries and third party modules.
IDEs also have useful tools such as GUI builders which become invaluable when doing professional Java work. So although I typically prefer a simple editor/terminal combo, I highly recommend trying out an IDE such as Eclipse or Netbeans to see how you like it and so that you'll know how to use one later on.
Eclipse may be bloated for learning needs, but will probably give you the best overall Java experience. Try working through some of the built-in tutorials if you find the interface confusing.
I too vouch for eclipse (or IDEA if you have the money, actually IDEA is better than eclipse by a small margin).
But, make sure that you know how to compile and debug without an IDE first, and also learn to read the compiler's warning/error messages - they are essential skills for developers that using an IDE can prevent you from learning.
Eclipse and NetBeans are both good options. If you don't mind paying a little, so is IntelliJ IDEA (an academic license costs $99).
As far as IDEs go, I've found Eclipse to be about the best you could ask for. If you are used to IDEs full of features like VS, it should be right up your alley, and it isn't particularly resource-hungry; the way it organizes your projects makes the whole thing pretty simple as well, and it's also good to have on your resume. If you're looking for a non-intrusive IDE, mostly intuitive and that does its job as a great assistant, go with Eclipse. Not to mention its customization options.
If, on the other side, you'd like a much more light IDE, textPad-style (why?), I'd recommend Geany; I've worked with it in the past and it's got all the basic features to get started with the language and not be overwhelmed with all the features that big IDEs can offer. But I'd still recommend to go with Eclipse as soon as you get used to the language and need the IDE to be more of an assistant.
Another vote for Eclipse. In particular, you should be able to install it from within Ubuntu, as there are packages for it in one of the repositories (I forget which one specifically, as I'm not at my Ubuntu machine right this minute). If you use the GUI package-management application under the "Admin" menu, you should be able to find Eclipse and related packages.
I'd actually just recommend Eclipse. It seems bloated at first, but once you get used to it, you can use it to develop code very very quickly (and thus it's an excellent choice for a quick bit of Java).
Features I like:
Control+1 for error fixing - it knows how to fix most compile errors - just highlight the error in the code (which will be underlined in red) and it will give you a list of suggestions. Control+1 selects the first suggestion, which is almost always correct.
You can use this error fixing feature to write code that uses methods you haven't written yet - the error fixing will create the method on the class/interface you called it on, with the correct parameters/name/visibility etc. Or, if theres a similarly named method with similar parameters, it will suggest you've spelt it wrong when you called it.
The refactoring tools are also supergreat - you can highlight a block of code to extract as a method, and it'll work out what variables need to be passed in, and what it should return (if anything). You can move variables between field and methods. You can change class/interface/variable names, and it will correct them only where it needs to (which beats a search and replace any day).
You really don't need to know many eclipse features to get the benefit of using it - and it'll dramatically speed up your coding. I wish I'd known how to use it at University.
Basically, I'd recommend Eclipse. The time saved coding will make up for having to click "yes" a couple times when you start a project..
I'm using NetBeans with success right now.
I usually just use vim, but i've actually found the IDE Geany quite intuitive with a lot of good features but not really overblown. Check it out.
EDIT: I don't think Geany is fit for enterprise-level programming, but for a quick program it's one of the better IDEs I've seen, especially if you've had bad experiences with NetBeans or Eclipse as I have.
As many others, I suggest you to use Eclipse. It works fine in linux and after a few days you will find it not so unfriendly.
Moreover, if you will start developing more complex programs in java, you already will be familiar with a standard, complete and open source IDE, which is also the foundation for many other professional IDE for other languages, like Adobe Flex Builder, Aptana Red Rails and so on.
There is an interactive "IDE" designed especially for learning: BlueJ at http://www.bluej.org/
While I generally agree that Eclipse, NetBeans, or one of the other IDEs can be very helpful, they are pretty heavyweight for a learning environment; and you can end up spending your time wrestling with the IDE instead of learning Java.
In my career I've also found some people that don't really understand what the IDE is doing for them; they are totally lost without it (see Voodoo Programming). I recommend you spend at least some of your time with a simple editor, like gedit or vim, and the command line javac compiler.
BlueJ is considered a good editor for Java, tough mostly aimed at beginners. It does not bloated as Eclipse, but contains many useful features. It is also an open source project, so you are welcome to give it a try.
In our working enviroment we have to use the free Oracle JDeveloper ... sigh .. at home I tend to use Eclipse more and I really like it
Netbeans is a heavy but good IDE. Netbeans always have many features you don't really need, but because it's made with the netbeans platform, you can always strip it down to the essentials !
If you don't like all the work, go with eclipse. It's a lighter IDE.
Geany is pretty handy, don't quite know how it is with programming Java, but with programming C and C++ it's a nice light weight IDE. (BE WARNED: Building big projects usally tend to fail in geany. Workaround: compile in Geany build in terminal)
Bryan

Categories

Resources