Posts

How to get RAM size using java?

package com.demo.memoryheap; import java.lang.management.ManagementFactory; /**  * @author abdul  *  */ public class FreeMemoryUsingMxBean {     /**      * @param args      */     public static void main(String[] args) {         com.sun.management.OperatingSystemMXBean mxbean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();                 System.out.println("Total Memory in MB: " + mxbean.getTotalPhysicalMemorySize()/(1024*1024));                 System.out.println("Free Memory in MB: " + mxbean.getFreePhysicalMemorySize()/(1024*1024));     } } Note : If you get access restriction error while working on Eclipse , check this : Access Restriction issue

Access restriction on class due to restriction on required library rt.jar for OperatingSystemMXBean ?

Its work for me : Go to the Build Path settings in the project properties. Remove the JRE System Library Add it back; Select "Add Library" and select the JRE System Library. The default worked for me

How to convert InputStream to String in Java?

/**  *  */ package convert.stream.to.string; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; /**  * @author abdul  *  */ public class StreamToString {     /**      * @param args      */     public static void main(String[] args) {         StreamToString streamToString = new StreamToString();               //intilize an InputStream         InputStream is = new ByteArrayInputStream("file content:\nData1\nData2".getBytes());               /*          * Call the method to convert the stream to string          */  ...

How to find exact version of Red Hat Linux

[root@localhost ]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.2 (Tikanga) For others: Slackware: /etc/slackware-version Mandrake: /etc/mandrake-release Red Hat: /etc/redhat-release Fedora: /etc/fedora-release

How to configure session timeout for putty

Image
Click on the upper left hand corner of your putty screen, then click on 'Change Settings', then 'Connection'. I have my 'keepalive' set to 300. Now It will time out after 5 minutes.

How to create a ant log file

ant -logfile <filename>.log

Get Sub List of Java ArrayList Example

package com.subList.demo; import java.util.ArrayList; import java.util.List; /**  * This Java Example shows how to get sub list of java ArrayList using subList method.  *  * @author abdul  */ public class SubListDemo {     public static void main(String args[]) {         //create an ArrayList object         List<String> list = new ArrayList<String>();         int range = 4;         //Add elements to Arraylist         list.add("A");         list.add("B");         list.add("C");         list.add("D");         list.add("E");         list.add("F");         list.add(...