by jNayden | Mar 11, 2011 | Aggregated, Uncategorized
In my life many times has happened when I am assigned to a totally new project that I have no idea what it is about, that has to go live in 2 weeks and that I have to fix some issues in this ultra strange code sometimes even code written in different language. On my question is there any documentation the answer is: Yes but it is very old or no. So in short they want me to start working on a project with no documentation at all. My second question is is there a javadoc and the anwer is : yeah … kind of … so I am in a project with 30% javadoc with methods in French language for example ( I don’t know even a single word in French) so in short I am loosing 2 weeks to understand what is using what what is the model what is PersonnePhysique and what is this crazy domain model. I believe this has happened with everyone of you at least once so what can you do ? You can start digging into the java code like crazy ( like everyone of us have tried many times) You can install intellij idea and use the great reverse engineering way to create UML diagrams for specific classes but intelliJ idea costs money. You can install netbeans 6.5 and do the same but you have to use this out dated version of NetBeans because this doesn’t exist in newer versions, thanks Oracle. You can install Eclipse + MoDisco + MDT + KML to generate xmisomething file then to generate xml file...
by jNayden | Jul 27, 2010 | Aggregated, Uncategorized
It is little strange that no one really uses emptyList like he should in Java. So this is small post showing how to use the emptyList method in the Collections class. Question: How to create an empty list ? lets assume that we have a class Book with multiple titles. So the class in our examples will be: import java.util.List; public class Book { private List<String> titles; public void setTitles(List<String> titles) { this.titles = titles; } public List<String> getTitles() { return titles; } } Lets say that in our snippet we have something like : Book myCrazyBook=new Book(); and we want to assign an empty list to the titles in this book. This is a common scenario if you want to set something to be emptyList in specific case instead of null. So of course your first try will be something like: Answer 1: myCrazyBook.setTitles(new ArrayList()); -WARRNING – ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized Ok changing to: myCrazyBook.setTitles(new ArrayList<String>()); WTF ? the problem in this answer is not small one : – you are creating empty ArrayList which basiclly is not needed. ( what if you are in a loop 1000+ empty ArrayLists ? ) Answer 2. myCrazyBook.setTitles(Collections.EMPTY_LIST); -WARNING : Type safety: The expression of type List needs unchecked conversion to conform to List<String>, because the EMPTY_LIST is raw type, which was heavily used before Java 1.5. The definition of this list is : /** * The empty list (immutable). This list is serializable. * *...
by jNayden | Jun 29, 2010 | Aggregated, Uncategorized
How to write validation like confirm password, confirm email and etc in Spring MVC. NOTE: To make bean validation to work its nice to read this tutorial: <a href="http://wheelersoftware.com/articles/spring-bean-validation-framework.html"></a> Today I was busy making some validations and implementations on very common scenario: change email and password. So we have a new password AND a new email also for both of them we have a confirm email/password field. And we want to validate everything nicely and to show to the user the real validation message if there is some error. So … I’ve to use a form which already uses some annotations like @NoBlank and etc I think everyone of you is using annotations framework if you don’t use it SHAME ON YOU !:) Anyway so I’ve added some fields to existing form bean: private String newPassword; private String confirmNewPassword; private String newEmail; private String confirmNewEmail; Basiclly in my case this is very big form and none of this fields is mendatory so the user can leave all of them blank. My first idea was to add at least Length for the password and Email annotations for the email so I do: @Length(min=6,max=20) private String newPassword; private String confirmNewPassword; @Email private String newEmail; private String confirmNewEmail; Ok but the confirm fields should have the same rules ? Maybe… The problem that I saw is that length and email by default means NotBlank. To make email validator to work or length validator they first check is the field blank. In my case I want the blank to be OK.. so I asked god google what to do. The answer applyIf. So...
by jNayden | Sep 27, 2009 | Aggregated, Uncategorized
Today I’ve try to create code snippet manager using Java and Swing. In my previous post I try to done this using WPF and C# (http://gochev.blogspot.com/2009/09/code-snipper-manager-in-c-and-wpf.html) I’ve just wanted to see how harder is to create the same app using Java and Swing.First lets make some compare about the WPF and Swing version of the app.The WPF version consists of 5 files(2 XAML files and 3 cs files with classes) The WPF version uses XAML for the view (only 30 lines) and 8 lines in file called App.xaml.The C# class with the logic is 208 lines of code. The Snippet model class is not 62 lines of code using C# properties and etc. The Java version have 3 classes. One is the main class, the snippet model class 54 lines (most of them created automatically by eclipse like getters setters in C# YOU HAVE TO WRITE THEM MANUALLY) and the Logic + View class is 290 lines of code. So in conclusion I can say that Java version is 40 lines of code more but this is because of the event handlers which are anonymous classes everywhere in my code. Anyway the result is :WPF app looking like this (on left) and Swing app on right: As you can notice the WPF app looks very worse. Maybe because of the fonts which are not clear typed AND I CAN’T MAKE THEM CLEAR TYPE 🙂 The Swing app have clear type fonts and I’ve included Substance look and feel because it have nice animations and hover effects.The result is – Swing app which looks better under Windows and All OSes...
by jNayden | Sep 1, 2009 | Aggregated, Uncategorized
In this days every Ajax application uses jQuery or Dojo or something like this. If you ask me jQuery is the most often framework because it is small, it helps a lot, it has cool features and it is promoted by Microsoft (we live in strange days). jQuery can be used for many things one of them is effects. We all know how Flash, Silverilght and JavaFX “Rich UI” look and often with CSS and JavaScript it’s very hard to make things that can be done in easy in flash. The jQuery helps a lot with it fade effects slideUp/slideDown and etc. I as a Java Developer I like GWT but often I use JSF too. When I use JSF I’ve always add JQuery because at certain point I’ve always need to type some javascript and with jquery its easier. When I use GWT I’ve wanted to be able to use JQuery the same way like I’ve use it in JSF app or even better. The solution is GWTQuery or GQuery: http://code.google.com/p/gwtquery/ . From the website we can see That Gwt Query is a jQuery-like API written in GWT, which allows GWT to be used in progressive enhancement scenarios where perhaps GWT widgets are too heavyweight. When I saw this I said: “awesome”. You can read how to get started from here http://code.google.com/p/gwtquery/wiki/GettingStarted I will not explain how to setup and use gwt query because in the wiki you will get up2date information about possible changes but the result is awesome. Lets assume that we have a table and we want to hide it when the user clicks a...
by jNayden | Sep 1, 2009 | Aggregated, Uncategorized
Everyone know about GWT right ? This is Java framework for creating real rich ajax applications using the Java language and not using JavaScript. The idea is that your project have two parts : client side and server side. The server side is Java and is compiled to Java using javac and putted in the web server the client side is compiled to JavaScript using GWT Java2JavaScript compiler, the communication between server side and client side is using async call, the result is : real AJAX. First why I call it real ajax ? The common way to make rich applications this days ( or maybe from 2005 till now) is to use non ajax web framework and use custom ajax controls that uses UpdatePanel or AjaxPanel that makes “partial rendering”. In typical Non Ajax application (lets use ASP.net or JSF) when we submit the form or make a call using a button server creates the HTML result and send it to the browser. The browser just visualized the HTML and “voala” we have regular page. To create the view in server side is not the best idea but it was used for the last 10 years or more. Lets create a simple ASP.net page ( I will create ASP.net page not JSF page because it is faster there is no difference in the result and the way how it is created, they are almost the same). The ASP.net page looks like this: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br />...
Recent Comments