Java Code Completion, My Way


Oracle Java tutorial that explains how to use the java code completion feature in visual studio.

Java Code Completion

Java Code Completion allows you to write code, and then displays a list of possible options for completing the line of code currently being typed. Code completion also saves time by preventing you from having to type in the entire package name or other information associated with your code, such as class and method names. When typing a statement, NetBeans IDE provides suggestions for completing your statement. If you do not want to complete the statement at the suggestion offered, press Escape to clear the suggestion.

So far, Java’s code completion (aka “Content Assist”) has been a constant source of frustration for me. I’ve been spoiled by Visual Studio’s IntelliSense and ReSharper. When I first tried out Eclipse, I couldn’t find any way to see the parameters for a method or constructor. You could use content assist to bring up a list of methods, but you couldn’t see their signatures until you selected them from the list.

After much Googling, experimentation, and posting on various forums, I found a way to make it work reasonably well. You can see the parameters for a method or constructor as soon as you type an opening parenthesis. Here’s how:

– Install the Subclipse plugin

– Open Preferences > Java > Editor > Content Assist > Favorites

– Click Add… > Advanced…

– Enter “org.eclipse.jdt.ui.text.javaProposal” (without quotes) in the Class textbox, and click OK

– Set the Visibility to “0”, and “Add” it to your Favorite list

In my previous post, I talked about the different ways a programmer can write code. Some programmers sit down and type out the entire program in their head before they write it down. They know exactly how to implement each feature before they start working on it.

Other programmers start by typing out the entire declaration of a class or method. They will add all of the formal parameters or instance variables even though they don’t need them yet. They will then delete these as they work through implementing each method or constructor.

Still others prefer to write out only what is absolutely necessary, such as the name of a class, method, or variable, to get code completion to generate the rest for them. Then, as they work through implementing each method or constructor, they will use code completion again and again to add more declarations and statements to their code.

Regardless of which technique you use to write your source code, one thing is clear: writing Java source code has become simpler than ever before; thanks to hundreds of features built into modern IDEs like Eclipse and NetBeans that help you write more code in less time.

I had a few minutes today to implement the first major feature I’ve been wanting in my Java editor: code completion. I say “my” editor because I’ve built it from scratch, using Visual Studio 2010 and a series of macros and addins for Java code assistance. As mentioned before, my goal is to build a lightweight but useful editor for writing Java code in Visual Studio.

For this initial attempt at code completion, I chose to keep things simple. There is no database of classes and methods like in the more advanced IDEs; instead, completion works only on local variables. This makes the implementation easy; after typing “.”, it simply searches the current file backward for any variable names that match the text preceding the dot. Using this information, it then lists all fields and methods of those classes.

I’ve been using Eclipse in all my Java courses. Eclipse is a good, solid environment, and it has good code completion—once you get used to how it works. Unfortunately, I haven’t been able to find a way around the fact that you have to press control-space every time you want to see the popup of possible completions.

The first time I used Visual Studio (I’m a C

I’ve been working on, and working with Visual Studio Code for a while now. I started with the Python Extension, which is great. Then I moved onto Java code. The Java extension is also very good!

But there was one thing that really bothered me about it. There is a “use recommendations from sdk” option – it enables code completion based on your build path, libraries and such. But it didn’t work for me. If I would try to use a method from any library imported with Maven, the extension wouldn’t find it and suggest anything – not even if the package name was already typed in! It drove me crazy…

Well, not anymore! I finally figured out how to make this work, and it’s super easy! Just add “java.home”: “” in your user settings (ctrl + shift + p > Preferences: Open Settings (JSON) > user settings). This way you can specify the JDK version used by VS Code to complete your code – yes, you can choose between multiple versions at once!

No more looking up method names because VS Code doesn’t know them…

Visual Studio Code is an open source editor available for Windows, Linux and OS X. It has built in support for TypeScript and JavaScript, and has great support for front-end development (especially Angular 2).

But what about Java?

In this blog post I will show you how to make VS Code work just like Visual Studio’s Autocomplete. This is the feature that shows a list of possible options as you type, allowing you to quickly pick the right one without having to type everything out.


Leave a Reply

Your email address will not be published. Required fields are marked *