Skip to main content

Posts

Long running task?? SwingWorker to help

I don't know how many people or any one now uses Swing for designing applications in Java. But while reading Java docs in my free time I came across this class called SwingWorker, now many of who work/had worked in Swing might be saying "Whats new in this class"!! Well, nothing is new in there but this class is new for me coz I never worked in Swing, but in my college days I was working on a project using Swing called Visual Java. A NetBeans kind of software, I stopped working on it when I came to know that its already there.. :) Coming back to SwingWorker. I am writing this post for this class is because this class is really a handy for those who are developing or starting to develop applications using Swing. While developing any software if there is any long running task, we put it in a separate thread, Background thread. So SwingWorker provides us the same functionality adding some methods where we can put our UI manipulation code. Both the classes provide doInBac...

Java Tools Plugin for Notepad++ Update

This post and the plugin is outdated. Please use plugin from  this link  which is updated and allows customization of shortcut key mappings and much more . This post is regarding the update for Notepad++ plugin which I wrote to use compile and execute Java programs from the Notepad++ editor itself. I have updated the plugin so that user can customize the shortcut keys assigned for compiling and executing the programs. Following image shows simple Settings dialog where you can customize the shortcut keys mapping. Although user can customize the keys but to apply them Notepad++ must be restarted. Well, I tried but in Notepad++, there is no way to change mapping after initialization process of plugin.. Click here to download the plugin.

Form Validation, double check always!!

Validation is one of the most important tasks while creating any form on a web site. Almost every website you visit you will find at least one form. As JavaScript is now a days supported by all browsers and many websites rely on the JavaScript completely and does not work if JavaScript is not supported. Also as the browsers evolved, they started offering various developer friendly tools with their browsers such as Google Chrome provides a console where you can execute JavaScript. Now the important question is when you have a form on your website you should always have both Client side form validation as well as server side validation. Now many people think why do we require server side validation?? 1. Well because even though JavaScript is supported by all browsers, people forget that browsers also provide various developer friendly tools using which we can change the entire JavaScript code. Let's say, I just change validation function to return true in all the cases.. Your ...

Java Tools Plugin for Notepad++

This post and the plugin is outdated. Please use plugin from this link which is updated and allows customization of shortcut key mappings and much more . Notepad++ is a great free editor. I like notepad++ because its a light weight editor and loads instantly. I use notepad++ for editing many files everyday. One plugin I always wanted was a plugin which lets me compile my java files and execute them from editor itself, but I couldn't find it so I wrote a myself. This plugin can be downloaded from  this link . I am working on this plugin to make it more effective, so that if user have more than one installations of JDK or JRE then user should be able to choose which one to use etc. This is a simple plugin which has two commands- Compile - compiles a java file. Run - executes a java file. For using this plugin Java must be installed on the system.

Encrypt Decrypt data using AES in Java

AES stands for Advanced Encryption Standard. AES is an Symmetric Key Algorithm, that means key used for encrypting the data, same key will be used for  decryption of  the encrypted data. This algorithm supplants DES algorithm. This post shows how to use AES algorithm in Java to encrypt and decrypt data. Encrypting Data- import java.security.GeneralSecurityException; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; public class AESTest1 { public static void main(String[] args) throws GeneralSecurityException { KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(128); SecretKey key = keyGenerator.generateKey(); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, key); byte encryptedData[] = cipher.doFinal(args[0].getBytes()); } } In above example we have used KeyGenerator class, which generates key for encrypting data, as we are using...

Type Erasure in Java

While reading some posts online I came across the following post - List<integer> list = new ArrayList<integer>(); List&lt;integer&gt; list = new ArrayList&lt;integer&gt;(); list.add(1); list.add(2); List list1 = new ArrayList(); list1.add(&quot;Some String&quot;); list.addAll(list1); This code compiles and executes as well, this works because of Type Erasure concept in Java. I knew about Type Erasure but while reading more about it on internet I found some posts which were questioning on Type Erasure concept. Following code makes more confusing about Type Erasure concept, if compiler removes all the information about type parameters and type arguments then how does following code works?? class A<T>{ } class B extends A<String>{ public B() { System.out.println(((ParameterizedType)getClass(). getGenericSuperclass()).getActualTypeArguments()[0]); } } public static void main(String args[]){ ...

Client Side MVC

The current project on which I am working in my company, I have been introduced to a new concept(at least its new for me :) ) Client side MVC by one of my colleague and its actually very good technique. Why to have client side MVC- 1. It allows you to manage your data on client side. 2. It allows you to customize your views with Modularized JavaScript code. 3. It allows you to create complex views. In our application we are using Backbone.js to design Client side MVC. Even though I am not an expert in Backbone.js but I liked it, because of the features which are provided by it and how easy it makes to create layouts, view and loads of other things. Backbone.js provides Model, View, Collection and Router(Controller) to create a MVC model. Backbone has a main dependency - Underscore.js, which is a JavaScript library(Of course!!). Creating models using Backbone.js is very easy- var Book = Backbone.Model.extend({      defaults : {       ...