Monday, November 7, 2011

Truncate nohup.out file in linux

While sending your program output to file called nohup.out, you can't simply delete the file. Since, it is handled in server memory. In that case, you have to empty file using following command.

If you delete nohup.out, while running your program, it will leads to server memory growing and become server unstable.

change the working directory to location where your nohup.out file reside. Then execute the following command to empty the file.

cat /dev/null >nohup.out

NOTE :- nohup.out is in linux for gathering program output data. If you run application as following output will redirect to the nohup.

nohup java -jar testApp.jar

Tuesday, October 25, 2011

Find multicast groups

In windows, use following  commands to find multicast groups.

Open command prompt and run the following command in terminal.

netsh interface ip show joins

Friday, September 16, 2011

Find contents in files

Suppose, there are many files that contains "CONTENT" you want to search, use the following command in the Linux terminal.

grep "CONTENT" *.*

Friday, September 9, 2011

Create Scheduler in Java


Some applications need to run on a scheduled time. This java application runs on every Sunday midnight.

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class ScheduleTest extends TimerTask {

public void run() {
         System.out.println("Schedule working ");
         //TODO
      }
}

class Application {

public static void main(String[] args) {

    Timer timer = new Timer();
    Calendar date = Calendar.getInstance();
       
         date.set(
                  Calendar.DAY_OF_WEEK,
                  Calendar.SUNDAY
         );

         date.set(Calendar.HOUR, 0);
         date.set(Calendar.MINUTE, 0);
         date.set(Calendar.SECOND, 0);
         date.set(Calendar.MILLISECOND, 0);

// Schedule to run every Sunday in midnight

         timer.schedule(
         new ScheduleTest (),
         date.getTime(),
         1000 * 60 * 60 * 24 * 7
         );
    }
}

Tuesday, August 30, 2011

Conversion between signed & unsigned byte

Convert byte value from signed to unsigned

Use '&' operation with 0xFF  as follows.
Suppose signed byte value is byt (-120,64,....).

    byt & 0xFF

Above will convert signed to unsigned and return unsigned value.

Convert byte value from unsigned to signed

    ByteBuffer byteBuff = ByteBuffer.allocate(4);
    byteBuff.putInt(intValue);
    by[i] = byteBuff.get(3);


Above code convert  unsigned values to sign byte values.

Sunday, August 21, 2011

How to get System information in windows

  • Open command prompt
  • Type "systeminfo" command
  • Run the command
This will get a few seconds to load information.

Thursday, August 11, 2011

View Linux version using command

Use following command to get linux version.

uname -a