925
votes
41answers
304k views

Avoiding “!= null” statements in Java?

I work with Java all day long. The most used idiom (code snippet) I'm programming in Java, is to test if an object != null before I use it. This is to avoid a NullPointerException. I find the code ...
0
votes
0answers
28 views

How to define snippet for table creation and formatting in Spring MVC web application?

In my conroller I assign an ArrayList that contains JavaBeans objects and I need to list these objects into HTML table in a view (JSP template). It's little more complicated than that: All rows of a ...
0
votes
2answers
173 views

SWT Snippet2. Table sorting. items array changes in the loop. How does this work?

http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java I am trying in SWT to add sorting to a table widget. ...
0
votes
4answers
121 views

Why isn't this valid Java?

Surely this should be valid Java? Have I got the syntax slightly wrong? return (url != null) ? url : (throw new NotFoundException("No url")); If not I suppose I'd have to do this: if(url == null) ...
-2
votes
1answer
71 views

what does private Set<String> uniqueAuthors indicate in a java snippet?

what does private Set<String> uniqueAuthors; indicate in a java snippet?
4
votes
1answer
1k views

Snippet creation keystroke/shortcut in Eclipse

So I was using Eclipse and I went to go copy some import statements I had selected. I somehow mis-typed, and the coolest thing happened: a snippet package was created, and a Snippet.java class was ...
0
votes
1answer
106 views

Trouble with java snippets

public class GenericWorldLoader implements WorldLoader { @Override public LoginResult checkLogin(PlayerDetails pd) { Player player = null; int code = 2; File f = ...
1
vote
1answer
462 views

Graph drawing using ZEST framework when button pressed, not working?

I am trying to draw a graph using the ZEST framwework in JAVA. The intended work of code is as follows: 1) Shell is set to FormLayout. 2) Added a label, textbox, and a button using FormData ...
1
vote
2answers
53 views

Live method overrride

I'm pretty new to Java and I'm finishing my first project using it. Basically I read Head First Java and the API documentation for the classes I've used so far. That's my Java background. This little ...
9
votes
4answers
12k views

How to use the “sysout” snippet in Eclipse with selected text?

I am aware of the Eclipse snippet "sysout" which is neatly replaced with System.out.println(); when tab-completed. This is very useful but sometimes, I need to wrap some existing code in a ...
0
votes
1answer
344 views

Java to VB.Net Conversion [Small Snippet]

I have this snippet, it's in Java: final InetAddress address = InetAddress.getLocalHost(); final NetworkInterface ni = NetworkInterface.getByInetAddress(address); key = new ...
0
votes
1answer
726 views

Java to VB.Net Conversion of This Function

I have a Java snippet here, I was wondering if it is possible to translate to VB.Net, as I have no found a snippet for VB.Net - only this: private static byte[] SHA1(final String in) ...
1
vote
2answers
89 views

Java Code - Why a variable is being cloned here?

Look at the following code which i am copying from javax.naming.InitialContext. An argument of HashTable type is being passed to the constructor. here is the code snippet public ...
5
votes
1answer
498 views

Looking for a Java equivalent to .NET's Snippet Compiler

I am looking for a Java equivalent to .NET's Snippet Compiler. Is there any such utility out there? That or a really light weight Java IDE for Windows? Eclipse and NetBeans seem too heavy-weight to ...