Posts

Showing posts from 2009

Worth of Skills

Image

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(); } } }

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 ----->>>>" +strLine); in.close(); } catch (Exception e) { e.printStackTrace(); } } }

Top 20 Tips To Keep Your System Faster

Follow these tips and you will definitely have a much faster and more reliable PC! Most of the below tips works for windows 98   1. Wallpapers : They slow your whole system down, so if you're willing to compromise, have a basic plain one instead!   2. Drivers : Update your hardware drivers as frequently as possible.  New drivers tend to increase system speed especially in the case of graphics cards, their drivers are updated by the manufacturer very frequently!   3. Minimizing : If you want to use several programs at the same time then minimize those you are not using.  This helps reduce the overload on RAM.      4. Boot Faster : The 'starting Windows 95/98' message on startup can delay your booting for a couple of seconds.  To get rid of this message go to c:\ and find the file Msdos.sys.  Remove the Read-Only option.  Next, open it in Notepad or any other text editor.  Finally, go to the text 'Options' within the file and make the following changes: Add BootDela...

To Kill a Process in Windows using Java

In Java it is easy to stop or kill a executing process. Using the Runtime and Process class, this can be acheived. Runtime r=Runtime.getRuntime();        String command="taskkill /f /im [application name].exe"; Process p=r.exec(command);

Sending email attachments using Java and SMTP

Using the Secure iNet Factory components adding file attachments to your outbound email messages is a very simple task. The process for adding file attachments to your email message is described in the code example provided below. Example 01 /* 02 * @(#)SmtpAttachmentExample.java 03 * 04 * Copyright (c) 2001-2003 JSCAPE 05 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A. 06 * All rights reserved. 07 * 08 * This software is the confidential and proprietary information of 09 * JSCAPE. ("Confidential Information"). You shall not disclose such 10 * Confidential Information and shall use it only in accordance with 11 * the terms of the license agreement you entered into with JSCAPE. 12 */ 13 14 import com.jscape.inet.smtp.*; 15 import com.jscape.inet.mime.*; 16 import com.jscape.inet.email.*; 17 import java.io.*; 18 19 public class SmtpAttachmentExample extends SmtpAdapter { 20 public void sendMessage ( String hostname, String to, String from, String subject, Str...