Archive for the ‘Java’ Category

Netbeans 5.5 slow startup

जानेवारी 15, 2009

Actually we are developing project in jsp, but i don’t know why Netbeans 5.5 takes lots n lots n lots of time for opening,
Previously my PC’s RAM was 512MB, I upgraded it to 1.5GB, then also it takes nearly 3 minutes for starting on my windows machine, i think there may be problem of java runtime environment, when i’ll get the soln. to this problem then i’ll post here….

Servlet Lifecycle

जानेवारी 11, 2009

.:Servlet Life Cycle:.

1) Load the servlet .class file into web container’s JVM
2) Create an instance of that class
3) The web container create a unique ServletConfig object that contains any initialization parameters. This config object is passed to the init method.
4) The web container begins sending requests to that component using the service method. Web container issue a unique request and response object to the service method. Each request is processed in unique thread.
5) When web application being shutdown, the web container calls the destroy method

Configuring and Compiling Servlet

डिसेंबर 15, 2008

Here are some steps to import javax.Servlet packages in .java file.
First you need to download and install Apache tomcat web server from http://apache.multidist.com

1. To import javax.servlet.* package,

Right click My Computer -> Click Properties

Go to “Advanced” tab, Click On “Environment Variables” Button

In the “System Variables” section append the “PATH” variable as

C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar)

2. Create a java class extending GenericServlet

3. Add service method into it, which takes two arguements ServletRequest and ServletResponse

4. Handle the request and send appropriate response to the client using the service() method

5. save and compile the .java file

6. Copy and paste the .class file generated into “C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\examples\WEB-INF\classes” directory
(I’m using Tomcat 6.0 here, directory name may vary according to apache server version)

7. edit “web.xml” file located in “C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\examples\WEB-INF” directory

8. add appropriate <servet> and <servlet-mapping> tag in “web.xml” file
e.g. Here name of servlet is myServlet

<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>myServlet</servlet-class>

</servlet>
<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>/myServlet</url-pattern>

</servlet-mapping>

9. execute the servlet
e.g.
http://127.0.0.1:8080/examples/myServlet

10. All Done!!

NIIT Malad Center Rocks!!

Top 5 Productivity Killers at the Office

डिसेंबर 15, 2008

IM: (AIM, MSN, Yahoo, Google Chat, Twitter)

PRODUCTIVITY KILLERS! Ok so hey we’re not totally out of our minds, we do use these tools at times to keep in touch with our staff, partners, and contractors. The reason that we say it’s a real productivity killer is because of all the non-work related chatter inherit with these programs. You get links to the latest you-tube videos, rants, bored “whatups” from people with nothing better to than waste your precious time. It takes a good 15-20 minutes to get back in the zone and being productive, you can just imagine the effect this has on people over an 8 hr work period. Twitter is a whole other beast. If in a few months my co-workers and associates asking me to get on twitter, I will permanently unplug my Ethernet connection.

Internet Browsing

Yes, it’s great having information at your fingertips and the browser has been the single best tool at getting us information hosted on thousands if not millions of servers across the inter-planetary-galactic-universe-watchamacallit. The problem is it’s not only information. Any worry, thought, inkling for a bit of mid-work entertainment and boom, off to browser land and onto your favorite World Wide Web Address. Mix the Browser with IM and you got a lethal concoction of mindless stupor that can lead to hours of ROFL, LOL, checkdisout!.

Search (Google,Yahoo,MSN)

Once again, great tool with tremendous benefits. But it’s never just used for what it’s ideally meant to be used for. The Search Engine is the new Calculator of our time. We just don’t have to think anymore. Any problem, question, thought we have can now be Google’d. Yes just Google away and hope that someone else has done all the hard-thinking work for us and posted it in some forum, some blog, some article. Most of the time unless it’s technical, it rarely helps and we find out hey we actually need to put some thought into our work. Throw in a mix of ads, irrelevant search results and my search for the answer to my latest problem lands me on a blog about why my dog feels the need to hump my neighbors leg.

Faxing

Oh how I detest this. If this list was up to me and not the whole staff at our office, every item on this list would have to do with the fax machine! Why is it in the time of IM, 2gig Emails, VOIP, Wireless web on my iPhone, that I still have to run to the stupid FAX machine? The thing takes 1 page at a time with it’s AOL Dialup like buzzing like sound. The only improvement in the decades this machine has been around is that now it comes combined in all-in-one. It’s a total killer, there needs to be a better solution to send documents securely between two parties. There is money to be made here. Someone needs to get on it. If I am still using the fax machine in 5 years to send secure documents, please feel free to come and kick me on the shins!

E-Mail

Now this is a great tool, I’m not putting down its immense usefulness. I am putting down the people that don’t know how to use it and the people that think I really want to know how to enlarge an appendage on my body and that I need to know about everyday of the week. Why do I have to dig through 100 emails to get to the one that is most important to me. Why? Why? Why?

And even when I get to the important ones, the senders don’t have a clue how to use the subject box to title an e-mail properly, either using “Help”, “Respond back”, “ASAP” . Mind you, these are the same subject titles used by the good folks at NIIT ltd.

Now all the tools and services mentioned above are great. They’ve done a lot to help people in business stay connected and share information at amazing speed. We’ve gone from a world of writing letters (that had formal etiquette) to a using various communication tools with no generally accepted guidelines for use. These are great tools, but used improperly they seriously drain productivity. We can’t escape using them if we want to be part of what’s going on in society. So we have to adapt and learn.

Student Biodata Swing Applet

डिसेंबर 4, 2008

Problem Statement:

Create Java program to enter BioData of Student,

 

Student bio data swing

Student bio data swing Applet

  

QuickStart:

Step by Step Guide,

          First we will import the java packages

import java.awt.*;  //import awt componentsimport java.awt.event.*;  //import awt eventsimport javax.swing.*;  //import swing componentsimport javax.swing.JOptionPane.*; //import

       we are implementing the program using applet so we have
to append following lines into the code-

/*        
<applet code=”BioData” height=”220″ width=”400″>
</applet>

*/

also we are creating an applet so we extend the class from JApplet

 

 

public class BioData extends JApplet

 

Perform required declaration of java components in the classs:

 

       
 
JLabel lblName, lblAddress, lblTelephone, lblGender,lblQual;
       
 
JTextField txtName, txtAddress, txtTelephone;
       
 
JPanel c,pnlGender,pnlOk;
       
 
JRadioButton optMale,optFemale;
       
 
ButtonGroup optGroup;
         JComboBox cmbQual;
       
 
JButton btnSubmit,btnClose;
 

In the constructor we will initialize the previously declared components:


public BioData(){
         
lblName=new JLabel(“Name:”,JLabel.RIGHT);

           txtName=new JTextField(15);

           lblAddress=new JLabel(“Address”,JLabel.RIGHT);

          txtAddress=new JTextField(15);

          lblTelephone=new JLabel(“Telephone”,JLabel.RIGHT);

           txtTelephone=new JTextField(15);


          lblGender=new JLabel(“Gender”,JLabel.RIGHT);


          pnlGender=new JPanel();

          optMale=new JRadioButton(“Male”);


          optFemale=new JRadioButton(“Female”);


          optGroup=new ButtonGroup();


          lblQual=new JLabel(“Qualification”,JLabel.RIGHT);


          cmbQual=new JComboBox();

          pnlOk=new JPanel();


          btnSubmit=new JButton(“Submit”);


          btnClose=new JButton(“Close”);

          c=new JPanel();

 }

In the init() method of JApplet which initializes the JApplet, we add the components
to the applet window container using add() method, this method is called
automatically when you run applet using appletviewer or  a browser

public void init(){ 
         setLayout(new FlowLayout(FlowLayout.CENTER)); 

         c.setBackground(new java.awt.Color(204, 204, 255)); 

         c.setLayout(new GridLayout(5,2)); 

         c.add(lblName);
         c.add(txtName); 

         c.add(lblAddress);

         c.add(txtAddress); 


         c.add(lblTelephone);

          c.add(txtTelephone);


          c.add(lblGender);

          c.add(pnlGender); 


         optGroup.add(optMale); 


         optGroup.add(optFemale); 


         pnlGender.add(optMale); 


         pnlGender.add(optFemale); 


         cmbQual.addItem(“BSc”); 


         cmbQual.addItem(“BCom”); 


         cmbQual.addItem(“BA”); 


         c.add(lblQual); 

         c.add(cmbQual); 


         //c.setLocation(0,0);

         setSize(400,220); 


         add(c);

         add(btnSubmit);

         add(btnClose); 


         btnClose.addActionListener(new ActionListener(){ 

             
   public void actionPerformed(ActionEvent ae){ 

             
           System.out.println(ae.getActionCommand()); 


                       
 JOptionPane.showMessageDialog(btnClose,ae.getActionCommand()); 

             
   } 

         }); 


         btnSubmit.addActionListener(new ActionListener(){ 

             
   public void actionPerformed(ActionEvent ae){

             
            System.out.println(ae.getActionCommand()); 


                       
 JOptionPane.showMessageDialog(btnSubmit,ae.getActionCommand());

             
    } 

         }); 

 }

 

in init() method we are using anonymous classes to handle events, using anonymous
classes in the java applications is the best way for event handling,

Finally, Save the file as “BioData.java”

Open cmd, go to the directory
where the file is located eg. cd Java

Compile program using javac BioData.java

To run the applet use command appletviewer BioData.java

Here’s the output of program:

 

biodata

biodata

                       

Download Source code

Thanx for Reading the article, this is my First Java article .