Mostrando postagens com marcador java. Mostrar todas as postagens
Mostrando postagens com marcador java. Mostrar todas as postagens

quarta-feira, 23 de junho de 2010

Let's calculate

Everyone knows that float point numbers are far from been precise. In fact they are as precise as any other number, the problem is that they work in a different base (2 instead of 10).

Let's take an example to illustrate that: the number 0.01, it is a quite simple and clear number in base 10 notation. Now let's add to it 0.09, which is the expected result? 0.1 right? Well doing it using floating point numbers we will get: 0.09999999999999999.

But why? We it is because altough 0.01 and 0.09 can be easily represented in a base 10 notation it doesn't have a real representation in the base 2 notation. It is something like 1/3 it is 0.3333334, the same with those number. What we have at the end is a periodic number, which is rounded to provided the expected number, but when we do a calculation this number cannot be rounded anymore.

Basic stuff, and I guess everyone faced it before, expecting the right result is the same of someone (yes it is a true story) that wants to divide the 100% by 3 and sum it back and expect to have 100%. Well it is not going to happen, 100% by 3 is 33,333333% and it sum back is 99,99999999%.

Sure that there is nice ways to work around this problem, in most of the languages. But all this introduction is to say about this ways, it is just to present a really nice calculation component/program that you can use in your Java programs: Frink.

"Frink is a practical calculating tool and programming language designed to make physical calculations simple, to help ensure that answers come out right, and to make a tool that's really useful in the real world. It tracks units of measure (feet, meters, kilograms, watts, etc.) through all calculations, allowing you to mix units of measure transparently, and helps you easily verify that your answers make sense. It also contains a large data file of physical quantities, freeing you from having to look them up, and freeing you to make effortless calculations without getting bogged down in the mechanics."
You can use it to calculation with the right precision your nice mathematical stuffs (no more error in 0.01 + 0.09), but you can do even more with that. You can virtually convert any unit to any unit.
The possible calculations goes from the normal phisical stuffs like, energy to temperature to crazy examples like how much time Superman should recharge his energies at the Sun to save Lois Lane and some kids, or even further how much weight Lois should loose to help Superman saving some kids (check the examples here).

Take a look at the main website, it worths and can be really helpfull for you, when you need to do some nice calculation in your application.

And finally for those that want to go further in floating point theory: What Every Computer Scientist Should Know About Floating-Point Arithmetic.


A good sidekick for this post is The Magic Numbers - Forever Lost.

Enjoy it ;-)

quarta-feira, 9 de junho de 2010

Apache Pivot and news

It has been a while since the last post. Unfortunetely the time is still short to continues with the DOD posts, in this meanwhile I will talk with a relatively new Apache project: Pivot.

As stated in the project main page the purpose of Pivot is to:
Building rich internet applications (RIA) in Java by combining the enhanced productivity and usability features of a modern RIA toolkit with the robustness of the Java platform.
The first issue that should be clarified, it is not a HTML+CSS+Javascript solution like ExtJs or JQueryUI or any other framework around. It is in fact a framework for build application in the old and good JVM.
It means that to run this RIA application you still need the Applet (or webstart), a JVM in client and all the stuff for this kind of application.

The first question is: so not why Swing? First of all the Pivot UI classes provide a lighter implementation than Swing, something like Thinlet. All the UI elements are rendered using Java2D and it also provide some nice effects (over the tradicional Swing).

On the top of it the interface can be created with a declarative language, so you don't need to use that huge amount of code. They have choosen to use the WTKX, which is a XML that you can specify the interface (acording to the project website: "A nice and open XML for declaring graphical user interfaces in Java"). This fact is already a great advantage over Swing.

And finally why RIA? Is it not just another UI framework. Well in fact no, it also comes with a set of classes and libraries that makes the comunication with a webserver much easier, thinks like http calls, web service integration and so on.

I think it as a good alternative for traditional Swing app, maybe not just for RIA application, even for your Java desktop app. Such kind of integration with the webservices is really usefull.

What I still miss there is a better way to deploy your application over the web. Using applets and webstart is still a pain.

By the way, before saying see you next time, I would like to introduce a new session in the posts, a part that can be used even if the post is really boring or not usefull at all. For example, tip for a song, movie, a cake receipt, a joke, whatever. Today I will go for a music, so...

A good sidekick for this post is Dropkick Murphys - Johnny, I Hardly Knew Ya.

terça-feira, 20 de abril de 2010

Java in the factory field

Back to the middle of 2003 I have spent sometime reading and investigating how to use Java in the factory field, based on some standards like Fieldbus, Profibus, Supervisory Systems and so on. It was an early time, a time that I was walking in green fields but without money or contacts to transform the research in something more concrete.

Not that nowadays I have contacts or money, in fact I am not even in the green fields anymore, but looking at my old papers and pdfs I have found those documents. And it brought me some curiosity where was the state of things in this area; back to that time we had a lot of papers, researches but no real implementation in the factory fields itself; it was still the realm of C programmers.

For my disappointment a brief search and inspection proved that Java hadn't stepped forward in most of these areas, but a work demonstration at JavaOne 2007 looked really promising. It is an industry robot automation using merely JAVA, for sure it is using the Real-Time Specification for Java 2.0, as we need a more strict control over what is happening in the machine.
It is used on top of a bus standard called EtherCAT, which is a kind of bus that communicates over Ethernet and not some serial protocol.

The main point here is to see that it is possible to have Java running in a critical environment that needs time based response in a preemptive mode. By the way if you want to see the robot in action just go for this video World's First Java-Controlled Industrial Robot



For those that want to remember about industrial bus here is collection of wiki pages that could helpful:
- Fieldbus (http://en.wikipedia.org/wiki/Fieldbus)
- EtherCat (http://en.wikipedia.org/wiki/EtherCAT)
- Profibus (http://en.wikipedia.org/wiki/PROFIBUS)

And finally the paper Using Real-time Java for Industrial Robot Control that has an overview about the robot implementation with java.

I hope you enjoy it as a new curiosity area or make you remember old hard working days!

terça-feira, 16 de fevereiro de 2010

Patterns of Deployment

Today I was looking at a Javalobby post, that highlight some deployment tools. Between those tools there is a interesting one called SmartFrog (java based and developt by HP, yes it is true, these guys still have some projects).

SmartFrog is a powerful and flexible Java-based software framework for configuring, deploying and managing distributed software systems.

Take a look if you want, but the main idea of this post is to invite you to see one of the SmartFrog wikipage: Patterns of Deployment.

In that page you will find nice patterns to deploy application, some address by SmartFrog, some not. But the main idea of this page is to show you the possible patterns and tools for that.

I am sure that you need to deploy your application and maybe creating the .WAR is not enough or that easy ;-)

sexta-feira, 5 de fevereiro de 2010

Graph Database

Graph database are not about images or graphs and things like that :-). They are simply a database organized as a Graph, you don't have tables, you just have nodes and relations.
Interesting concept that can be applied in some kind of structure that we could need to have work with.

Too conceptual? Well I suggest you to take a look at the project Neo4j project. It is a java project that implements a graph database.
Take a look, investigate the examples, I am sure that you will find where to apply it easily (at least you will know that there is another option to your good friend Relational Database).

segunda-feira, 26 de outubro de 2009

Oh my God, I don't understand why I cannot use static maps to store user information.

Sorry folks, it was a long time since the last post, but I promisse that I am going back to stay.

Today we will take about a issue that I have heard about in the office for the whole last week: memory leak.

I believe that some memory leak is ok to happen, mainly if you store things on the HttpSession. Let's be realistics, it is a easy solution and if the data keeps on the memory for 30 minutes who cares?

But actually the memory leak that we have found is not realted to the session, it was related to the 2 different issues: thread variables and static maps.
  • Thread variables: a lot of things were being stored into the thread variable, and using as key some object. First, usually the web servers reuse the threads, so the information there was being keep for a looong time. Second object as key SHOULD-ALWAYS-NO EXCUSE TO NOT HAVE hash, otherwise baby, guess what? Every add is a new entry on the map. That's a bingo: memory leak.
  • Static maps: this is just a more obvious leak than the thread variables, use a static map to store information, where the key also do not implement a proper comparation methods. So every entry lead to a forever-and-ever information into the memory. As as Murphy says: there is always something worst, those information stored into the map where GUI objects, which was reference even to God. And the leak could lead to a OutOfMemory after 5 screen hits.

Nice ins't it? I can understand the problems, what I cannot understand is people blaming the GUI obejcts to have the necessary references. Come on, they are GUI objects that are supposed to work for a single request.
But the real problem is that people still tries to solve problems that are not present yet. The performance problems are the classical example: you never run the application, so you don't know if there is performance problems or not. Why should you address them? Why to worry about it?
Most of the problems could be solve with a proper approach to the problem and not with cache (that usually leads to a whole bunch of other problems). And if the cache is need think about what are you doing: my key if unique? is it replacing the information? what is the live time of the data? should I need another cache than the HttpSession? ...

Make like the buddhists: breath 10 times before doing something, if after that time you still want to do it, go and think about it and then do it, otherwise just go home and relax.

sexta-feira, 20 de fevereiro de 2009

I am back for some finger pointing

Hello all!!!

It was a long time since my last post, I know it. But I am back, and this time for some finger pointing.
Yes that it! No technical stuff here, just fun.

Why are you doing it? (a fair question): I have just jumped in a new project and currenctly I am looking the code around me.
Take a look at this pearl: a class called SwissArmyKnife. What would you expect from it? A class with a lot of util method that makes things that even McGuyver could never imagine, yes that is true... but the reality is a little bit different.

Take a look:

public class SwissArmyKnife {
public static String getSimpleClassName( String strClazzName ){
String strSimpleClassName = "";
StringTokenizer st = new StringTokenizer(strClazzName, ".");
while(st.hasMoreTokens()){
strSimpleClassName = st.nextToken();
}
return strSimpleClassName;
}
}

domingo, 12 de outubro de 2008

Managing plugins on Eclipse

Have you ever asked to yourself if it is really necessary to copy your plugins into the Eclipse diretory and make everything a big mass?
No it is not necessary to make it, take a look on this IBM article: Manage your Eclipse environment, you will be amazed how easy it is to make things organized.

domingo, 10 de agosto de 2008

x86 emulator in Java!

At this moment I couldn't imagine any real application for it, but it doesn't matter: it is fun!
The JPC is a x86 emulator and the team was able to run DOS and Linux in a applet, completly open source it is a great knowledge source.
Take a look on their page, try it playing Lemings or other nice game: The JPC Project: Computer virtualization in Java.

sábado, 9 de agosto de 2008

Getting started with Spring MVC

If you are looking for a tutorial to let you have a first contact with the Spring MVC take a look on this post from Jeroen van Wilgenburg: Getting started with Spring-web-mvc and the Spring IDE-plugin – creating a simple web application.

quarta-feira, 6 de agosto de 2008

Simplified DAO with Spring and Hibernate

I know that it is nothing new for the Spring and Hibernate developers, but it is a good entry point for those frameworks or even better, what you can get from them.
Take a look on this article from Unruly Rambling: Spring and Hibernate, Simplify the DAO layer and this one from ONJava: Persistence in Spring.

terça-feira, 5 de agosto de 2008

Library for GUI programming

If you are involved with GUI programming you should take a look on this framework: Fuse.
Fuse is a lightweight resource injection library specifically designed for GUI programming.
Also take a look on this JavaLobby article: Easier Custom Components with Swing Fuse.

domingo, 3 de agosto de 2008

Does your software provide a help?

It doesn't matter if it is online, offline, command line, what-ever-line: your software should provide a help to the user.
There is a specific software engineering discipline to that (I will provide some links after), but you can start with some implementations for a help into your application: JavaHelp System.

I know that it is nothing new, but it if you don't know that you should take a look. It can give you some ideas.

sexta-feira, 13 de junho de 2008

Quaere

A different concept framework to add queries to your java programs:

Quaere is an open source, extensible framework that adds a querying syntax reminiscent of SQL to Java applications. Quaere allows you to filter, enumerate and create projections over a number of collections and other queryable resources using a common, expressive syntax.

Just for your information it is based on a LINQ to SQL: .NET Language-Integrated Query for Relational Data.

terça-feira, 10 de junho de 2008

Let's play?

There is many ways to learn how to developt using Java language, but I should admit that IBM offers three great ways and both are really challenging: gaming.
The idea behind is to create classes (using all the widgets from Java language) that will be used by a gaming program. The first one is to create a robot, that will fight agains other robots, the second one is to create a car to run in a rally and the third is to create peasants and knights, conquer the world and increase your medieval kingdom.
Besides the Java knowleadge that you get coding for these games you also increase your skills for artificial inteligence.
Let's play?

sexta-feira, 6 de junho de 2008

Is it dead? Nooooo...

In my last company I was still using 1.4 and I believe that in the previous company it is also true.
But folks you need to move, just take a look on this article from javalobby: Help, I'm Still Using Java 1.4!
Let's face the problem and fight agains it, let's move to 1.5.