What is the difference between java and javaw?

Everyday is a new learning opportunity. I have been a programmer for more than 5 years now, but I realized sometimes people tend to ignore smaller nice features – which you later repent you should have learned years ago. Here is what I learned today about java/javaw.

The javaw command is identical to java, except that with javaw there is no associated console window. Use javaw when you don’t want a command prompt window to appear. The javaw launcher will, however, display a dialog box with error information if a launch fails for some reason.

Just giving you  a background on why it was useful to me: I was working on a shared machine with my co-workers and I used to leave one of my tools running in the console. This tool was supposed to stay alive all the time to serve its purpose of polling the logged users – but sometimes it used to get killed by some other users (and sometimes myself too) in ignorance. Then when I learned using ‘javaw’ I didnt have to care even if I myself or my co-workers killed the console, the program ran on the background anyways.

You could run your programs as a service anyways – but I am not going to advocate about those ideas in this post today.

Calculating Folder Size In Java

The following piece of java code demonstrates how we can calculate the size of a given folder using Java Application. This uses a recursive technique. We start with a root directory, and start listing the files/folder. If a file is found, we calculate its size and sum of total size and also increase the total number of files counted so far, if it is a directory, we further do the recursion.

This program has been fully compiled and tested to find the folder size in Java.

/**
 * @author Kushal Paudyal
 * www.sanjaal.com/java
 * Last Modified On: 30th August 2008
 */
package com.kushal.utilities;

import java.io.File;
import java.text.DecimalFormat;
import java.text.NumberFormat;

public class TopLevelFolderSize {

	int totalFolderCount=0;
	int totalFileCount=0;

	public static void main(String args [])
	{
		/**
		 * Define your folder here. This is the folder whose size
		 * statistics you want to find out.
		 */
		String folder = "C:/Users/kushal/Desktop/tempKushal";

		try{
			DecimalFormat fmt =new DecimalFormat("#.##");

			TopLevelFolderSize fg=new TopLevelFolderSize();

			/**Calculating the file size. By default size in long
			 * is returned.
			 */
			long fileSizeByte=fg.getFileSize(new File(folder));

			/**
			 * Formatting the long value to calculate size in
			 * different units KB, MB and GB
			 */
			double fileSizeKB=Double.valueOf(fmt.format(fileSizeByte /1024));
			double fileSizeMB=Double.valueOf(fmt.format(fileSizeByte /(1024*1024)));
			double fileSizeGB=Double.valueOf(fmt.format(fileSizeByte /(1024*1024*1024)));

			/**Printing the statistics**/
			System.out.println("nn##############--Folder Statistics--#################");
			System.out.println("Total Folder Size: ["+fileSizeByte+" Bytes] ntt["
						+fileSizeKB+" KB] ntt["
						+fileSizeMB+" MB] ntt["
						+fileSizeGB+" GB]");
			System.out.println("Total Number of Folders: "+fg.getTotalFolderCount());
			System.out.println("Total Number of Files: "+fg.getTotalFileCount());
			System.out.println("##########--End Of Folder Statistics--##############");

		}catch (Exception e)
		{
			System.out.println("Exception Occurred: "+e.getMessage());
		}
	}

	/**
	 * This is a recursive method.
	 * If file is found, total file size is calculated.
	 * If it is a folder, we recurse further.
	 */
	public long getFileSize(File folder) {
		totalFolderCount++; //Counting the total folders

		System.out.println("Processing " + folder.getName());
		long foldersize = 0;

		File[] filelist = folder.listFiles();
		for (int i = 0; i < filelist.length; i++) {
			if (filelist[i].isDirectory()) {
				foldersize += getFileSize(filelist[i]);
			} else {
				totalFileCount++; //Counting the total files
				foldersize += filelist[i].length();
			}
		}

		return foldersize;
	}

	/**
	 * @return the totalFolderCount
	 */
	public int getTotalFolderCount() {
		return totalFolderCount;
	}

	/**
	 * @return the totalFileCount
	 */
	public int getTotalFileCount() {
		return totalFileCount;
	}

}


———————————————————————
SAMPLE OUTPUT:
———————————————————————
Processing tempKushal
Processing cute pictures
Processing image col
Processing Moline Tornado
Processing send
Processing Party At Prabhakars
Processing images

##############–Folder Statistics–#################
Total Folder Size: [151850658 Bytes]
[148291.0 KB]
[144.0 MB]
[0.0 GB]
Total Number of Folders: 7
Total Number of Files: 154
##########–End Of Folder Statistics–##############

15 plus best practices for continuous integration of your software

Here is a list of 15 plus continuous integration tips or do’s and don’ts for your software. If you have more tips, please add them to the comment section. I will pick it up from there and add it to this list.

  1. Maintain single source code repository
  2. Commit code frequently. Ideally have everyone in your team commit their code everyday.
  3. Run all test cases / test suites locally before committing your code to the repository.
  4. Never check-in a broken build – if you found broken test cases, fix those before committing the code.
  5. If you checked in a code that broke the build, fix it. Take responsibility on the build that you broke.
  6. Don’t comment out failing test cases – fix them.
  7. Automate the build process using tools like Ant or Maven.
  8. Automate the unit tests so that on every build whole set of test cases run.
  9. Make a clear separation of Unit Tests and Integratio Tests
  10. Configure the build so that every commit to the repository triggers a build.
  11. Keep the builds fast – fail the build if it runs for too long and optimize the build process.
  12. Replicate production environment as closely as possible on your test environments.
  13. Make the results of your test cases visible to everyone in your team.
  14. Send an email to the team for every build – both for success and failure.
  15. Auotmate your deployment process – ideally set up a trigger to run a deployment once the build is complete.
  16. Run static code analysis tools like checkstyle on your every build and fail the build in case of violations.