Wednesday 6 April 2011

Difference between Compiler and Interpreter and assembler

Assembler :

A program that translates programs from assembly language to machine language is called as Assembler.
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture. This representation is usually defined by the hardware manufacturer, and is based on mnemonics

Interpreter :

An Interpreter translates high-level instructions into an intermediate form, which it then executes.

Compiler :

A Compiler translates high-level instructions directly into machine language. Compiled programs generally run faster than interpreted programs.


Tuesday 5 April 2011

Java Program to generate alphanumeric characters in random


public class RandomGenerationOfStrings
        {
        public static String getPassword(int n)
        {
    char[] pw = new char[n];
    int c  = 'A';
    int  r1 = 0;
    for (int i=0; i < n; i++)
    {
      r1 = (int)(Math.random() * 3);
      switch(r1) {
        case 0: c = '0' +  (int)(Math.random() * 10);
        break;
        case 1: c = 'a' +  (int)(Math.random() * 26);
        break;
        case 2: c = 'A' +  (int)(Math.random() * 26);
        break;
      }
      pw[i] = (char)c;
    }
    return new String(pw);
  }

  public static void main(String[] args) {
    int len = 10; // default 8 on unix, more is useless

   }
    System.out.println(getPassword(len));
  }
}

Java Program to generate strings(10 character) randomly


public class PasswordGeneration
{
  public static void main(String[] args)
  {
    int PASSWORD_LENGTH = 10;
    StringBuilder sb = new StringBuilder();
    for (int x = 0; x < PASSWORD_LENGTH; x++)
    {
      sb.append((char)((int)(Math.random()*26)+97));
    }
    System.out.println(sb.toString());
  }

}

Monday 4 April 2011

When windows will not allow a Java program to delete a directory

Recently i wrote a Java program to delete a directory and i found that Windows was not allowing delete under the following circumstances.
  1. A file under the sub directory is used by another process
  2. Is non empty having sub directories

My first post in Blog

I am a fresher learning web development in Java JEE. I use this blog to remember stuff I have learnt.