Posts

To start and stop tomcat server using Java

The command to execute in dos prompt - For Tomcat 5.5 To Start: net start tomcat5 To Stop: net stop tomcat5 public class TestTomcatService { public static void main(String[] args) throws IOException { TestTomcatService obj = new TestTomcatService(); obj.startService(); obj.stopService(); } public void startService() { try { String[] command = new String[3]; command[0] = "cmd"; command[1] = "/C"; command[2] = "net start tomcat5"; Process p = Runtime.getRuntime().exec(command); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); // read the output from the command String s = null; System.out.println("Here is the standard output of the command:\n"); while ((s = stdInput.readLine()) != null) { System.out.println(s); } // read any errors from the attempted command System.out.println(...

Find difference in days in Java

To calculate the difference between two dates, we will be using Calendar (java.util.*) public static long daysDifference(Calendar startDate, Calendar endDate) { Calendar date = (Calendar) startDate.clone(); long daysBetween = 0; while (date.before(endDate)) { date.add(Calendar.DAY_OF_MONTH, 1); daysBetween++; } return daysBetween; } The while loop will be executed until the startDate is less than the endDate. The long value daysBetween will return the days difference.

How to Succeed

1. Don't talk negatively about people behind their backs. 2. If you gossip, people won't confide in you. Mind your own business. 3. Try to work for someone who'll challenge your powers. 4. You'll learn more in a year than 4 years of college. 5. Successful bosses have good communication skills. They learn from people, including their employees. 6. Work in such a way that makes your boss look good. It's not flattery 7. On downsizing, the first to go are those with few friends. Bosses prefer competent people whom they respect. 8. Dress for the job you want, not the one you have. Let your dress reflect professionalism. 9. Workout to get in good physical shape. Unless exceptionally skilled, the unhealthy are at a comparative disadvantage. 10. Personal integrity is crucial. tell nothing but the truth. Bosses can forgive mistakes but if you lie, you're gone 11. Be on time. Try to arrive few minutes early. It saves you from stress. You'll be much relaxed & work ...

Mobile Charge - Saving Tips

If you're expecting a call and your battery icon starts blinking, the first thing you should do is find a charger. But if that's not an option, here are ten things you can do to hang on. We'll skip the usual tips about the 'memory effect' and which battery type is better NiCd or Li-Ion because you don't really have a choice in that. Close Background Applications If you're using a Smartphone, close applications that you don't need. Applications that stay active in the background use up a bit of CPU, which uses up battery. Make sure you 'exit' the applications from the menu, not by pressing the 'End' key, as that merely puts the application in the background. In Series 60 Smartphones (mostly Nokias), hold down the 'Menu' key to get a list of all applications running in the background to close them. In Windows Mobile 5 phones, open the 'Memory' application and check the 'Running programs' tab to close them. Turn D...

How To Block IP Addresses On Linux Server

Take a look at your log file (/var/log/secure for Fedora Core 4) and you will discover numerous automated ssh hacking attempts using dictionary attack. So now you have identified the offending addresses. How do you stop them? Here comes the magic mantra which uses iptables (packet) firewall: iptables -A INPUT -s a.b.c.d -j DROP Replace a.b.c.d with the offending IP address. Repeat this for each of the offending IP addresses.

Festival Special: How to prepare Biryani !!!

Image
INGREDIENTS :       • 500 grams of basmati rice • 1 kg of mutton (diced into small pieces) • 2 tablespoons of garam masala • 6 nos. of red chillies • 3 nos. of green chillies • A handful of cashew nuts • 1 large onion (chopped) • 5 nos. of cloves • 2 nos. of cinnamon sticks • 2 nos. of cardamom • 6 sprigs of fresh coriander (chopped) • 1 small bunch of mint (chopped) • 1 tablespoon of ginger-garlic paste • 3 tablespoons of saffron (dissolved in cup milk) • 1 cup of yoghurt (beaten) • 2 nos. of lime • 4 nos. of boiled eggs • 5 tablespoons of ghee/oil • Salt to taste Procedure: • Mix mutton pieces with ginger-garlic paste and beaten yoghurt and keep aside • Grind the chillies and cashew nuts together • Heat four tablespoons of ghee/oil and fry the chilli-cashew paste. Now add mutton, one-fourth of fried onion, 1 tablespoon garam masala and salt to taste • As ghee separates from the m...

Read Notepad Contents using Java

import java.io.*; public class ReadNotepad { public static void main(String[] args) { try { FileInputStream fstream = new FileInputStream("C:\\Sample.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { } System.out.println("Notepad Contents---->>>>"+strLine); in.close(); } catch(Exception e) { e.printStackTrace(); } } }