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:

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

VBScript read/write binary, encode/decode Base64

Hi folks,

this time a longer posting, especially the code listing below. Today I’ll show some VBScript sample code on how to read/write a (binary) file and encode/decode it to/from Base64. You may ask why… Okay, this is mainly usefull if you need to call WebServices with byte array parameters when your file lies on disk. BTW: with http://www.pocketsoap.com/ it’s relativly easy to call WebServices with VBScript and I should really blog an example later. 

Imagine a WebService to convert certain file types, e.g. image formats. With this sample functions (+ PocketSoap) calling it would be no problem and may turns out usefull for thumbnail generation, picture post editing and whatever you want to do with a binary file received by a WebService on server-side…

Okay, enough blabla, now the script, which is blasting fast btw. This should work out-of-the-box on every XP machine (vista untested), should be self-documenting enough to understand and you may use an image file for proof of concept, like I used a little smiley png. And yes, I named the Script “ReadFileEncodeBase64DecodeBase64WriteFile.vbs” (try typing first letters and press TAB when using cmd) as it’s only used for sample purposes. Happy coding!

Greetz, GHad

'
' Call via cmd: cscript ReadFileEncodeBase64DecodeBase64WriteFile.vbs [pathToFile]
'
' - Reads file from arg into byte array
' - Encodes byte array to Base64 String
' - Decodes Base64 String to byte array
' - Writes byte array to new file
'
' Sample WITHOUT any warrenty! Use at own risk! Copyright 2008 Gerhard Balthasar
'
 
Option Explicit
' common consts
Const TypeBinary = 1
Const ForReading = 1, ForWriting = 2, ForAppending = 8
 
' getting file from args (no checks!)
Dim arguments, inFile, outFile
 
Set arguments = WScript.Arguments
inFile = arguments(0)
outFile = "new_" & inFile
 
Dim inByteArray, base64Encoded, base64Decoded, outByteArray

inByteArray = readBytes(inFile)
base64Encoded = encodeBase64(inByteArray)
 
Wscript.echo "Base64 encoded: " + base64Encoded
 
base64Decoded = decodeBase64(base64Encoded)
writeBytes outFile, base64Decoded
 
Wscript.echo "Finished!"
 
private function readBytes(file)
  dim inStream
  ' ADODB stream object used
  set inStream = WScript.CreateObject("ADODB.Stream")
  ' open with no arguments makes the stream an empty container 
  inStream.Open
  inStream.type= TypeBinary
  inStream.LoadFromFile(file)
  readBytes = inStream.Read()
end function
 
private function encodeBase64(bytes)
  dim DM, EL
  Set DM = CreateObject("Microsoft.XMLDOM")
  ' Create temporary node with Base64 data type
  Set EL = DM.createElement("tmp")
  EL.DataType = "bin.base64"
  ' Set bytes, get encoded String
  EL.NodeTypedValue = bytes
  encodeBase64 = EL.Text
end function
 
private function decodeBase64(base64)
  dim DM, EL
  Set DM = CreateObject("Microsoft.XMLDOM")
  ' Create temporary node with Base64 data type
  Set EL = DM.createElement("tmp")
  EL.DataType = "bin.base64"
  ' Set encoded String, get bytes
  EL.Text = base64
  decodeBase64 = EL.NodeTypedValue
end function
 
private Sub writeBytes(file, bytes)
  Dim binaryStream
  Set binaryStream = CreateObject("ADODB.Stream")
  binaryStream.Type = TypeBinary
  'Open the stream and write binary data
  binaryStream.Open
  binaryStream.Write bytes
  'Save binary data to disk
  binaryStream.SaveToFile file, ForWriting
End Sub
 

Simple yet powerful JavaScript Console

Just discovered Blackbird, an easy to integrate console for JavaScript debugging. Not tried yet, but looks very promising: http://www.gscottolson.com/blackbirdjs/

Next time I need to develop some JS, I’ll integrate it for sure…

Greetz, GHad

Grails resources

Hello again :-)

This time I found a nice blog entry about Grails and an overview of must-reads and resources for developing your first grails website: http://blog.saddey.net/2008/10/11/grails-links-from-my-first-week-with-grails/

Looks worthy for a closer investigation of grails. Well, I wanted to develop my own grails site as a little private side project since summer, but I still have no time. I first need to get my infrastructure right, as my 2 1/2 year old notebook is getting buggy and slow and needs a replacemt and that needs money, which I don’t have (not even banks have money nower days…). Maybe next three month I’ll get new hardware and energy for my side projects. At least I hope so.

Greetz, GHad

Next Page »