Why sysout won't work? - java

I checked the preferences settings in my Eclipse, it's all set to default with sysout option on, but when I typed sysout in eclipse, it won't automatically go into System.out.println().
I've checked several other related topics which mention ctrl + space.
It is a shortcut for input method on my computer. I don't know if this is related to my unable to use the sysout. If not, please let me know how I can get my sysout working.
If yes, please kindly let me know how I can reset 'ctrl + space' or set other shortcut for content assistant.

Eclipse > Preferences > Java > Editor > Content Assistant > Advanced
Make sure Template Proposals is checked in one of the shown lists.

In recent version of Mac (10.14.1) , Mac OS Settings --> Keyboard --> Shortcuts(tab) --> Input sources.
uncheck the setting ctrl +Space.
Now go to Eclipse IDE and it should work.

You have to press Ctrl + Space for the sysout (or equivalently: syso) shortcut to work in Eclipse, as sysout is not part of Java in anyway, on the contrary: it's an abbreviation introduced in Eclipse that only works after you press Ctrl + Space and expands to System.out.println().
By the way, syserr (or equivalently: syse) will expand to System.err.println() after pressing Ctrl + Space.

public static void main(String[] args)
This public static void ... blah blah has to be put for the sysout
to work

After trying all the answers above with no success I found another reason why Ctrl+Space could be prevented from working.
In my instance Ctrl+Space worked for some projects in the workspace but not others. I discovered that the project that it did not work for did not have the jdk in the build path, instead it had the jre for the application server (weblogic 12). The application ran fine on the server but Ctrl+Space to open the template proposals didn't work and other things like syntax highlighting were not quite right.
I hope this helps anyone who comes to this questions 3 years after it was asked (Like I did).

Eclipse Shortcuts:
Syso + Control + Space: Puts System.out.println()
Alt + Shift + R: Rename
Control + F11: Run
ALT + Up/Down: move the current line (or lines selected) in the editor up or down
Control + Shift + O: Import
Control + I: Indent
Control + D: Delete Line
Control + H: Search Your Entire Project

I had the same problem achieving simple ctrl+space templates with eclipse using jre. Showed empty templates for everything.
Try installing the jdk in separate directory then add into Preferences / Installed jre: add in the new directory. Then use that in your build path. It should solve the problem.

Is there anyway to modify the keyboard shortcuts in eclipse? here you can find out how to make a custom shortcut Window -> Preferences -> General -> Keys
edit: here is a video tutorial http://eclipseone.wordpress.com/2010/02/03/how-to-manage-keyboard-shortcuts-in-eclipse/

For me sysout in eclipse created in two lines. println() in new line..Then I found myself how to avoid this and get System.out.println in one line ..go to Windows > Preferences > Java->Templates (or type templates on search field in top left corner box).Then In template configuring section uncheck "use code formatter"..thats it.. :)
System.out
.println();

Seems like you in windows and your keyboard shortcut for eclipse is got replaced with the system keyboard shortcut for language. well, either you replace it the keyboard combination to shows the template proposals by :
1. open the preferences dialog
2. go to general -> keys
3. in the search dialog, find the command `Content Assist`
4. change the binding and then click OK button
or, you can change the combination key to change the language in the Text Services and Input Language and then go to the Advanced Key Settings tab and then change the key sequence.

Select in the menu bar "Window > Preferences > Java > Editor > Templates"
deselect at the lower end of window: "Use code formatter"

In my case it didn't work because ctrl+space was being used by another program Ubuntu(I-Bus) in my case ref. here Try changing ctrl-space by another key combination in general->keys to find out if this is causing the problem.

I started having the same problem with sysout shortcut when I installed the Scala plug-in in Enclipse. None of the answers worked, but the solution turned out to be very simple. I unchecked all Scala templates in Preferences -> Scala -> Templates So if you use any plug-ins, make sure their templates do not get in the way of your Java templates.

I was facing the same issue. If you use OS X Eclipse Ctrl+Space shortcut can be interfering with OS X system's "Selecting previous input source" shortcut using Ctrl+Space shortcut as default. OS X system shortcut has higher priority, that is the reason why Eclipse does not work.
Just go to System Preferencies/Keyboard/Shortcuts/Input Source and uncheck the "Selecting previous input source" or change the shortcut on something else. Eclipse should work after that even without restart.

I had the same problem. I had ctrl + Space used as a shortcut for input source in Mac. To disable this go to settings -> Keyboard -> Input Sources and uncheck Select the previous source. Than syso shortcut will work.

set your perspective on default and your problem will solve.
window -> perspective ->open perspective -> other -> select default

Related

Eclipse Organize Imports shortcut not working on Mac

I'm using Eclipse (STS version 3.9.0) on macOS Sierra. I have a fresh install of STS. Organize Imports (Cmd + Shift + O) is defined out of the box. I can get this function to work by going through the menu entry Source > Organize Imports, but the key combination does nothing.
Additionally, the shortcut combination is not shown next to the menu item, while other menu items do have shortcut combinations shown.
What can I do to get this functionality via keystroke?
I have seen this happen on two different machines.
I have checked there are no other conflicting keybindings by sorting by the binding:
In Preferences > General > Keys > Filter the keys for ⇧⌘O
By changing the When from In Windows to Editing Java Source, the shortcut key started to work for me.
I've seen the answer on the comments above but it wasn't easy to see, that's why I'm writing it right here for more clarity. Thanks Paul for the question & answer.
Try the following steps:
Go to Windows -> Preferences-> General -> Keys on STS Menu
Click "Filters..." on the Keys page and uncheck all.
Enter "⇧+⌘+O" to search the command list for ⇧+⌘+O.
You can see the command list, and then unbind commands other than "Organize Imports".
Click "Apply".

Netbeans Javadoc auto-displaying

I am working on an xml file inside of Netbeans and something changed in my settings where when I open up a bracket, it turns the bracket red and displays the Javadoc in addition to the code-completion tool.
I like the code-completion but not the javadoc. Does someone know how to turn it off the Javadoc?
I found out the answer:
In Netbeans, go Tools -> Options -> Code Completion -> uncheck "Auto Popup Documentation Window"
I'm still not sure what keyboard shortcut I hit to enable it in the first place, but this turned it off.

Intellij code formatting, Java annotations on new lines

I'm using IntelliJ 12 and
It's putting my member variable annotations on the same line, which i hate! How do I setup the code formatter to keep annotations on separate lines?
thanks!
Navigate to Preferences → Editor → Code Style → Java → Wrapping and Braces tab, then locate the section Field annotations and check the option Do not wrap after single annotation.
In IntelliJ v14:
In IntelliJ 12 You can find it in setup here (bottom right):
I think all the above answers are correct but here is step by step for Mac users:
Click on "IntelliJ IDEA"
Click on "Preferences"
Go "Code Style" on the left navigation window and you will see "Java" listed below it and Click on it !
Look for the header tab "Wrapping and Braces" on the right side of Preferences window.
At this point you want to look for the item called "Do not wrap after single annotation" under "Field annotations". click "ok" and you are done !
Nothing seemed to work for me with version 2.3.3 or Android Studio. I gave up and checked Line breaks under Keep when reformatting. I just have to be very careful when I add line breaks.

Stop spacebar keypress from triggering autocomplete in Eclipse

Update
This was fixed in Eclipse 2018-12. This behaviour is still default, but can be configured off - see the accepted answer for how
I'll leave the question as it was for posterity, and for those on earlier versions of Eclipse
In Eclipse, I've enabled intellisense-style suggestions for Java by going to
Window -> Preferences -> Java/Editor/Content Assist
and setting the following
Auto activation delay (ms) -> 0
Auto activation triggers for Java -> .(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
source = Eclipse Intellisense?
This works brilliantly, apart from one annoying problem. When I hit spacebar, the token being typed is autocompleted with whatever is at the top of the suggestions list. Fair enough, except that sometimes I'll type a class/variable name with an exact legal match, but this won't appear as the top suggestion. So when I naturally hit spacebar Eclipse inserts something completely wrong.
E.G. after typing Cookie I'll hit spacebar and get CookieMonster.
This seems like a bug, and happens often enough to be annoying, but even despite this I don't want spacebar to trigger autocomplete in general. I may want to type a variable name which hasn't been declared yet, or something similar. I want to use autocomplete as a helper tool, but my natural typing should always take priority over it.
I'd like to stop spacebar triggering autocomplete, and either fall back to using enter, or better still trigger autocomplete with a custom key not used in ordinary typing. Is any of this possible?
I've played around with all the settings in Content Assist to no avail. Googling the question just returns a bunch of results about disabling the autocomplete feature.
This issue is fixed from Eclipse 2018-12 [4.10] see the accepted answer
It's present in all prior versions, i.e. 2018-09 [4.9], Photon [4.8], Oxygen [4.7], Neon [4.6], etc..
Eclipse 2018-12 was already patched for this!
A patch for Bug 348857 was recently merged to the Eclipse project and was released as part of Eclipse 2018-12. You can download that version here.
You now have a new option to disable all insertion triggers apart from enter, which will prevent spacebar from causing autocompletion.
Simply go to Preferences... -> Java -> Editor -> Content Assist (or Window -> Preferences -> Java -> Editor -> Content Assist on Windows) and select Disable insertion triggers except 'Enter', as shown in the screenshot below:
There is a solution on the issue tracker for this.
Copy the jar in the eclipse/dropins folder. With the next restart space is diabled as autocompletion trigger.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=348857
Eclipse 12-2018 and newer: This is working natively, check Pyves answer.
Use a SDK version of eclipse
1.open Plug-ins View and find org.eclipse.jface.text, right click, choose import as Source Project. After import, you find it in your workspace.
2.In src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java
char[] triggers = t.getTriggerCharacter();
if(contains(triggers,key))
change to
if(key!='='&&key!=0x20&&contains(triggers,key))
3.Export org.eclipse.jface.text
Right click the project folder of org.eclipse.jface.text, choose export-->Deployable plugins and fragments, next, destination choose archive file, finish. Replace the one in eclipse/plugins with the one you generate.
The spacebar has been a key to select the autocomplete even in Indigo. To my knowledge, this can't be configured.
In fact, that is probably why the delay exists.
I suggest setting the delay to some optimal value that allows you to type things like private void ... comfortably without triggering suggestions for private and void. Then in case you get a suggestion because you waited too long, press Escape to abort Content Assist.
Same configuration as davnicwil, same issue, still on eclipse 4.4.
Solution: Intercept (hook) SHIFT+SPACE (press and hold) on (editor-window) eclipse and replace it with ESC,SPACE (sequence). Now you my decide between
Autocomplete+SPACE: press SPACE when autosuggestion present
just SPACE: press predefined key combination or sequence (e.g. SHIFT+SPACE)
On windows you may use http://www.heise.de/download/activaid.html (you can also use AutoHotkey, java native hook, ...)
HowTo with ActivAid:
Open Ac'tivAid, select "UserHotkeys"
click on "+", set a description
click on "short cut", press e.g. SHIFT+SPACE
Command: "{ESC}{SPACE}" (without quotes)
click "+", select eclipse editor frame, press ENTER
click OK, OK in Ac'tivAid
My config file:activAid/settings/ac'tivAid.ini:[UserHotkeys]
Hotkey11=+Space
Path11=<Send>{ESC}{SPACE}
Description11=Eclipse Shift+Space -> Esc,Space
Category11=
Application11=ahk_class SWT_Window0
You may also remap keys on non-english keyboards with "HotStrings", e.g. ö->{,ä->} etc.
Finally worked it out.
Try download this org.eclipse.jface.text.jar and copy it to your plugin folder(Typically eclipse/plugin). Do not forget to backup your own one.
Works on Eclipse Juno.
If the link doesn't work, comment on this, thanks.
In Eclipse go to Window -> Preferences -> General -> Keys and remove the binding for the command Content Assist.
You could disable Auto activation via the check box in
Window -> Preferences -> Java/Editor/Content Assist
and activate the auto-complete feature on demand. The default hotkey for this is
CTRL+Space

IntelliJ Organize Imports

Does IntelliJ have an Organize Imports feature similar to that in Eclipse?
What I have is a Java file with multiple classes missing their imports. Example:
package com.test;
public class Foo {
public Map map;
public JTable table;
}
In Eclipse I could use Organize Imports and it would automatically import both java.util.Map and javax.swing.JTable. In IntelliJ I have to individually go to each class, select it, then press Alt-Enter. There is an Optimize Imports feature but all it seems to do is sort and expand the existing imports.
I'm using IntelliJ 10.5.
Ctrl + Alt + O (Code → Optimize Imports...) is what you're looking for, both on Windows/Linux and macOS keymaps.
It says "Optimize", but, if configured to do so, it will also:
organize existing imports
remove unneeded imports
add new required imports
add unambiguous imports on the fly
You can tune the auto-import settings under "Settings → Editor → General → Auto Import" as described by Dave.
You can also modify how the imports are auto-ordered under "Settings → Editor → Code Style → Java → Imports"
Under "Settings -> Editor -> General -> Auto Import" there are several options regarding automatic imports. Only unambiguous imports may be added automatically; this is one of the options.
Simple & short solution worked for me.
Go to File -> Settings -> Editor -> Auto Import -> Java (left panel) and make the below things:
Select check box for "Add unambigious imports on the fly" and "Optimize imports on the fly"
Refer this.
In addition to Optimize Imports and Auto Import, which were pointed out by #dave-newton and #ryan-stewart in earlier answers, go to:
IDEA <= 13: File menu > Settings > Code Style > Java > Imports
IDEA >= 14: File menu > Settings > Editor > Code Style > Java > Imports (thanks to #mathias-bader for the hint!)
There you can fine tune the grouping and order or imports, "Class count to use import with '*'", etc.
Note:
since IDEA 13 you can configure the project default settings from the IDEA "start page": Configure > Project defaults > Settings > .... Then every new project will have those default settings:
July 2015 - I have concluded that IntelliJ does not support automatically resolving imports with a single function. "Organize imports" simply removes unused imports, it does not resolve unimported types. Control-Space resolves a single unimported type. There does not exist a single action to resolve all types' imports.
navigate to the file where you want to organize imports or just click on the whole package or even click on the project than press CTRL + ALT + O
In IntelliJ 14, the path to the settings for Auto Import has changed. The path is
IntelliJ IDEA->Preferences->Editor->General->Auto Import
then follow the instructions above, clicking
Add unambiguous imports on the fly
I can't imagine why this wouldn't be set by default.
Shortcut for the Mac: (ctrl + opt + o)
Goto Help -> Find Action (Short Cut for this is Cntl + Shift + A) and type Optimize imports (Short cut for this is Cntl + Alt + O)
Just move your mouse over the missing view and hit keys on windows ALT + ENTER
ALT+ENTER was far from eclipse habit ,in IDEA for me mouse over did not work , so in setting>IDESetting>Keymap>Show intention actions and quick-fixes I changed it to mouse left click , It did not support mouse over! but mouse left click was OK and closest to my intention.
That plugin will automatically do the "organize import" action on file save: https://github.com/dubreuia/intellij-plugin-save-actions.
To install: "File > Settings > Plugins > Browse repositories... > Search 'Save Actions' > Category 'Code tools'". Then activate the "organize import" save action.
I finally created a workaround around this frustrating issue. I'm not completely happy with the workaround, but it's better than nothing.
Basically, after you paste the source code and unambigous imports are fixed, just press F2 to highlight the next compiler error. If the current error is an import-missing error, press Alt+Enter, then Enter to select the Import option, then pick the correct import. Then, press F2 again.
If you are missing just one import (the class name has red underline), click and hover the mouse over it, and a blue suggested import statement will appear. If you hit, Alt + Enter at this point, the import will be included in the file and the red underline should disappear.
Shortcut on Android Studio on MacOS: Control + Option + O
I did not have any wildcard * as mentioned in one of the answers, neither did any of the formatting through Android Studio mentioned worked
What helped was running this:
./gradlew ktlintFormat

Categories