Please advice on where can I find the lib in order to use the shorter expression of System.out.println()
and where should I place that lib.
As Bakkal explained, for the keyboard shortcuts, in netbeans
you can go to tools->options->editor->code templates and add or edit your own shortcuts.
In Eclipse
it's on templates.
Java is a verbose language.
If you are only 3 days in, and this is already bothering you, maybe you'd be better off learning a different language like Scala:
scala> println("Hello World")
Hello World
In a loose sense, this would qualify as using a "library" to enable shorter expressions ;)
You could use logging libraries instead of re-inventing the wheel. Log4j for instance will provide methods for different messages like info()
, warn()
and error()
.
or simply make a println
method of your own and call it:
void println(Object line) {
System.out.println(line);
}
println("Hello World");
IntelliJ IDEA and NetBeans:
you type sout
then press TAB, and it types System.out.println()
for you, with the cursor in the right place.
Eclipse:
Type syso
then press CTRL + SPACE.
Other
Find a "snippets" plugin for your favorite text editor/IDE
import static java.lang.System.out;
out.println("Hello World");
println("Hello, World!")
println "Hello, World!"
print "Hello, World!"
puts "Hello, World!"
(println "Hello, World!")
print('Hello, World!');
Use log4j or JDK logging so you can just create a static logger in the class and call it like this:
LOG.info("foo")
Some interesting alternatives:
OPTION 1
PrintStream p = System.out;
p.println("hello");
OPTION 2
PrintWriter p = new PrintWriter(System.out, true);
p.println("Hello");
My solution for BlueJ is to edit the New Class template "stdclass.tmpl" in Program Files (x86)\BlueJ\lib\english\templates\newclass and add this method:
public static <T> void p(T s)
{
System.out.println(s);
}
Or this other version:
public static void p(Object s)
{
System.out.println(s);
}
As for Eclipse I'm using the suggested shortcut syso + <Ctrl> + <Space>
:)