Sep 30

Use the getHostName() method of the InetAddress class


InetAddress address = InetAddress.getLocalHost();
String hostname = address.getHostName(); 

written by objects \\ tags:

Sep 30

Use the InetAddress class.


InetAddress address = InetAddress.getLocalHost();
byte[] ip = address.getAddress();

// to get a string representation use 
// the getHostAddress() method

String ipString = address.getHostAddress();

// for a string representation in 
// form hostname/literal IP address 
// use the toString() method

String hostAndIp = address.toString(); 

written by objects \\ tags:

Sep 30

Use the Calendar class to set the day of the week to the first day of the week.


Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_WEEK, 
   cal.getActualMinimum(Calendar.DAY_OF_WEEK));
Date firstDayOfTheWeek = cal.getTime(); 

written by objects \\ tags: ,