Archive for the ‘Java development’ Category
Java 7 – Small language changes
Hi everyone,
Apart from the great proposals made by Neal Gafter that can be found everywhere on the web, I have some too… But I don’t know how to make them “official” because of my lack of knowledge about deeper changes in the specs or compiler. Anyway, I’ll like to post them, maybe someone can give me a hint how to get them in…
@Home I’ve writen a small closures framework w/ double brace initialization, but I stumbled upon two issues that made me (almost) surrender:
- Java should allow access to non final variables from inside anonymous classes
- And I need to finish the construction of an object in its super constructor to prevent direct execution of a double braced anonymous class, as the instructions inside the double brace is been “copied” to the anonymous constructor
Something I come over just today:
Java should ease the usage of static final fields/constants when declared inside the class you call a method. Instead of doing like
TableWrapData tdGrabName = new TableWrapData(TableWrapData.FILL_GRAB);
it should be possible to write
TableWrapData tdGrabName = new TableWrapData(FILL_GRAB);
The same accounts for enumerations. As the method definition states the type, why do I need to write it again? E.g. having a class
class SomeClass { public SomeClass(SomeEnum enum) {} }
instead of
new SomeClass(SomeEnum.Value);
I want to do
new SomeClass(Value);
of course with full IDE support
Another one is to allow Interfaces for Annotation fields. That would ease the use of Enums that implement this interface, thus making customizable/extendable enums possible.
If you have questions or suggestions, feel free to post some comments, I’ll get back to you…
Greetz, GHad
Short update
Hi @all and a happy new year
Yeah, I know, it’s little bit late already, but I simply had no time to blog earlier. Too much to do with testing out Win7 and hacking java and vbscript…
Anyway, here are some new cool findings to check out:
http://www.electricsheep.org/ – Grid-based computing of fractal mantras as screensaver
Consider GlassFish ESB v2 for SOA Tooling (http://www.developer.com/services/article.php/3799641) for a good tutorial about GlassFish, NetBeans, ESB and BPEL
http://www.javapassion.com/ – Where you can learn about many aspects of Java developing technologies (with passion
http://thediscoblog.com/2009/01/21/shed-the-weight-with-groovlets/ – Get quick and easy groovelets to work at your favourite (application) server and why those groovy servlets rock
http://garbagecollected.org/2007/07/12/builder-pattern-deluxe/ – A generic proxy approch to the builder pattern
http://www.isodisk.com/ – A portable ISO mounting/creating solution for Windows
So long and many greetz,
GHad
Stuff to check out
Well, the web is full of surprises especially for people like me who want to try out everything but don’t have the time… I still hope to get some free time over the holidays to get some dev done and to check out all the links I’ve posted recently. Well, I still have some more
[no(c)]
Online/Multi computer syncs: https://www.mesh.com/Welcome/default.aspx (needs Windows Live ID though…),
Better…: http://www.getdropbox.com/ (50GB for 99$/year)
Adding a social network to your website: http://elgg.org/index.php (Sounds easy and looks good)
A nice Linux distro to try at a VM: http://www.linuxmint.com/
Office 2008 styled apps with JRibbon and A03 look and feel for Java: http://www.pushing-pixels.org/?p=941
MessageFormat for Java description: http://blog.nexaweb.com/post/a-guide-to-java-messageformat-or-how-i-learned-to-stop-worrying-and-love-macros/ (cool for templating)
Runtime class management: http://code.google.com/p/reflections/ (cool for frameworks for example)
Extending Java foreach: http://www.iam.unibe.ch/~akuhn/blog/2008/pimp-my-foreach-loop/
BTW… VirtualBox 2.1 is out with experimental OpenGL3D and x64 Guest under 32-Bit OS support. Must look for a portable edition… Okay, think that’s all for the moment, I’ll post some cool stuff later if I have time.
Greetz, GHad
Bringing together .NET and Java
I just researched some bridging technologies for calling Win DLL/Com objects from Java. I stumpled upon those two very usefull sites:
- http://groovy.codehaus.org/Bridging+the+Gap+Between+Java+and+.NET+with+Groovy+and+Scriptom
- https://jdic.dev.java.net/
The first one shows how to write a COM DLL with VisualBasic, using other Com-Objects and accessing this new DLL from within Groovy and/or Java. This is something for making my Optimus Mini Three really usable from groovy/java I hope. The second one provides native functions via APIs to Java for creating IE, floating windows and retrieving system informations. Bringing this all together into an usefull application I will try
Greetz, GHad
Play! Java Server/Services development
Just a quick link again: http://www.playframework.org/
Quote from the page:
Discover a clean alternative to bloated enterprise Java stacks. Play! focuses on developers productivity and targets RESTfull Architectures
I just read the examples and it looks really cool for use at home, building some simple home services, for example a media album for all family members and such things. I’ll take a look when I’m finally done with my hardware…
Greetz, GHad
Google-API-Translate-Java
Only a quick reminder to look at: Google Translation Api for Java
Makes i18n for example a no brainer, because for Menus, Buttons and little instructions, automatic translation should work well. When combined with automatic saved properties files, even offline mode for applications can do well.
Greetz, GHad
Java math with roman numbers…
Hi all,
just found this page: For.example
This is a nice way of getting into JavaC for making a java pre-processor. Along with Compiler Annotations and Groovy this is a real good change to realize uncommon Java solutions for DSLs, shortcuts, code generation and many other things. I really should fire up my eclipse @ home for my pet projects and give it a try.
Greetz, GHad
Calling a REST WebService from Java (without libs)
I needed to geocode an address today by using free WebServices. The final solution is to use yahoo, but here is the full list of other usefull services:
- Yahoo: http://developer.yahoo.com/maps/rest/V1/geocode.html
- Yahoo (without app-id): http://www.batchgeocode.com/lookup/
- Lookup for ZIP/Place only, but many more free services: http://www.geonames.org/export/web-services.html
Anyway, still needed to call the WS from Java, but thanks to google I found a solution quickly (http://xml.nig.ac.jp/tutorial/rest/index.html) and expanded it to my usecase:
private static String buildWebQuery(Map<String, String> parameters) throws Exception {
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> entry : parameters.entrySet()) {
String key = URLEncoder.encode(entry.getKey(), "UTF-8");
String value = URLEncoder.encode(entry.getValue(), "UTF-8");
sb.append(key).append("=").append(value).append("&");
}
return sb.toString().substring(0, sb.length() - 1);
}
public static String callRestfulWebService(String address, Map<String, String> parameters) throws Exception {
return callRestfulWebService(address, parameters, null, 0);
}
public static String callRestfulWebService(String address, Map<String, String> parameters, String proxy, String port) throws Exception {
return callRestfulWebService(address, parameters, proxy, Integer.parseInt(port));
}
public static String callRestfulWebService(String address, Map<String, String> parameters, String proxy, int port) throws Exception {
Proxy proxyObject = null;
if (StringUtils.isNotBlank(proxy) && port > 0) {
InetSocketAddress proxyAddress = new InetSocketAddress(proxy, port);
proxyObject = new Proxy(Proxy.Type.HTTP, proxyAddress);
}
String response = "";
String query = buildWebQuery(parameters);
// More info: http://xml.nig.ac.jp/tutorial/rest/index.html
URL url = new URL(address);
// make post mode connection
URLConnection urlc = null;
if (proxyObject == null) {
urlc = url.openConnection();
} else {
urlc = url.openConnection(proxyObject);
}
urlc.setDoOutput(true);
urlc.setAllowUserInteraction(false);
// send query
PrintStream ps = new PrintStream(urlc.getOutputStream());
ps.print(query);
ps.close();
// retrieve result
BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream(), "UTF-8"));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
sb.append("\n");
}
br.close();
response = sb.toString();
return response;
}
With these few methods you can call any REST WebService with any parameters (as Map) and use a proxy per call. The code also takes care of right encoding of parameters. The result is a xml string, which can be processed by regexp in an easy way.
Greetz, GHad
BTW: For how to create REST webservices take a look at: http://inverse2.com/?p=43
Create unique identifiers in Java – UUID
Sometimes you have the need for unique identifiers. Luckily, Java provides an easy way for creating globaly unique strings:
import java.util.UUID;
public class GenerateUUID {
public static final void main(String... aArgs){
//generate random UUIDs
UUID idOne = UUID.randomUUID();
UUID idTwo = UUID.randomUUID();
log("UUID One: " + idOne);
log("UUID Two: " + idTwo);
}
private static void log(Object aObject){
System.out.println( String.valueOf(aObject) );
}
}
outputs:
UUID One: 067e6162-3b6f-4ae2-a171-2470b63dff00 UUID Two: 54947df8-0e9e-4471-a2f9-9af509fb5889 Thanks to Java Practices for providing this usefull piece of information!
Get more from your Java
Just take a look at HiddenFeatures for Java… I bet you’ll be surprised. A very usefull ressource if you like to look for something cool to test out
Comments (2)
Comments (1)
Leave a Comment