<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6627970515100200907</id><updated>2012-02-16T06:43:19.638-08:00</updated><category term='JAVA 2.0 NOTE-14'/><category term='JAVA 2.0 NOTE-2'/><category term='FAQ-9'/><category term='Architecture'/><category term='JAVA INTERVIEW TIPS'/><category term='Faq-14'/><category term='JAVA 2.0 NOTE-6'/><category term='Java Example Event Programming-9'/><category term='Java Example Event Programming-10'/><category term='CORE JAVA faqs2'/><category term='String'/><category term='Core JAVA1'/><category term='Java Example Event Programming-6'/><category term='FAQ-2'/><category term='JVM faqs2'/><category term='FAQ-5'/><category term='Core JAVA4'/><category term='Java Example Event Programming-3'/><category term='EJB'/><category term='procedures'/><category term='String in Java'/><category term='JAVA 2.0 NOTE-3'/><category term='Java Swings'/><category term='Faq-13'/><category term='JAVA 2.0 NOTE-5'/><category term='Java Multi Threading'/><category term='Java Example Event Programming-11'/><category term='FAQ-6'/><category term='JAVA 2.0 NOTE-9'/><category term='History of Java'/><category term='faq-11'/><category term='JAVA 2.0 NOTE-10'/><category term='Java Example Event Programming-7'/><category term='FAQ-3'/><category term='Core JAVA2'/><category term='Java Example Event Programming-14'/><category term='JAVA 2.0 NOTE-13'/><category term='Java Example Event Programming-2'/><category term='FAQ-10'/><category term='Core JAVA3'/><category term='Java Example Event Programming-12'/><category term='Java Example Event Programming-5'/><category term='java Tips'/><category term='JAVA 2.0 NOTE-12'/><category term='JAVA 2.0 NOTE-16'/><category term='Java Inheritance'/><category term='CORE JAVA faqs'/><category term='Java Threads'/><category term='Java Example Event Programming-15'/><category term='JAVA 2.0 NOTE-8'/><category term='FAQ-7'/><category term='faq-12'/><category term='XML'/><category term='Faq-16'/><category term='HIBERNATE'/><category term='Java Example Event Programming-8'/><category term='FAQ-4'/><category term='Points learnt from Java mock exams'/><category term='Variable n Expression'/><category term='FAQ-1'/><category term='Java Example Event Programming-13'/><category term='Abstract Class and Interface'/><category term='JAVA 2.0 NOTE-15'/><category term='Java Exceptions'/><category term='Simple java prog.'/><category term='struts'/><category term='JAVA 2.0 NOTE-7'/><category term='JVM FAQs'/><category term='JAVA 2.0 NOTE-11'/><category term='FAQ-8'/><category term='Java Example Event Programming-1'/><category term='Assertion in Java'/><category term='JAVA 2.0 NOTE-4'/><category term='Wrapper Classes'/><category term='Faq-15'/><category term='JAVA 2.0 NOTE-1'/><title type='text'>Java</title><subtitle type='html'>Java - J2EE - Strings - Constructors - AWT - Multithreading - Exception Handling - Garbage Collection - J2ME - JDBC - Servlets - JSP - WebSphere - WSAD - Weblogic - Tomcat - Eclipse - JFC - Swings - EJB - Struts - Spring - Hibernate - AJAX - HTML - UML -JavaScript - XML - Webservices - SOAP - AXIS - JMS - JNDI - Oracle -PL/SQL - MySQL - InterviewQuestions</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>78</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-7577289806846895510</id><published>2008-03-05T07:06:00.000-08:00</published><updated>2008-03-05T07:20:05.614-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA INTERVIEW TIPS'/><title type='text'>JAVA INTERVIEW TIPS</title><content type='html'>&lt;strong&gt;&lt;span style="color:#000099;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000099;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000099;"&gt;Tip #1&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Be honest to answer technical questions, you are not expected to remember everything (for example you might know a few design patterns but not all of them). If you have not used a design pattern in question, request the interviewer, if you could describe a different design pattern.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000099;"&gt;Tip #2&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Every body is nervous for interviews and being a little nervous is natural. But if you are too nervous then you can overcome this by preparing for your interviews and by treating each interview as a free technical/behavioural training course. Have an attitude that even if you are not going to get the job, you are going to learn something good out of it. If you go with this attitude you will put yourself in a win/win situation and you might really get the offer. If you take this attitude you can learn a lot from your interviews. Also never think that you have to answer all the questions correctly. Do not get put off by a tricky or a difficult question. What really earns you a job is the combination of your knowledge + experience + attitude&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000099;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000099;"&gt;Tip #3&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Where possible briefly demonstrate how you applied your skills/knowledge in the key areas like design concepts, transactional issues, performance issues, memory leaks, best practices etc as described in the book Java/J2EE Job Interview Companion along with your business skills and interpersonal skills. Find the right time to raise questions and answer those questions to show your strength in the technical key areas, business and interpersonal skills.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000099;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000099;"&gt;Tip #4&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Tell me about yourself or about some of the recent projects you have worked with? What do you consider your most significant achievement? Why do you think you are qualified for this position?Above mentioned interview questions are very common and the interviewer will be mainly looking for 4 qualities:1. Passion.2. Ability to understand potential failures (transactional issues, concurrency issues, design issues etc).3. Ability to see things at a high level as well as drill down when required.4. Ability to think dynamically to deliver solutions to complex problems and ability to analyse “what if ” scenarios (What if I want to support a non Web client?, What if I want to support other types of products? etc).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000099;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000099;"&gt;Tip #5&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;What was the last Java related technical book or article you read? Which Java related website(s) or resource(s) do you use to keep your knowledge up to date beyond Google? What do you think of some of the emerging technologies/frameworks like AOP, IOC, Spring, Tapestry etc? What recent technology trends are important to enterprise development?The interviewer will be mainly looking for your:Curiosity to learn: How eager you are to learn new things and keep up to date with the technology.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Learn the Java/J2EE Core Concepts/Key Areas with an easy to understand questions and answers approach.The best way to make an impression in any organizations is to understand and proactively apply and resolve the issues relating to 14 Key Areas covered in this book.Lulu books Top 100 best seller.Free Java J2EE Interview Q&amp;amp;A PDF download.&lt;br /&gt;&lt;br /&gt;1. Language Fundamentals&lt;br /&gt;&lt;br /&gt;2. Specification Fundamentals&lt;br /&gt;&lt;br /&gt;3. Design Concepts&lt;br /&gt;&lt;br /&gt;4. Design Patterns&lt;br /&gt;&lt;br /&gt;5. Transactional Issues&lt;br /&gt;&lt;br /&gt;6. Concurrency Issues&lt;br /&gt;&lt;br /&gt;7. Performance Issues&lt;br /&gt;&lt;br /&gt;8. Scalability Issues&lt;br /&gt;&lt;br /&gt;9. Memory Issues&lt;br /&gt;&lt;br /&gt;10. Exception Handling&lt;br /&gt;&lt;br /&gt;11. Security&lt;br /&gt;&lt;br /&gt;12. Best Practices&lt;br /&gt;&lt;br /&gt;13. Software Development Process&lt;br /&gt;&lt;br /&gt;14. Coding&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This book will assist all Java/J2EE practitioners to become better at what they do. Usually it takes years to understand all the core concepts and design/coding issues when you rely only on your work experience. The best way to fast track this is to read appropriate technical information and proactively apply these in your work environment. It worked for me and hopefully it will work for you as well. I was also at one stage undecided whether to name this book Java/J2EE core concepts and solving design/coding issues or Java/J2EE Job Interview Companion. The reason I chose Java/J2EE Job Interview Companion is because these core concepts and design/coding issues helped me to be successful in my interviews and also gave me thumbs up in code reviews.&lt;br /&gt;&lt;br /&gt;Succeed in your Java J2EE Job interviews with the help of &lt;a href="http://java4interview.blogspot.com/"&gt;Java/J2EE Job Interview Companion&lt;br /&gt;&lt;/a&gt;Over 400 frequently asked and popular Java J2EE Interview Questions with clear and concise answers. All answers are well supported with diagrams, examples, code snippets and cross referencing.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000099;"&gt;STICK TO THIS SITE!!!!&lt;/span&gt;&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-7577289806846895510?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/7577289806846895510/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=7577289806846895510' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/7577289806846895510'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/7577289806846895510'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/03/tip-1-be-honest-to-answer-technical.html' title='JAVA INTERVIEW TIPS'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-9222031646420478193</id><published>2008-01-07T00:08:00.000-08:00</published><updated>2008-01-07T01:09:41.631-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example Event Programming-15'/><title type='text'>Java Example Event Programming</title><content type='html'>&lt;strong&gt;&lt;span style="color:#660000;"&gt;Swing Program&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;&lt;br /&gt;&lt;textarea name="unique_name" rows="3" cols="30"&gt;* &lt;applet code="butt" width="400" height="500"&gt; &lt;/applet&gt; */ &lt;textarea&gt;&lt;br /&gt;&lt;br /&gt;public class butt extends JApplet&lt;br /&gt;{&lt;br /&gt;public void init()&lt;br /&gt;{&lt;br /&gt;Container c = getContentPane();&lt;br /&gt;ImageIcon ii = new ImageIcon("fish.gif");&lt;br /&gt;JLabel j = new JLabel("Fish image",ii,JLabel.LEFT);&lt;br /&gt;c.add(j);&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.awt.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;&lt;br /&gt;&lt;textarea name="unique_name" rows="3" cols="30"&gt;* &lt;applet code="butt1" width="400" height="500"&gt; &lt;/applet&gt; */ &lt;textarea&gt;&lt;br /&gt;&lt;br /&gt;public class butt1 extends JApplet implements ActionListener&lt;br /&gt;{&lt;br /&gt;JTextField jtf = new JTextField(20);&lt;br /&gt;public void init()&lt;br /&gt;{&lt;br /&gt;Container c = getContentPane();&lt;br /&gt;c.setLayout(new GridLayout(4,4));&lt;br /&gt;ImageIcon i1 = new ImageIcon("Genier.gif");&lt;br /&gt;ImageIcon i2 = new ImageIcon("Genieg.gif");&lt;br /&gt;ImageIcon i3 = new ImageIcon("Genies.gif");    &lt;br /&gt;JButton jb1 = new JButton(i1);&lt;br /&gt;JButton jb2 = new JButton(i2);&lt;br /&gt;JButton jb3 = new JButton(i3);&lt;br /&gt;jb1.setActionCommand("Fish");&lt;br /&gt;jb2.setActionCommand("Genisis");&lt;br /&gt;jb3.setActionCommand("Cherries");&lt;br /&gt;jb1.addActionListener(this);&lt;br /&gt;jb2.addActionListener(this);&lt;br /&gt;jb3.addActionListener(this);&lt;br /&gt;for(int i=0;i&lt;6000;i++);&lt;br /&gt;c.add(jb1);&lt;br /&gt;for(int i=0;i&lt;26000;i++);&lt;br /&gt;c.add(jb2);&lt;br /&gt;for(int i=0;i&lt;26000;i++);&lt;br /&gt;c.add(jb3);&lt;br /&gt;c.add(jtf);&lt;br /&gt;}&lt;br /&gt;public void actionPerformed(ActionEvent ae)&lt;br /&gt;{&lt;br /&gt;jtf.setText(ae.getActionCommand());&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.awt.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;&lt;br /&gt;&lt;textarea name="unique_name" rows="3" cols="30"&gt;* &lt;applet code="gene" width="400" height="500"&gt; &lt;/applet&gt; */ &lt;textarea&gt;&lt;br /&gt;&lt;br /&gt;public class gene extends JApplet implements ActionListener&lt;br /&gt;{&lt;br /&gt;JLabel l;&lt;br /&gt;public void init()&lt;br /&gt;{&lt;br /&gt;Container c = getContentPane();&lt;br /&gt;l = new JLabel("Image icon");&lt;br /&gt;c.setLayout(new GridLayout(3,3));&lt;br /&gt;ImageIcon i2 = new ImageIcon("Genieg.gif");&lt;br /&gt;JButton jb2 = new JButton("swing button",i2);&lt;br /&gt;jb2.setActionCommand("Genisis");&lt;br /&gt;c.add(jb2);&lt;br /&gt;jb2.addActionListener(this);&lt;br /&gt;}&lt;br /&gt;public void actionPerformed(ActionEvent a)&lt;br /&gt;{&lt;br /&gt;l.setText("Pressed");&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.awt.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;&lt;br /&gt;&lt;textarea name="unique_name" rows="3" cols="30"&gt;* &lt;applet code="geneier" width="400" height="500"&gt; &lt;/applet&gt; */ &lt;textarea&gt;&lt;br /&gt;&lt;br /&gt;public class geneier extends JApplet implements ActionListener&lt;br /&gt;{&lt;br /&gt;JTextField jtf = new JTextField(20);&lt;br /&gt;JButton jb1;&lt;br /&gt;Container c = getContentPane();&lt;br /&gt;public void init()&lt;br /&gt;{&lt;br /&gt;c.setLayout(new GridLayout(2,2));&lt;br /&gt;ImageIcon i1 = new ImageIcon("Genier.gif");&lt;br /&gt;ImageIcon i2 = new ImageIcon("Genieg.gif");&lt;br /&gt;ImageIcon i3 = new ImageIcon("Genies.gif");&lt;br /&gt;jb1 = new JButton(i1);&lt;br /&gt;for(int i=0;i&lt;26000;i++);&lt;br /&gt;for(int i=0;i&lt;26000;i++);&lt;br /&gt;jb1.setIcon(i2);&lt;br /&gt;for(int i=0;i&lt;26000;i++);&lt;br /&gt;for(int i=0;i&lt;26000;i++);&lt;br /&gt;c.add(jb1);&lt;br /&gt;jb1.setActionCommand("Fish");&lt;br /&gt;jb1.addActionListener(this);&lt;br /&gt;c.add(jtf);&lt;br /&gt;for(int i=0;i&lt;26000;i++);&lt;br /&gt;for(int i=0;i&lt;26000;i++);&lt;br /&gt;for(int i=0;i&lt;26000;i++);&lt;br /&gt;c.add(jb1);&lt;br /&gt;}&lt;br /&gt;/* public void paint(Graphics g)&lt;br /&gt;{&lt;br /&gt;c.add(jb1);&lt;br /&gt;}&lt;br /&gt;*/&lt;br /&gt;public void actionPerformed(ActionEvent ae)&lt;br /&gt;{&lt;br /&gt;jtf.setText(ae.getActionCommand());&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.*;&lt;br /&gt;public class jscroll extends JApplet&lt;br /&gt;{&lt;br /&gt;public void init( )&lt;br /&gt;{&lt;br /&gt;Container CP = getContentPane( );&lt;br /&gt;JPanel jp = new JPanel( );&lt;br /&gt;GridLayout g = new GridLayout(20,20);&lt;br /&gt;jp.setLayout(g);&lt;br /&gt;int b = 0,i,k;&lt;br /&gt;for( i = 0; i&lt;20; i++)&lt;br /&gt;{&lt;br /&gt;for(k=0;k&lt;20;k++)&lt;br /&gt;{&lt;br /&gt;jp.add(new JButton("Button " + b));&lt;br /&gt;b++;&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;&lt;br /&gt;int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;&lt;br /&gt;JScrollPane jsp = new JScrollPane(jp, v, h) ;&lt;br /&gt;CP.add(jsp, BorderLayout.CENTER);&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.awt.*;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;public class radio extends JApplet&lt;br /&gt;{&lt;br /&gt;public void init()&lt;br /&gt;{&lt;br /&gt;Container c = getContentPane();&lt;br /&gt;c.setLayout(new FlowLayout());&lt;br /&gt;ImageIcon i1 = new ImageIcon("cup1.gif");&lt;br /&gt;ImageIcon i2 = new ImageIcon("cup2.gif");&lt;br /&gt;ImageIcon i3 = new ImageIcon("cup3.gif");&lt;br /&gt;JRadioButton jb1 = new JRadioButton("Face ",i1);&lt;br /&gt;JRadioButton jb2 = new JRadioButton("Sun ",i2);&lt;br /&gt;JRadioButton jb3 = new JRadioButton("Song ",i3);&lt;br /&gt;ButtonGroup bg = new ButtonGroup();&lt;br /&gt;bg.add(jb1);&lt;br /&gt;bg.add(jb2);&lt;br /&gt;bg.add(jb3);&lt;br /&gt;c.add(jb1);&lt;br /&gt;c.add(jb2);&lt;br /&gt;c.add(jb3);&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.*;&lt;br /&gt;public class swing1 extends JApplet&lt;br /&gt;{&lt;br /&gt;public void init()&lt;br /&gt;{&lt;br /&gt;Container cp=getContentPane();&lt;br /&gt;JLabel l1=new JLabel("Enter name");&lt;br /&gt;JTextField jt=new JTextField(20);&lt;br /&gt;JLabel l2=new JLabel("Enter age");&lt;br /&gt;JTextField jt1=new JTextField(20);&lt;br /&gt;cp.add(l1);cp.add(jt);&lt;br /&gt;cp.add(l2);cp.add(jt1); }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;textarea name="unique_name" rows="3" cols="30"&gt;* &lt;applet code="geneier" width="400" height="500"&gt; &lt;/applet&gt; */ &lt;/textarea&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-9222031646420478193?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/9222031646420478193/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=9222031646420478193' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/9222031646420478193'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/9222031646420478193'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/01/java-example-event-programming_1088.html' title='Java Example Event Programming'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-9140487033435318206</id><published>2008-01-07T00:06:00.000-08:00</published><updated>2008-01-07T00:07:34.790-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example Event Programming-14'/><title type='text'>Java Example Event Programming</title><content type='html'>&lt;strong&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color:#660000;"&gt;Servelts Program&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;import java.io.*;&lt;br /&gt;import javax.servlet.*;&lt;br /&gt;import javax.servlet.http;&lt;br /&gt;public class colorservlet extends HttpServlet&lt;br /&gt;{&lt;br /&gt;public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException, HttpServletException&lt;br /&gt;{&lt;br /&gt;String color = request.getParameter("color");&lt;br /&gt;res.setContentType("text/html");&lt;br /&gt;PrintWriter pw = res.getWriter();&lt;br /&gt;pw.println("&lt;b&gt; the selected color is &lt;/b&gt;");&lt;br /&gt;pw.println(color);&lt;br /&gt;pw.close();&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.io.*;&lt;br /&gt;import javax.servlet.*;&lt;br /&gt;public class serv1 extends GenericServlet&lt;br /&gt;{&lt;br /&gt;public void service (ServletRequest req, ServletResponse res) throws ServletException,IOException&lt;br /&gt;{&lt;br /&gt;res.setContentType("text/html");&lt;br /&gt;PrintWriter pw = res.getWriter();&lt;br /&gt;pw.println("&lt;b&gt; Hello &lt;i&gt; Palani&lt;/b&gt;&lt;/i&gt;");&lt;br /&gt;pw.close();&lt;br /&gt;}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-9140487033435318206?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/9140487033435318206/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=9140487033435318206' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/9140487033435318206'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/9140487033435318206'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/01/java-example-event-programming_3006.html' title='Java Example Event Programming'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-3360013270386298105</id><published>2008-01-07T00:03:00.000-08:00</published><updated>2008-01-07T00:05:55.927-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example Event Programming-13'/><title type='text'>Java Example Event Programming</title><content type='html'>&lt;strong&gt;&lt;span style="font-size:130%;color:#660000;"&gt;Important points&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.rmi.* ; all methods in this package throws&lt;br /&gt;RemoteException that must be caught.&lt;br /&gt;Remote in interface indicates that this is remote interface,&lt;br /&gt;the methods can be used by object in the remote machine.&lt;br /&gt;Server extends UnicastRemoteObject implements&lt;br /&gt;remote interface&lt;br /&gt;Also import java.rmi.server.* for server program&lt;br /&gt;Naming.rebind("servername", serverobject);&lt;br /&gt;Others methods are bind , rebind, unbind&lt;br /&gt;In client, Naming.lookup("rmi://ipaddress/servername") method is used to identify the server and returns remote interface. 6. Use inter.method to call the method in client.    &lt;br /&gt;Steps to exucute RMI&lt;br /&gt;Write programs for interface, server and client and compile them.&lt;br /&gt;javac inter.java&lt;br /&gt;javac server.java&lt;br /&gt;javac client.java or javac *.java&lt;br /&gt;2. Then use rmi compiler to create stub and skeleton class.&lt;br /&gt;rmic server&lt;br /&gt;3. Copy inter, server, skeleton to server machine and&lt;br /&gt;inter, client and stub to client program&lt;br /&gt;4. Then start rmi registry by&lt;br /&gt;start rmiregistry&lt;br /&gt;5. Run the server program in server machine by&lt;br /&gt;java server&lt;br /&gt;6. Execute the client program by&lt;br /&gt;java client ipaddress arg1 arg2&lt;br /&gt;java client 200.200.1.120 5 8  &lt;br /&gt;&lt;br /&gt;import java.rmi.*;&lt;br /&gt;public class client&lt;br /&gt;{&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;int a = Integer.parseInt(arg[1]);&lt;br /&gt;int b = Integer.parseInt(arg[2]);&lt;br /&gt;int result;&lt;br /&gt;inter i = (inter) Naming.lookup("rmi://" + arg[0] + "/Addserver");&lt;br /&gt;System.out.println("client");&lt;br /&gt;i.getdata(a,b);&lt;br /&gt;result = i.adddata();&lt;br /&gt;System.out.println(result);&lt;br /&gt;}&lt;br /&gt;catch(Exception e)&lt;br /&gt;{&lt;br /&gt;System.out.println("error " + e);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;/* Example for deserialization&lt;br /&gt;ObjectInputStream(FileInputStream f)&lt;br /&gt;*/&lt;br /&gt;import java.io.*;&lt;br /&gt;class myclass implements Serializable&lt;br /&gt;{&lt;br /&gt;String s;&lt;br /&gt;int i;&lt;br /&gt;int j;&lt;br /&gt;myclass(String s1,int m,int n)&lt;br /&gt;{&lt;br /&gt;s=s1; i=m;j=n;&lt;br /&gt;}&lt;br /&gt;public String toString()&lt;br /&gt;{&lt;br /&gt;return (s + i + j);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;class deser&lt;br /&gt;{&lt;br /&gt;public static void main(String arg[]) throws Exception&lt;br /&gt;{&lt;br /&gt;myclass ob2 ;&lt;br /&gt;FileInputStream f = new FileInputStream("obj");&lt;br /&gt;ObjectInputStream o = new ObjectInputStream(f);&lt;br /&gt;ob2 = (myclass) o.readObject();&lt;br /&gt;System.out.println(ob2.s + ob2.i);&lt;br /&gt;o.close();&lt;br /&gt;System.out.println("Obeject2 " + ob2);&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.rmi.*;&lt;br /&gt;public interface inter extends Remote&lt;br /&gt;{&lt;br /&gt;public void getdata(int m,int n) throws RemoteException;&lt;br /&gt;int adddata() throws RemoteException;&lt;br /&gt;}    &lt;br /&gt;/* Example for serialization&lt;br /&gt;ObjectOutputStream(FileOutputStream f)&lt;br /&gt;o.writeObject(ob)&lt;br /&gt;*/&lt;br /&gt;import java.io.*;&lt;br /&gt;class myclass implements Serializable&lt;br /&gt;{&lt;br /&gt;String s;&lt;br /&gt;int i;&lt;br /&gt;int j;&lt;br /&gt;myclass(String s1,int m,int n)&lt;br /&gt;{&lt;br /&gt;s=s1; i=m;j=n;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;class ser&lt;br /&gt;{&lt;br /&gt;public static void main(String arg[]) throws IOException, NotSerializableException&lt;br /&gt;{&lt;br /&gt;myclass ob = new myclass("Murali",4,5);&lt;br /&gt;FileOutputStream f = new FileOutputStream("obj");&lt;br /&gt;ObjectOutputStream o = new ObjectOutputStream(f);&lt;br /&gt;o.writeObject(ob);&lt;br /&gt;o.flush();&lt;br /&gt;o.close();&lt;br /&gt;System.out.println(ob);&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.rmi.*;&lt;br /&gt;import java.rmi.server.*;&lt;br /&gt;public class server extends UnicastRemoteObject implements inter&lt;br /&gt;{&lt;br /&gt;int x,y;&lt;br /&gt;public server() throws RemoteException&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;public int adddata() throws RemoteException&lt;br /&gt;{&lt;br /&gt;return x+y;&lt;br /&gt;}&lt;br /&gt;public void getdata(int m, int n) throws RemoteException&lt;br /&gt;{&lt;br /&gt;x=m; y=n;&lt;br /&gt;}&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;server s = new server();&lt;br /&gt;Naming.rebind("Addserver",s);&lt;br /&gt;}&lt;br /&gt;catch(Exception e)&lt;br /&gt;{&lt;br /&gt;System.out.println("Exception e");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.rmi.*;&lt;br /&gt;import java.rmiregistry.*;&lt;br /&gt;public class clientport&lt;br /&gt;{&lt;br /&gt;public void actionPerformed(ActionEvent e)&lt;br /&gt;{&lt;br /&gt;if(e.getSource() == submit)&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;rmiserver server = (rmiserver) Naming.lookup("rmi//localhost/connect");&lt;br /&gt;String name = getData();&lt;br /&gt;}&lt;br /&gt;catch(Exception e)&lt;br /&gt;{&lt;br /&gt;System.out.pritnln("Unable to connect");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.sql.*;&lt;br /&gt;public class details&lt;br /&gt;{&lt;br /&gt;private Connection connect = null;&lt;br /&gt;private Statement query =null;&lt;br /&gt;private ResultSet result = null;&lt;br /&gt;String dsn;&lt;br /&gt;public details(String dsn)&lt;br /&gt;{&lt;br /&gt;this.dsn = "jdbc:odbc:" + dsn ;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;connect = DriverManager.getConnection(dsn,"","");&lt;br /&gt;query = connect.createStatement();&lt;br /&gt;}&lt;br /&gt;catch(Exception e)&lt;br /&gt;{&lt;br /&gt;e.printStackTrace();&lt;br /&gt;System.out.println("Connection failed");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;public void setData(String Table, String data)&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;// String sql = "Insert into " + table + (name) values("'+data+'")";&lt;br /&gt;String sql = "Insert into table(name) values('rrr')";&lt;br /&gt;query.executeUpdate(sql);&lt;br /&gt;}&lt;br /&gt;catch(Exception e)&lt;br /&gt;{&lt;br /&gt;System.out.println("Query failed");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.rmi.*;&lt;br /&gt;import java.rmi.server.*;&lt;br /&gt;public class rmidatabase extends UnicastRemoteObject implements rmiserver&lt;br /&gt;{&lt;br /&gt;private details det=null;&lt;br /&gt;public rmidatabase(String name) throws RemoteException&lt;br /&gt;{&lt;br /&gt;super();&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;Naming.rebind(name,this);&lt;br /&gt;}&lt;br /&gt;catch(Exception e)&lt;br /&gt;{&lt;br /&gt;System.out.println("Unable to bind");&lt;br /&gt;}&lt;br /&gt;det = new details("student");&lt;br /&gt;}&lt;br /&gt;public String receiveData(String s)&lt;br /&gt;{&lt;br /&gt;return null;&lt;br /&gt;}&lt;br /&gt;public void sendData(String data)&lt;br /&gt;{&lt;br /&gt;System.out.println("Server sending data");&lt;br /&gt;det.sendData("registration",data);&lt;br /&gt;}&lt;br /&gt;public static void main(String a[])&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;System.setSecurityManager(new RMISecurityManager());&lt;br /&gt;rmidatabase connect = new rmidatabase("connect");&lt;br /&gt;System.out.println("Server started");&lt;br /&gt;}&lt;br /&gt;catch(Exception e)&lt;br /&gt;{&lt;br /&gt;System.out.println("Error in server");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.rmi.*;&lt;br /&gt;interface rmiserver extends Remote&lt;br /&gt;{&lt;br /&gt;public void sendData(String data) throws RemoteException ;&lt;br /&gt;public String receiveData(String data) throws RemoteException ;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-3360013270386298105?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/3360013270386298105/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=3360013270386298105' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3360013270386298105'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3360013270386298105'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/01/java-example-event-programming_07.html' title='Java Example Event Programming'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-1469711116275021859</id><published>2008-01-06T23:59:00.000-08:00</published><updated>2008-01-07T00:02:41.063-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example Event Programming-12'/><title type='text'>Java Example Event Programming</title><content type='html'>&lt;strong&gt;&lt;span style="color:#660000;"&gt;Remote Method Invocation [RMI]    &lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;allows object in one machine to use method in another machine&lt;br /&gt;one method of creating distributed application&lt;br /&gt;Layers in RMI&lt;br /&gt;Stub/Skeleton Layer&lt;br /&gt;&lt;br /&gt;Remote Reference Layer&lt;br /&gt;&lt;br /&gt;Transport Layer    &lt;br /&gt;Client Server    &lt;br /&gt;Stub Skeleton   &lt;br /&gt;RRL RRL    &lt;br /&gt;Transport Layer Transport Layer    &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Example program to find the sum of 2 numbers using rmi&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;inter.java&lt;br /&gt;import java.rmi.*;&lt;br /&gt;public interface inter extends Remote&lt;br /&gt;{&lt;br /&gt;public void getdata(int m,int n) throws RemoteException;&lt;br /&gt;int adddata() throws RemoteException;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;color:#660000;"&gt;server.java&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;import java.rmi.*;&lt;br /&gt;import java.rmi.server.*;&lt;br /&gt;public class server extends UnicastRemoteObject implements inter&lt;br /&gt;{&lt;br /&gt;int x,y;&lt;br /&gt;public server() throws RemoteException&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;public int adddata() throws RemoteException&lt;br /&gt;{&lt;br /&gt;return x+y;&lt;br /&gt;}&lt;br /&gt;public void getdata(int m, int n) throws RemoteException&lt;br /&gt;{&lt;br /&gt;x=m; y=n;&lt;br /&gt;}&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;server s = new server();&lt;br /&gt;Naming.rebind("Addserver",s);&lt;br /&gt;}&lt;br /&gt;catch(Exception e)&lt;br /&gt;{&lt;br /&gt;System.out.println("can not bund the name " + e);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;color:#660000;"&gt;client.java&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;import java.rmi.*;&lt;br /&gt;public class client&lt;br /&gt;{&lt;br /&gt;public static void main(String arg[ ])&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;int a = Integer.parseInt(arg[1]);&lt;br /&gt;int b = Integer.parseInt(arg[2]);&lt;br /&gt;int result;&lt;br /&gt;inter i = (inter) Naming.lookup("rmi://" + arg[0] +&lt;br /&gt;"/Addserver");&lt;br /&gt;System.out.println("client");&lt;br /&gt;i.getdata(a,b);&lt;br /&gt;result = i.adddata();&lt;br /&gt;System.out.println(result);&lt;br /&gt;}&lt;br /&gt;catch(Exception e)&lt;br /&gt;{&lt;br /&gt;System.out.println("can not connect with server " + e);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-1469711116275021859?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/1469711116275021859/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=1469711116275021859' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1469711116275021859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1469711116275021859'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/01/java-example-event-programming_6477.html' title='Java Example Event Programming'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-1554530708311590824</id><published>2008-01-06T23:57:00.000-08:00</published><updated>2008-01-06T23:58:56.208-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example Event Programming-11'/><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="font-size:130%;color:#660000;"&gt;Pack Programs&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;import pack.*;&lt;br /&gt;class p&lt;br /&gt;{&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;{&lt;br /&gt;pa p = new pa();&lt;br /&gt;p.m();&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;package pack;&lt;br /&gt;public class pa&lt;br /&gt;{&lt;br /&gt;public void m()&lt;br /&gt;{&lt;br /&gt;aa ob = new aa();&lt;br /&gt;System.out.println(ob.a);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;class aa&lt;br /&gt;{&lt;br /&gt;public int a=22;&lt;br /&gt;}    &lt;br /&gt;import pack.*;&lt;br /&gt;class pa1&lt;br /&gt;{&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;{&lt;br /&gt;pa p = new pa();&lt;br /&gt;p.m();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;import pack.*;&lt;br /&gt;class s&lt;br /&gt;{&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;{&lt;br /&gt;sample ss = new sample();&lt;br /&gt;ss.m();&lt;br /&gt;c ss1 = new c();&lt;br /&gt;System.out.println(ss1.a);&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;package pack;&lt;br /&gt;import p.*;&lt;br /&gt;public class sam&lt;br /&gt;{&lt;br /&gt;public void m()&lt;br /&gt;{&lt;br /&gt;c ob1 = new c();&lt;br /&gt;// c1 ob2 = new c1();&lt;br /&gt;// c2 ob3 = new c2();&lt;br /&gt;ob2.m();&lt;br /&gt;// ob2.m2();&lt;br /&gt;System.out.println(ob1.a);&lt;br /&gt;// System.out.println(ob1.b);&lt;br /&gt;// System.out.println(ob1.c);&lt;br /&gt;// System.out.println(ob1.d);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;class c&lt;br /&gt;{&lt;br /&gt;public int a=55;&lt;br /&gt;}    &lt;br /&gt;package pack;&lt;br /&gt;public class sample&lt;br /&gt;{&lt;br /&gt;public void m()&lt;br /&gt;{&lt;br /&gt;c ob1 = new c();&lt;br /&gt;System.out.println(ob1.a);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;class c&lt;br /&gt;{&lt;br /&gt;public int a=55;&lt;br /&gt;}    &lt;br /&gt;package p;&lt;br /&gt;public class c&lt;br /&gt;{&lt;br /&gt;public int a=1;&lt;br /&gt;private int b=2;&lt;br /&gt;protected int c=3;&lt;br /&gt;int d =4;&lt;br /&gt;}    &lt;br /&gt;package p;&lt;br /&gt;public class c1&lt;br /&gt;{&lt;br /&gt;public void m()&lt;br /&gt;{&lt;br /&gt;System.out.println("m method");&lt;br /&gt;}&lt;br /&gt;public void m1()&lt;br /&gt;{&lt;br /&gt;System.out.println("m1 method");&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;package p;&lt;br /&gt;public class c2&lt;br /&gt;{&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;{&lt;br /&gt;System.out.println("this is package");&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;interface i&lt;br /&gt;{&lt;br /&gt;final int a=33;&lt;br /&gt;int b=44;&lt;br /&gt;class c&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;public void m();&lt;br /&gt;public void m1();&lt;br /&gt;}    &lt;br /&gt;class int1 implements i&lt;br /&gt;{&lt;br /&gt;public void m()&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;public void m1()&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;{&lt;br /&gt;c ob = new c();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;package p.p1;&lt;br /&gt;public class c&lt;br /&gt;{&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;{&lt;br /&gt;System.out.println("Subpackage");&lt;br /&gt;}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-1554530708311590824?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/1554530708311590824/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=1554530708311590824' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1554530708311590824'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1554530708311590824'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/01/pack-programs-import-pack.html' title=''/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-4411688754193299275</id><published>2008-01-06T23:52:00.000-08:00</published><updated>2008-01-06T23:55:00.263-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example Event Programming-10'/><title type='text'>Java Example Event Programming</title><content type='html'>&lt;span style="color:#330000;"&gt;&lt;span style="font-size:130%;"&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Network Program&lt;/span&gt; &lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;import java.net.*;&lt;br /&gt;&lt;br /&gt;class dataclient&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static DatagramSocket ds;&lt;br /&gt;&lt;br /&gt;public static byte buffer[] = new byte[1024];&lt;br /&gt;&lt;br /&gt;public static void main(String args[]) throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;ds = new DatagramSocket(1999);&lt;br /&gt;&lt;br /&gt;while(true)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;DatagramPacket p = new DatagramPacket(buffer,buffer.length);&lt;br /&gt;&lt;br /&gt;ds.receive(p);&lt;br /&gt;&lt;br /&gt;System.out.println(new String(p.getData(),0,p.getLength()));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.net.*;&lt;br /&gt;&lt;br /&gt;class dataserver&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static DatagramSocket ds;&lt;br /&gt;&lt;br /&gt;public static byte buffer[] = new byte[1024];&lt;br /&gt;&lt;br /&gt;public static void main(String args[]) throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;InetAddress ia = InetAddress.getByName(args[0]);&lt;br /&gt;&lt;br /&gt;ds = new DatagramSocket(1666);&lt;br /&gt;&lt;br /&gt;int pos=0;&lt;br /&gt;&lt;br /&gt;while(true)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int c = System.in.read();&lt;br /&gt;&lt;br /&gt;switch(c)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;case 'q':&lt;br /&gt;&lt;br /&gt;System.out.println("Server quits");&lt;br /&gt;&lt;br /&gt;return;&lt;br /&gt;&lt;br /&gt;case '\r':&lt;br /&gt;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case '\n':&lt;br /&gt;&lt;br /&gt;ds.send(new DatagramPacket(buffer,pos,ia,1999));&lt;br /&gt;&lt;br /&gt;pos=0;&lt;br /&gt;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;default:&lt;br /&gt;&lt;br /&gt;buffer[pos++] = (byte) c;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// a simple client that sends lines to server and reads lines from server&lt;br /&gt;&lt;br /&gt;import java.net.*;&lt;br /&gt;&lt;br /&gt;import java.io.* ;&lt;br /&gt;&lt;br /&gt;public class tcpclient&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String arg[]) throws IOException&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;InetAddress addr;&lt;br /&gt;&lt;br /&gt;if(arg.length &gt; 0)&lt;br /&gt;&lt;br /&gt;addr = InetAddress.getByName(arg[0]);&lt;br /&gt;&lt;br /&gt;else&lt;br /&gt;&lt;br /&gt;addr = InetAddress.getByName("localhost");&lt;br /&gt;&lt;br /&gt;System.out.println("addr = " + addr);&lt;br /&gt;&lt;br /&gt;Socket s = new Socket(addr,1666);&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("Socket = " + s);&lt;br /&gt;&lt;br /&gt;BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));&lt;br /&gt;&lt;br /&gt;PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(s.getOutputStream())),true);&lt;br /&gt;&lt;br /&gt;for(int i =0;i&lt;5;i++)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;out.println("howdy " + i);&lt;br /&gt;&lt;br /&gt;String str = in.readLine();&lt;br /&gt;&lt;br /&gt;System.out.println(str);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;out.println("End");&lt;br /&gt;&lt;br /&gt;} finally&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("closing...");&lt;br /&gt;&lt;br /&gt;s.close();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.io.* ;&lt;br /&gt;&lt;br /&gt;import java.net.* ;&lt;br /&gt;&lt;br /&gt;public class tcpserver&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String arg[]) throws IOException&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;ServerSocket ss = new ServerSocket(1666);&lt;br /&gt;&lt;br /&gt;System.out.println("Server started " + ss);&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Socket s = ss.accept();&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("Connection accepted " + s);&lt;br /&gt;&lt;br /&gt;BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));&lt;br /&gt;&lt;br /&gt;// output is flushed by printwriter&lt;br /&gt;&lt;br /&gt;PrintWriter pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream()),true);&lt;br /&gt;&lt;br /&gt;while(true)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;String str = br.readLine();&lt;br /&gt;&lt;br /&gt;if(str.equals("End"))&lt;br /&gt;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;System.out.println("Echoing : " + str);&lt;br /&gt;&lt;br /&gt;pw.println(str);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;finally&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("closing ...");&lt;br /&gt;&lt;br /&gt;s.close();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;finally&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;ss.close();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.net.*;&lt;br /&gt;&lt;br /&gt;class client&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static DatagramSocket ds;&lt;br /&gt;&lt;br /&gt;public static byte buffer[] = new byte[1024];&lt;br /&gt;&lt;br /&gt;public static void main(String arg[]) throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;ds = new DatagramSocket(6);&lt;br /&gt;&lt;br /&gt;while(true)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;String a;&lt;br /&gt;&lt;br /&gt;DatagramPacket p = new DatagramPacket(buffer,buffer.length);&lt;br /&gt;&lt;br /&gt;ds.receive(p);&lt;br /&gt;&lt;br /&gt;a=new String(p.getData(),p.getLength(),1);&lt;br /&gt;&lt;br /&gt;if (a.equals("q"))&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("Server response is shut off now");&lt;br /&gt;&lt;br /&gt;return;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;System.out.println(new String(p.getData(),0,p.getLength()));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.net.*;&lt;br /&gt;&lt;br /&gt;class dataclient&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static DatagramSocket ds;&lt;br /&gt;&lt;br /&gt;public static byte buffer[] = new byte[1024];&lt;br /&gt;&lt;br /&gt;public static void main(String args[]) throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;ds = new DatagramSocket(1999);&lt;br /&gt;&lt;br /&gt;while(true)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;DatagramPacket p = new DatagramPacket(buffer,buffer.length);&lt;br /&gt;&lt;br /&gt;ds.receive(p);&lt;br /&gt;&lt;br /&gt;System.out.println(new String(p.getData(),0,p.getLength()));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.net.*;&lt;br /&gt;&lt;br /&gt;class dataserver&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static int serverport = 1666;&lt;br /&gt;&lt;br /&gt;public static int clientport = 1999;&lt;br /&gt;&lt;br /&gt;public static DatagramSocket ds;&lt;br /&gt;&lt;br /&gt;public static byte buffer[] = new byte[1024];&lt;br /&gt;&lt;br /&gt;public static void server() throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int pos=0;&lt;br /&gt;&lt;br /&gt;while(true)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int c = System.in.read();&lt;br /&gt;&lt;br /&gt;switch(c)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;case -1:&lt;br /&gt;&lt;br /&gt;System.out.println("Server quits");&lt;br /&gt;&lt;br /&gt;return;&lt;br /&gt;&lt;br /&gt;case '\r':&lt;br /&gt;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case '\n':&lt;br /&gt;&lt;br /&gt;ds.send(new DatagramPacket(buffer,pos,InetAddress.getLocalHost(),clientport));&lt;br /&gt;&lt;br /&gt;pos=0;&lt;br /&gt;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;default:&lt;br /&gt;&lt;br /&gt;buffer[pos++] = (byte) c;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void client() throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;while(true)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;DatagramPacket p = new DatagramPacket(buffer,buffer.length);&lt;br /&gt;&lt;br /&gt;ds.receive(p);&lt;br /&gt;&lt;br /&gt;System.out.println(new String(p.getData(),0,p.getLength()));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void main(String args[]) throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;if(args.length ==1)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;ds = new DatagramSocket(serverport);&lt;br /&gt;&lt;br /&gt;server();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;else&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;ds = new DatagramSocket(clientport);&lt;br /&gt;&lt;br /&gt;client();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.net.*;&lt;br /&gt;&lt;br /&gt;class inet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String arg[]) throws UnknownHostException,MalformedURLException&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;InetAddress b = InetAddress.getLocalHost();&lt;br /&gt;&lt;br /&gt;System.out.println(b);&lt;br /&gt;&lt;br /&gt;String s = b.getHostAddress();&lt;br /&gt;&lt;br /&gt;System.out.println(s);&lt;br /&gt;&lt;br /&gt;InetAddress c = InetAddress.getByName(arg[0]);&lt;br /&gt;&lt;br /&gt;System.out.println(c);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;URL u = new URL("file:/j:/j002");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;import java.net.*;&lt;br /&gt;&lt;br /&gt;class server&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static DatagramSocket ds;&lt;br /&gt;&lt;br /&gt;public static byte buffer[] = new byte[1024];&lt;br /&gt;&lt;br /&gt;public static void main(String a[]) throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;InetAddress ia = InetAddress.getByName("tmproj13");&lt;br /&gt;&lt;br /&gt;System.out.print("Connect to ");&lt;br /&gt;&lt;br /&gt;System.out.println(ia);&lt;br /&gt;&lt;br /&gt;ds = new DatagramSocket(123);&lt;br /&gt;&lt;br /&gt;int pos=0;&lt;br /&gt;&lt;br /&gt;while(true)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int c = System.in.read();&lt;br /&gt;&lt;br /&gt;switch(c)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;case 'q':&lt;br /&gt;&lt;br /&gt;System.out.println("Server quits");&lt;br /&gt;&lt;br /&gt;return;&lt;br /&gt;&lt;br /&gt;case '\r':&lt;br /&gt;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case '\n':&lt;br /&gt;&lt;br /&gt;DatagramPacket dp = new DatagramPacket(buffer,pos,ia,456);&lt;br /&gt;&lt;br /&gt;ds.send(dp);&lt;br /&gt;&lt;br /&gt;pos=0;&lt;br /&gt;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;default:&lt;br /&gt;&lt;br /&gt;buffer[pos++] = (byte) c;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// a simple client that sends lines to server and reads lines from server&lt;br /&gt;&lt;br /&gt;import java.net.*;&lt;br /&gt;&lt;br /&gt;import java.io.* ;&lt;br /&gt;&lt;br /&gt;public class tcpclient&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String arg[]) throws IOException&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;InetAddress addr = InetAddress.getByName(null);&lt;br /&gt;&lt;br /&gt;// instead of null you can use localhost&lt;br /&gt;&lt;br /&gt;System.out.println("addr = " + addr);&lt;br /&gt;&lt;br /&gt;Socket s = new Socket(addr,tcpserver.port);&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("Socket = " + s);&lt;br /&gt;&lt;br /&gt;BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));&lt;br /&gt;&lt;br /&gt;PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(s.getOutputStream())),true);&lt;br /&gt;&lt;br /&gt;for(int i =0;i&lt;10;i++)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;out.println("howdy " + i);&lt;br /&gt;&lt;br /&gt;String str = in.readLine();&lt;br /&gt;&lt;br /&gt;System.out.println(str);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;out.println("End");&lt;br /&gt;&lt;br /&gt;} finally{&lt;br /&gt;&lt;br /&gt;System.out.println("closing...");&lt;br /&gt;&lt;br /&gt;s.close();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.io.* ;&lt;br /&gt;&lt;br /&gt;import java.net.* ;&lt;br /&gt;&lt;br /&gt;public class tcpserver&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static final int port=8080;&lt;br /&gt;&lt;br /&gt;public static void main(String arg[]) throws IOException&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;ServerSocket ss = new ServerSocket(port);&lt;br /&gt;&lt;br /&gt;Socket s ;&lt;br /&gt;&lt;br /&gt;System.out.println("Server started " + ss);&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;&lt;br /&gt;s = ss.accept();&lt;br /&gt;&lt;br /&gt;System.out.println("Connection accepted " + s);&lt;br /&gt;&lt;br /&gt;BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));&lt;br /&gt;&lt;br /&gt;// output is flushed by printwriter&lt;br /&gt;&lt;br /&gt;PrintWriter pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream()),true);&lt;br /&gt;&lt;br /&gt;while(true)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;String str = br.readLine();&lt;br /&gt;&lt;br /&gt;if(str.equals("stop"))&lt;br /&gt;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;System.out.println("Echoing : " + str);&lt;br /&gt;&lt;br /&gt;pw.println(str);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}finally {&lt;br /&gt;&lt;br /&gt;System.out.println("closing ...");&lt;br /&gt;&lt;br /&gt;s.close();&lt;br /&gt;&lt;br /&gt;ss.close();&lt;br /&gt;&lt;br /&gt;}}}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.net.*;&lt;br /&gt;&lt;br /&gt;class udpclient&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static int serverport = 666;&lt;br /&gt;&lt;br /&gt;public static int clientport = 999;&lt;br /&gt;&lt;br /&gt;public static DatagramSocket ds;&lt;br /&gt;&lt;br /&gt;public static byte buffer[] = new byte[1024];&lt;br /&gt;&lt;br /&gt;public static void client() throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;while(true)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;DatagramPacket p = new DatagramPacket(buffer,buffer.length);&lt;br /&gt;&lt;br /&gt;ds.receive(p);&lt;br /&gt;&lt;br /&gt;System.out.print(new String(p.getData(),0,p.getLength()));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void main(String args[]) throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;ds = new DatagramSocket(clientport);&lt;br /&gt;&lt;br /&gt;client();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;import java.net.*;&lt;br /&gt;&lt;br /&gt;class udpserver&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static int serverport = 666;&lt;br /&gt;&lt;br /&gt;public static int clientport = 999;&lt;br /&gt;&lt;br /&gt;public static DatagramSocket ds;&lt;br /&gt;&lt;br /&gt;public static byte buffer[] = new byte[1024];&lt;br /&gt;&lt;br /&gt;public static void server() throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int pos=0;&lt;br /&gt;&lt;br /&gt;while(true)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;InetAddress ia = InetAddress.getByName("rad-tm-17");&lt;br /&gt;&lt;br /&gt;int c = System.in.read();&lt;br /&gt;&lt;br /&gt;ds.send(new DatagramPacket(buffer,pos,ia,clientport));&lt;br /&gt;&lt;br /&gt;pos=0;&lt;br /&gt;&lt;br /&gt;buffer[pos++] = (byte) c;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void main(String args[]) throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;ds = new DatagramSocket(serverport);&lt;br /&gt;&lt;br /&gt;server();&lt;br /&gt;&lt;br /&gt;}}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-4411688754193299275?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/4411688754193299275/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=4411688754193299275' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/4411688754193299275'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/4411688754193299275'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/01/java-example-event-programming_2648.html' title='Java Example Event Programming'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-1083278803242617426</id><published>2008-01-06T23:46:00.002-08:00</published><updated>2008-01-06T23:51:50.952-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example Event Programming-9'/><title type='text'>Java Example Event Programming</title><content type='html'>&lt;strong&gt;&lt;span style="font-size:130%;color:#660000;"&gt;JDBC Program&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;import java.sql.*;&lt;br /&gt;import java.sql.Types.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;import java.io.*;&lt;br /&gt;class callstatapp&lt;br /&gt;{&lt;br /&gt;public static final int VARCHAR=2;&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;String st;&lt;br /&gt;BufferedReader br=new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;String url="jdbc:odbc:odbcoracle";&lt;br /&gt;Connection con=DriverManager.getConnection(url,"palani","kumar");&lt;br /&gt;CallableStatement cst;&lt;br /&gt;cst=con.prepareCall("?=call fun");&lt;br /&gt;con.close();&lt;br /&gt;cst.registerOutParameter(1,VARCHAR);&lt;br /&gt;st=cst.getString(1);&lt;br /&gt;System.out.println("The result is "+st);&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;System.out.println(ex);&lt;br /&gt;System.exit(0);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.sql.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;class connecapp&lt;br /&gt;{&lt;br /&gt;public static void main(String sarg[])&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;String url="jdbc:odbc:odbcoracle";&lt;br /&gt;Connection con=DriverManager.getConnection(url);&lt;br /&gt;DatabaseMetaData meta=con.getMetaData();&lt;br /&gt;System.out.println("database : "+meta.getDatabaseProductName());&lt;br /&gt;System.out.println("version : "+meta.getDatabaseProductVersion());&lt;br /&gt;System.out.println("username : "+meta.getUserName());&lt;br /&gt;con.close();&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;System.out.println(ex);&lt;br /&gt;System.exit(0);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.sql.*;&lt;br /&gt;class dbcon&lt;br /&gt;{&lt;br /&gt;static Connection con;&lt;br /&gt;public static void main(String a[ ]) throws Exception&lt;br /&gt;{&lt;br /&gt;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;con = DriverManager.getConnection("jdbc:odbc:empdsn","palani","kumar");&lt;br /&gt;System.out.println("Connected to database");&lt;br /&gt;Statement s = con.createStatement();&lt;br /&gt;int rows = s.executeUpdate("Insert into emp values(110,'murali1',19000)");&lt;br /&gt;System.out.println(rows + " rows inserted");&lt;br /&gt;rows = s.executeUpdate("Update emp set salary=1200 where empid=120");&lt;br /&gt;System.out.println(rows + " rows updated");&lt;br /&gt;s.close();&lt;br /&gt;con.close();&lt;br /&gt;}&lt;br /&gt;catch(SQLException e)&lt;br /&gt;{&lt;br /&gt;System.out.println("not Connected to database"+ e);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.sql.*;&lt;br /&gt;class dbcon1&lt;br /&gt;{&lt;br /&gt;static Connection con;&lt;br /&gt;public static void main(String a[ ]) throws Exception&lt;br /&gt;{&lt;br /&gt;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;con = DriverManager.getConnection("jdbc:odbc:odbcoracle","palani","kumar");&lt;br /&gt;System.out.println("Connected to database");&lt;br /&gt;Statement s = con.createStatement();&lt;br /&gt;int rows = s.executeUpdate("create table runtt (sno number, sname varchar2(20))");&lt;br /&gt;System.out.println(rows + " table created");&lt;br /&gt;s.close();&lt;br /&gt;con.close();&lt;br /&gt;}&lt;br /&gt;catch(SQLException e)&lt;br /&gt;{&lt;br /&gt;System.out.println("not Connected to database"+ e);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.sql.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;class driverapp&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;Enumeration drivers=DriverManager.getDrivers();&lt;br /&gt;System.out.println("The list of drivers in the system");&lt;br /&gt;while(drivers.hasMoreElements())&lt;br /&gt;{&lt;br /&gt;Driver driver=(Driver)drivers.nextElement();&lt;br /&gt;System.out.println("Driver: "+driver.getClass().getName());&lt;br /&gt;System.out.println("Major version: "+driver.getMajorVersion());&lt;br /&gt;System.out.println("Minor version: "+driver.getMinorVersion());&lt;br /&gt;System.out.println("JDBC complaint: "+driver.jdbcCompliant());&lt;br /&gt;DriverPropertyInfo props[]=driver.getPropertyInfo(" ",null);&lt;br /&gt;if(props!=null)&lt;br /&gt;{&lt;br /&gt;System.out.println("The list of properties");&lt;br /&gt;for(int i=0;i less than props.length;i++)&lt;br /&gt;{&lt;br /&gt;System.out.println(" Name : "+props[i].name);&lt;br /&gt;System.out.println(" Description : "+props[i].description);&lt;br /&gt;System.out.println(" value : "+props[i].value);&lt;br /&gt;if(props[i].choices!=null)&lt;br /&gt;{&lt;br /&gt;System.out.println("The list of choices");&lt;br /&gt;for(int j=0;i less than props[i].choices.length;j++)&lt;br /&gt;System.out.println(" "+props[i].choices[j]);&lt;br /&gt;}&lt;br /&gt;System.out.println("requires :"+props[i].required);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;System.out.println(ex);&lt;br /&gt;System.exit(0);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.sql.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;import java.io.*;&lt;br /&gt;class prestat&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;int i=1;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;String no;&lt;br /&gt;BufferedReader br=new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;String url="jdbc:odbc:odbcoracle";&lt;br /&gt;Connection con=DriverManager.getConnection(url,"palani","kumar");&lt;br /&gt;PreparedStatement pst;&lt;br /&gt;ResultSet rs;&lt;br /&gt;boolean hasResults;&lt;br /&gt;while(i&lt;=2)&lt;br /&gt;{&lt;br /&gt;pst=con.prepareStatement("insert into tt values(?)");&lt;br /&gt;System.out.println("\n Enter the employee no needed");&lt;br /&gt;no=br.readLine();&lt;br /&gt;System.out.println("\n The employee number chosen is "+no);&lt;br /&gt;pst.setString(1,no);&lt;br /&gt;hasResults=pst.execute();&lt;br /&gt;if(hasResults)&lt;br /&gt;{&lt;br /&gt;rs=pst.getResultSet();&lt;br /&gt;if(rs!=null)&lt;br /&gt;disp(rs);&lt;br /&gt;hasResults=false;&lt;br /&gt;}&lt;br /&gt;i=i+1;&lt;br /&gt;}&lt;br /&gt;con.close();&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;System.out.println(ex);&lt;br /&gt;System.exit(0);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;static void disp(ResultSet r) throws SQLException&lt;br /&gt;{&lt;br /&gt;System.out.print(r.getString(1));&lt;br /&gt;boolean m =r.next();&lt;br /&gt;System.out.print(r.getString(1));        &lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.sql.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;import java.io.*;&lt;br /&gt;class prestatapp&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;int i=1;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;String no;&lt;br /&gt;BufferedReader br=new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;String url="jdbc:odbc:odbcoracle";&lt;br /&gt;Connection con=DriverManager.getConnection(url,"palani","kumar");&lt;br /&gt;PreparedStatement pst;&lt;br /&gt;ResultSet rs;&lt;br /&gt;boolean hasResults;&lt;br /&gt;while(i&lt;=3)&lt;br /&gt;{&lt;br /&gt;pst=con.prepareStatement("insert into tt values(?)");&lt;br /&gt;System.out.println("\n Enter the employee no needed");&lt;br /&gt;no=br.readLine();&lt;br /&gt;System.out.println("\n The employee number chosen is "+no);&lt;br /&gt;pst.setString(1,no);&lt;br /&gt;hasResults=pst.execute();&lt;br /&gt;if(hasResults)&lt;br /&gt;{&lt;br /&gt;rs=pst.getResultSet();&lt;br /&gt;if(rs!=null)&lt;br /&gt;disp(rs);&lt;br /&gt;hasResults=false;&lt;br /&gt;}&lt;br /&gt;i=i+1;&lt;br /&gt;}&lt;br /&gt;con.close();&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;System.out.println(ex);&lt;br /&gt;System.exit(0);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;static void disp(ResultSet r) throws SQLException&lt;br /&gt;{&lt;br /&gt;ResultSetMetaData rmeta=r.getMetaData();&lt;br /&gt;int numcol=rmeta.getColumnCount();&lt;br /&gt;for(int i=1;i less than numcol;++i)&lt;br /&gt;System.out.print(rmeta.getColumnName(i));&lt;br /&gt;while(r.next())&lt;br /&gt;{&lt;br /&gt;for(int i=1;i less than numcol;++i)&lt;br /&gt;System.out.print(r.getString(i));&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.sql.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;class resulapp&lt;br /&gt;{&lt;br /&gt;public static void main(String sarg[])&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;String url="jdbc:odbc:odbcoracle";&lt;br /&gt;Connection con=DriverManager.getConnection(url,"palani","kumar");&lt;br /&gt;Statement st=con.createStatement();&lt;br /&gt;String sql="select * from emp";&lt;br /&gt;ResultSet rs=st.executeQuery(sql);&lt;br /&gt;disp(rs);&lt;br /&gt;con.close();&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;System.out.println(ex);&lt;br /&gt;System.exit(0);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;static void disp(ResultSet r) throws SQLException&lt;br /&gt;{&lt;br /&gt;ResultSetMetaData rmeta=r.getMetaData();&lt;br /&gt;int numcol=rmeta.getColumnCount();&lt;br /&gt;for(int i=1;i&lt;=numcol;++i)&lt;br /&gt;System.out.print(rmeta.getColumnName(i)+"\t");&lt;br /&gt;Sytem.out.print("\n");&lt;br /&gt;while(r.next())&lt;br /&gt;{&lt;br /&gt;for(int i=1;i&lt;=numcol;++i)&lt;br /&gt;System.out.print(r.getString(i)+ "\t" );&lt;br /&gt;System.out.print("\n");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.sql.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;class statapp&lt;br /&gt;{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;String url="jdbc:odbc:odbcoracle";&lt;br /&gt;Connection con=DriverManager.getConnection(url,"palani","kumar");&lt;br /&gt;Statement st=con.createStatement();&lt;br /&gt;String sql=args[0];&lt;br /&gt;System.out.println(sql);&lt;br /&gt;boolean hasResults=st.execute(sql);&lt;br /&gt;if(hasResults)&lt;br /&gt;{&lt;br /&gt;ResultSet rs=st.getResultSet();&lt;br /&gt;if(rs!=null)&lt;br /&gt;disp(rs);&lt;br /&gt;}&lt;br /&gt;con.close();&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;System.out.println(ex);&lt;br /&gt;System.exit(0);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;static void disp(ResultSet r) throws SQLException&lt;br /&gt;{&lt;br /&gt;ResultSetMetaData rmeta=r.getMetaData();&lt;br /&gt;int numcol=rmeta.getColumnCount();&lt;br /&gt;for(int i=1;iless than numcol;++i)&lt;br /&gt;System.out.print(rmeta.getColumnName(i));&lt;br /&gt;while(r.next())&lt;br /&gt;{&lt;br /&gt;for(int i=1;i less than numcol;++i)&lt;br /&gt;System.out.print(r.getString(i));&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;import java.sql.*;&lt;br /&gt;/* Table emp in oracle user palani columns eno ename sal */&lt;br /&gt;class fram extends JFrame implements ActionListener&lt;br /&gt;{&lt;br /&gt;TextField txteno, txtename, txtsal ;&lt;br /&gt;JLabel lbleno, lblename, lblsal, lblstat ;&lt;br /&gt;Container cp;&lt;br /&gt;Connection con;&lt;br /&gt;Statement st;&lt;br /&gt;JButton butinsert;&lt;br /&gt;fram()&lt;br /&gt;{&lt;br /&gt;txteno = new TextField(12);&lt;br /&gt;txtename = new TextField(12);&lt;br /&gt;txtsal = new TextField(12);&lt;br /&gt;lbleno = new JLabel("Empno ");&lt;br /&gt;lblename= new JLabel("Ename ");&lt;br /&gt;lblsal = new JLabel("salary");&lt;br /&gt;lblstat = new JLabel("");&lt;br /&gt;butinsert = new JButton("Insert");&lt;br /&gt;cp = this.getContentPane();&lt;br /&gt;cp.setLayout(new FlowLayout());&lt;br /&gt;cp.add(lbleno);&lt;br /&gt;cp.add(txteno);&lt;br /&gt;cp.add(lblename);&lt;br /&gt;cp.add(txtename);&lt;br /&gt;cp.add(lblsal);&lt;br /&gt;cp.add(txtsal);&lt;br /&gt;cp.add(butinsert);&lt;br /&gt;cp.add(lblstat);&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;String url="jdbc:odbc:odbcoracle";&lt;br /&gt;con=DriverManager.getConnection(url,"palani","kumar");&lt;br /&gt;lblstat.setText("successfully connected");&lt;br /&gt;st=con.createStatement();&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;System.out.println("Cannot connect " + ex);&lt;br /&gt;}&lt;br /&gt;butinsert.addActionListener(this);&lt;br /&gt;addWindowListener(new w(this));&lt;br /&gt;}&lt;br /&gt;class w extends WindowAdapter&lt;br /&gt;{&lt;br /&gt;fram f1;&lt;br /&gt;w(fram f2)&lt;br /&gt;{&lt;br /&gt;f1 = f2;&lt;br /&gt;}&lt;br /&gt;public void windowClosing(WindowEvent we)&lt;br /&gt;{&lt;br /&gt;f1.setVisible(false);&lt;br /&gt;f2.dispose();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;public void actionPerformed(ActionEvent e)&lt;br /&gt;{&lt;br /&gt;if(e.getSource() == butinsert)&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;int rows = st.executeUpdate("insert into emp values(121,'melvin',5500)");&lt;br /&gt;lblstat.setText(rows+ "inserted");&lt;br /&gt;} catch(SQLException se) { }&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;class swodbc&lt;br /&gt;{&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;{&lt;br /&gt;fram f = new fram();&lt;br /&gt;f.setVisible(true);&lt;br /&gt;f.setSize(400,400);&lt;br /&gt;f.setLocation(200,200);&lt;br /&gt;}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-1083278803242617426?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/1083278803242617426/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=1083278803242617426' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1083278803242617426'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1083278803242617426'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/01/java-example-event-programming_8008.html' title='Java Example Event Programming'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-3797905360795666004</id><published>2008-01-06T23:46:00.001-08:00</published><updated>2008-01-06T23:46:49.611-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example Event Programming-8'/><title type='text'>Java Example Event Programming</title><content type='html'>&lt;strong&gt;&lt;span style="font-size:130%;color:#660000;"&gt;Infterface Program&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;interface callback&lt;br /&gt;{&lt;br /&gt;void callback(int param);&lt;br /&gt;}    &lt;br /&gt;class imp2 implements callback&lt;br /&gt;{&lt;br /&gt;public void callback(int p)&lt;br /&gt;{&lt;br /&gt;System.out.println("callback called with " + p);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;class imp1&lt;br /&gt;{&lt;br /&gt;public static void main(String a[])&lt;br /&gt;{&lt;br /&gt;callback c = new imp2();&lt;br /&gt;c.callback(42);&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;class imp3 implements callback&lt;br /&gt;{&lt;br /&gt;public void callback(int t)&lt;br /&gt;{&lt;br /&gt;System.out.println("Interface");&lt;br /&gt;}&lt;br /&gt;public static void main(String a[])&lt;br /&gt;{&lt;br /&gt;imp3 i = new imp3();&lt;br /&gt;i.callback(6);&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;class int1 implements inter&lt;br /&gt;{&lt;br /&gt;public void m()&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;public interface inter&lt;br /&gt;{&lt;br /&gt;public void m();&lt;br /&gt;}    &lt;br /&gt;import java.io.*;&lt;br /&gt;class read&lt;br /&gt;{&lt;br /&gt;public static void main(String a[]) throws IOException&lt;br /&gt;{&lt;br /&gt;char c;&lt;br /&gt;InputStreamReader i = new InputStreamReader(System.in);&lt;br /&gt;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;c = (char) br.read();&lt;br /&gt;System.out.println(c);&lt;br /&gt;c = (char) i.read();&lt;br /&gt;System.out.println(c);&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.io.*;&lt;br /&gt;class read1&lt;br /&gt;{&lt;br /&gt;public static void main(String a[]) throws IOException&lt;br /&gt;{&lt;br /&gt;char c;&lt;br /&gt;String s;&lt;br /&gt;InputStreamReader i = new InputStreamReader(System.in);&lt;br /&gt;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;System.out.println("press chars");&lt;br /&gt;do&lt;br /&gt;{&lt;br /&gt;s = br.readLine();&lt;br /&gt;System.out.println(s);&lt;br /&gt;}while(!s.equals("stop"));&lt;br /&gt;System.out.println("press chars");&lt;br /&gt;do&lt;br /&gt;{&lt;br /&gt;// s = i.readLine();&lt;br /&gt;System.out.println(s);&lt;br /&gt;} while(!s.equals("stop"));&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.io.*;&lt;br /&gt;class fileread&lt;br /&gt;{&lt;br /&gt;public static void main(String a[]) throws IOException&lt;br /&gt;{&lt;br /&gt;int i;&lt;br /&gt;FileInputStream fin;&lt;br /&gt;try{&lt;br /&gt;fin = new FileInputStream(a[0]);&lt;br /&gt;}&lt;br /&gt;catch(FileNotFoundException e)&lt;br /&gt;{&lt;br /&gt;System.out.println("File not found");&lt;br /&gt;return ;&lt;br /&gt;}&lt;br /&gt;do&lt;br /&gt;{&lt;br /&gt;i = fin.read();&lt;br /&gt;if(i != -1)&lt;br /&gt;System.out.print((char) i);&lt;br /&gt;}&lt;br /&gt;while(i!= -1);&lt;br /&gt;fin.close();&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.io.*;&lt;br /&gt;class files&lt;br /&gt;{&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;{&lt;br /&gt;File f = new File ("c.c");&lt;br /&gt;System.out.println("File Name : " + f.getName());&lt;br /&gt;System.out.println(f.getPath());&lt;br /&gt;System.out.println(f.getAbsolutePath());&lt;br /&gt;String s;&lt;br /&gt;s = (f.canRead()? "is readable" : "is writable");&lt;br /&gt;System.out.println(s);&lt;br /&gt;s = (f.isDirectory()? "dir" : "not dir");&lt;br /&gt;System.out.println(s);&lt;br /&gt;s = (f.isFile()? "file" : "not file");&lt;br /&gt;System.out.println(s);&lt;br /&gt;boolean b = f.delete();&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.io.*;&lt;br /&gt;class filewrite&lt;br /&gt;{&lt;br /&gt;public static void main(String a[]) throws IOException,FileNotFoundException&lt;br /&gt;{&lt;br /&gt;FileOutputStream fin = new FileOutputStream(a[0]);&lt;br /&gt;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;// int i = br.read();&lt;br /&gt;String str = br.readLine();&lt;br /&gt;byte[] b = str.getBytes();&lt;br /&gt;fin.write(b);&lt;br /&gt;System.out.print("Stored in the file");&lt;br /&gt;fin.close();&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.io.*;&lt;br /&gt;class filewrite&lt;br /&gt;{&lt;br /&gt;public static void main(String a[]) throws IOException,FileNotFoundException&lt;br /&gt;{&lt;br /&gt;FileOutputStream fin = new FileOutputStream(a[0]);&lt;br /&gt;BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;InputStreamReader br2 = new InputStreamReader(System.in));&lt;br /&gt;// int i = br.read();&lt;br /&gt;byte b = br.read();&lt;br /&gt;byte b1 = br2.read();&lt;br /&gt;String str = br.readLine();&lt;br /&gt;// byte[] b = str.getBytes();&lt;br /&gt;fin.write(b);&lt;br /&gt;System.out.print("Stored in the file");&lt;br /&gt;fin.close();&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.io.*;&lt;br /&gt;class in&lt;br /&gt;{&lt;br /&gt;public static void main(String arg[]) throws Exception&lt;br /&gt;{&lt;br /&gt;System.out.println("enter a number");&lt;br /&gt;char c =(char) System.in.read();&lt;br /&gt;System.out.println(c);&lt;br /&gt;}&lt;br /&gt;}                        &lt;br /&gt;import java.io.*;&lt;br /&gt;class pw&lt;br /&gt;{&lt;br /&gt;public static void main(String a[])&lt;br /&gt;{&lt;br /&gt;PrintWriter pw = new PrintWriter(System.out,true);&lt;br /&gt;pw.print("this is the string");&lt;br /&gt;int i=9;&lt;br /&gt;pw.println(i);&lt;br /&gt;double d=34.34;&lt;br /&gt;pw.println(d);&lt;br /&gt;System.out.write('e');&lt;br /&gt;// System.out.write('lle');&lt;br /&gt;System.out.write('\n');&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.io.*;&lt;br /&gt;class read&lt;br /&gt;{&lt;br /&gt;public static void main(String a[]) throws IOException,FileNotFoundException&lt;br /&gt;{&lt;br /&gt;int i;&lt;br /&gt;FileInputStream fin = new FileInputStream(a[0]);&lt;br /&gt;do&lt;br /&gt;{&lt;br /&gt;i = fin.read();&lt;br /&gt;if(i != -1)&lt;br /&gt;System.out.print((char) i);&lt;br /&gt;}&lt;br /&gt;while(i!= -1);&lt;br /&gt;fin.close();&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.io.*;&lt;br /&gt;class reader&lt;br /&gt;{&lt;br /&gt;public static void main(String a[]) throws IOException&lt;br /&gt;{&lt;br /&gt;char c;&lt;br /&gt;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;System.out.println("enter characters . q to quit");&lt;br /&gt;do&lt;br /&gt;{&lt;br /&gt;c = (char) br.read();&lt;br /&gt;System.out.println(c);&lt;br /&gt;}while(c!= 'q');&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;import java.io.*;&lt;br /&gt;class reader1&lt;br /&gt;{&lt;br /&gt;public static void main(String a[]) throws IOException&lt;br /&gt;{&lt;br /&gt;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;String str;&lt;br /&gt;System.out.println("Enter 'stop' to quit");&lt;br /&gt;do&lt;br /&gt;{&lt;br /&gt;str = br.readLine();&lt;br /&gt;System.out.println(str);&lt;br /&gt;}while(!str.equals("stop"));&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;class str&lt;br /&gt;{&lt;br /&gt;public static void main(String a[])&lt;br /&gt;{&lt;br /&gt;StringBuffer s1 = new StringBuffer();&lt;br /&gt;StringBuffer s2 = new StringBuffer(12);&lt;br /&gt;StringBuffer s3 = new StringBuffer("palani");&lt;br /&gt;System.out.println(s1.length() +" "+ s2.length() +" " + s3.length());&lt;br /&gt;String s4 ="kumar" ;&lt;br /&gt;String s5 = s4;&lt;br /&gt;s2.append("Radiant");&lt;br /&gt;System.out.println(s4.toUpperCase());&lt;br /&gt;System.out.println(s1.length() +" "+ s2.length() +" " + s3.length());&lt;br /&gt;System.out.println("substring " + s3.substring(3,3));&lt;br /&gt;s3.append("kumar");&lt;br /&gt;System.out.println(s3);&lt;br /&gt;System.out.println(s2.reverse());&lt;br /&gt;System.out.println(s2.delete(2,2));&lt;br /&gt;}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-3797905360795666004?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/3797905360795666004/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=3797905360795666004' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3797905360795666004'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3797905360795666004'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/01/java-example-event-programming_3822.html' title='Java Example Event Programming'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-5484253335106011187</id><published>2008-01-06T23:43:00.001-08:00</published><updated>2008-01-06T23:45:18.103-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example Event Programming-7'/><title type='text'>Java Example Event Programming</title><content type='html'>&lt;strong&gt;&lt;em&gt;&lt;span style="font-size:130%;color:#660000;"&gt;Inh Program&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class aa&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public int a = 11;&lt;br /&gt;&lt;br /&gt;private int b = 22;&lt;br /&gt;&lt;br /&gt;int c = 33;&lt;br /&gt;&lt;br /&gt;protected int d =44;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class bb extends aa&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void disp()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println(a);&lt;br /&gt;// System.out.println(b);&lt;br /&gt;&lt;br /&gt;System.out.println(c);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;System.out.println(d);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class access&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;bb ob = new bb();&lt;br /&gt;&lt;br /&gt;ob.disp();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;class a&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;a()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("A 's constructor");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void m()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("a 's method");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class b extends a&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;b()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;super();&lt;br /&gt;&lt;br /&gt;System.out.println("B's constructor");&lt;br /&gt;&lt;br /&gt;super.m();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void a()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("overrided a");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;class inh1&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String a[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;b bb = new b();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;class over&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void m()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void m(int a)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void m(float a)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public int m(int a)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;return a;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class methover&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;over o = new o();&lt;br /&gt;&lt;br /&gt;o.m();&lt;br /&gt;o.m(4);&lt;br /&gt;&lt;br /&gt;o.m(9.4f);&lt;br /&gt;&lt;br /&gt;int d = o.m(5);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-5484253335106011187?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/5484253335106011187/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=5484253335106011187' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/5484253335106011187'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/5484253335106011187'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/01/java-example-event-programming_8666.html' title='Java Example Event Programming'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-5482451145656567289</id><published>2008-01-06T23:41:00.000-08:00</published><updated>2008-01-06T23:43:42.387-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example Event Programming-6'/><title type='text'>Java Example Event Programming</title><content type='html'>&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Exception Program &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;class myexception extends Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public String toString()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;return "Myexception caught. A should be greater than 10";&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class ex&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String arg[]) throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int a = Integer.parseInt(arg[0]);&lt;br /&gt;&lt;br /&gt;if(a&lt;10)&lt;br /&gt;&lt;br /&gt;throw new myexception();&lt;br /&gt;&lt;br /&gt;System.out.println("A is correct");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class myexception extends Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public String getMessage()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;return "Myexception caught. A should be greater than 10";&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class ex1&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String arg[]) throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int a = Integer.parseInt(arg[0]);&lt;br /&gt;&lt;br /&gt;if(a&lt;10)&lt;br /&gt;&lt;br /&gt;throw new myexception();&lt;br /&gt;&lt;br /&gt;System.out.println("A is correct");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class ex3&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String a[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int m = Integer.parseInt(a[0]);&lt;br /&gt;&lt;br /&gt;int n = Integer.parseInt(a[1]);&lt;br /&gt;&lt;br /&gt;int r = m/n;&lt;br /&gt;&lt;br /&gt;int k;&lt;br /&gt;&lt;br /&gt;System.out.println(r);&lt;br /&gt;&lt;br /&gt;// System.out.println(k);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class ex4&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String a[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int m = Integer.parseInt(a[0]);&lt;br /&gt;&lt;br /&gt;int n = Integer.parseInt(a[1]);&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int r = m/n;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;catch(ArithmeticException e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("div by zero");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;catch(Exception e)&lt;br /&gt;&lt;br /&gt;{ System.out.println("general");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;finally&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("finally");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;System.out.println("Successfull");&lt;br /&gt;&lt;br /&gt;int k;&lt;br /&gt;&lt;br /&gt;// System.out.println(r);&lt;br /&gt;&lt;br /&gt;// System.out.println(k);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class A&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;A()&lt;br /&gt;&lt;br /&gt;{ System.out.println("A 's constructor");}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class B extends A&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void A()&lt;br /&gt;&lt;br /&gt;{ System.out.println("B 's constructor");}&lt;br /&gt;&lt;br /&gt;B()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;super();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class C extends B&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;C()&lt;br /&gt;&lt;br /&gt;{ System.out.println("C 's constructor");}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class ext1&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String a[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;C cc = new C();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-5482451145656567289?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/5482451145656567289/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=5482451145656567289' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/5482451145656567289'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/5482451145656567289'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/01/java-example-event-programming_6553.html' title='Java Example Event Programming'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-1016861226963084959</id><published>2008-01-06T23:12:00.000-08:00</published><updated>2008-01-06T23:39:56.377-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example Event Programming-5'/><title type='text'>Java Example Event Programming</title><content type='html'>&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;span style="font-size:130%;"&gt;Book Program&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;class x&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int a;&lt;br /&gt;&lt;br /&gt;float f;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class y extends x&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;double c;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class clas&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;x xx = new x();&lt;br /&gt;&lt;br /&gt;y yy = new y();&lt;br /&gt;Class ob;&lt;br /&gt;&lt;br /&gt;ob = xx.getClass();&lt;br /&gt;&lt;br /&gt;System.out.println("xx is object of type : " + ob.getName());&lt;br /&gt;&lt;br /&gt;ob = yy.getClass();&lt;br /&gt;&lt;br /&gt;System.out.println("yy is object of type : " + ob.getName());&lt;br /&gt;&lt;br /&gt;ob = ob.getSuperclass();&lt;br /&gt;&lt;br /&gt;System.out.println("y's superclass is : " + ob.getName());&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;class disp&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String a[])&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;textarea name="unique_name" rows="3" cols="30"&gt;{ System.out.println(a.length); for(int&lt;br /&gt;i=0; i&lt;a.length;i++&gt;){&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;System.out.println(a[i]);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;class init&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String[] arg)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int k;&lt;br /&gt;&lt;br /&gt;int n=!1;&lt;br /&gt;&lt;br /&gt;System.out.println(n);&lt;br /&gt;System.out.println(arg[0]);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;class out&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int i=20;&lt;br /&gt;private int j=30;&lt;br /&gt;&lt;br /&gt;public int k =40;&lt;br /&gt;&lt;br /&gt;protected int l=50;&lt;br /&gt;&lt;br /&gt;public void m()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;in inn = new in();&lt;br /&gt;&lt;br /&gt;inn.inmethod();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mpu()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("Pub");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mpr()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;System.out.println("Pri");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void mde()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("default");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class in&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int j=10;&lt;br /&gt;&lt;br /&gt;public void inmethod()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("Inner method" + (i+j+k+l));&lt;br /&gt;&lt;br /&gt;mpr();&lt;br /&gt;&lt;br /&gt;mpu();&lt;br /&gt;&lt;br /&gt;mde();&lt;br /&gt;&lt;br /&gt;System.out.println("this j"+j);&lt;br /&gt;&lt;br /&gt;// m();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;class inner&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;out o = new out();&lt;br /&gt;&lt;br /&gt;o.m();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;class math&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;System.out.println(Math.random());&lt;br /&gt;System.out.println(Math.E);&lt;br /&gt;&lt;br /&gt;System.out.println(Math.PI);&lt;br /&gt;&lt;br /&gt;System.out.println(4^5);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;class mem&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Runtime r = Runtime.getRuntime();&lt;br /&gt;long mem1,mem2;&lt;br /&gt;&lt;br /&gt;int i;&lt;br /&gt;&lt;br /&gt;Integer in[] = new Integer[1000];&lt;br /&gt;&lt;br /&gt;System.out.println("total memory " + r.totalMemory());&lt;br /&gt;&lt;br /&gt;mem1 = r.freeMemory();&lt;br /&gt;&lt;br /&gt;System.out.println("Free memory " + mem1);&lt;br /&gt;&lt;br /&gt;r.gc();&lt;br /&gt;&lt;br /&gt;mem1 = r.freeMemory();&lt;br /&gt;&lt;br /&gt;System.out.println("Free memory after garbage " + mem1);&lt;br /&gt;&lt;br /&gt;for(i=0;i&lt;1000;i++)&lt;br /&gt;&lt;br /&gt;in[i] = new Integer(i);&lt;br /&gt;&lt;br /&gt;mem2 = r.freeMemory();&lt;br /&gt;&lt;br /&gt;System.out.println("Free memory after decl" + mem2);&lt;br /&gt;&lt;br /&gt;System.out.println("diff " + (mem1-mem2));&lt;br /&gt;&lt;br /&gt;r.gc();&lt;br /&gt;&lt;br /&gt;r.gc();&lt;br /&gt;&lt;br /&gt;r.gc();&lt;br /&gt;&lt;br /&gt;mem2 = r.freeMemory();&lt;br /&gt;&lt;br /&gt;System.out.println("Free memory after gc " + mem2);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;class meth&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void p(String s)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;System.out.println(s);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;static&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;p("hello");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;public static void main(String a[])&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;p("hi");&lt;br /&gt;&lt;br /&gt;char k='f';&lt;br /&gt;&lt;br /&gt;switch(k)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;case 'f' :&lt;br /&gt;&lt;br /&gt;p("true");&lt;br /&gt;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case 'a':&lt;br /&gt;p("false");&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;default :&lt;br /&gt;&lt;br /&gt;p("default");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;public class priclass&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String a[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;a ob1 = new a();&lt;br /&gt;&lt;br /&gt;b ob2 = new b();&lt;br /&gt;&lt;br /&gt;c ob3 = new c();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected class a&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public int k=33;&lt;br /&gt;}&lt;br /&gt;class b&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public int j=23;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class c&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public int i=24;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class quest&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int i=7,j=8;&lt;br /&gt;&lt;br /&gt;int n=(ij) % (i &amp;amp; j) ;&lt;br /&gt;&lt;br /&gt;System.out.println(n);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;/* static class s&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("hi");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;static class statclass&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;s ss = new s();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.util.*;&lt;br /&gt;&lt;br /&gt;class test19&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String g[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Vector v = new Vector();&lt;br /&gt;&lt;br /&gt;v.add("Radiant");&lt;br /&gt;&lt;br /&gt;v.add("Software");&lt;br /&gt;&lt;br /&gt;System.out.println(v.elementAt(0) + v.elementAt(1));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-1016861226963084959?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/1016861226963084959/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=1016861226963084959' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1016861226963084959'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1016861226963084959'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/01/java-example-event-programming_6266.html' title='Java Example Event Programming'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-7537415932186716321</id><published>2008-01-06T22:21:00.000-08:00</published><updated>2008-01-06T22:28:45.001-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example Event Programming-3'/><title type='text'>Java Example Event Programming</title><content type='html'>&lt;strong&gt;&lt;em&gt;&lt;span style="color:#660000;"&gt;Applet Program&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class appcolor extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;setBackground(Color.yellow);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.drawString("Applet ",10,10);&lt;br /&gt;&lt;br /&gt;g.setColor(Color.red);&lt;br /&gt;&lt;br /&gt;g.drawString("This is red color",20,10);&lt;br /&gt;&lt;br /&gt;g.setColor(Color.magenta);&lt;br /&gt;g.drawString("Magenta",30,10);&lt;br /&gt;&lt;br /&gt;g.setColor(Color.blue);&lt;br /&gt;&lt;br /&gt;g.drawString("Blue",40,10);&lt;br /&gt;&lt;br /&gt;g.setColor(Color.green);&lt;br /&gt;&lt;br /&gt;g.drawString("Green",30,10);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class borderlay extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;BorderLayout f = new BorderLayout();&lt;br /&gt;&lt;br /&gt;setLayout(f);&lt;br /&gt;&lt;br /&gt;Button b1 = new Button("Left-West");&lt;br /&gt;&lt;br /&gt;Button b2 = new Button("Footer-south");&lt;br /&gt;&lt;br /&gt;Button b3 = new Button("PALANI");&lt;br /&gt;&lt;br /&gt;Button b4 = new Button("Right-East");&lt;br /&gt;Button b5 = new Button("Top-North");&lt;br /&gt;&lt;br /&gt;Button b6 = new Button("RADIANT");&lt;br /&gt;&lt;br /&gt;add(b1,BorderLayout.WEST);&lt;br /&gt;&lt;br /&gt;add(b2,BorderLayout.SOUTH);&lt;br /&gt;&lt;br /&gt;add(b3,BorderLayout.CENTER);&lt;br /&gt;&lt;br /&gt;add(b4,BorderLayout.EAST);&lt;br /&gt;&lt;br /&gt;add(b5,BorderLayout.NORTH);&lt;br /&gt;&lt;br /&gt;add(b6,BorderLayout.CENTER);&lt;br /&gt;&lt;br /&gt;TextField t = new TextField();&lt;br /&gt;&lt;br /&gt;add(t,BorderLayout.CENTER);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public Insets getInsets()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;return new Insets(10,10,10,10);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class butt extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Label one = new Label("mouse");&lt;br /&gt;&lt;br /&gt;Label two = new Label();&lt;br /&gt;Label three = new Label("HCL",Label.CENTER);&lt;br /&gt;&lt;br /&gt;add(one);&lt;br /&gt;&lt;br /&gt;add(two);&lt;br /&gt;&lt;br /&gt;add(three);&lt;br /&gt;&lt;br /&gt;two.setText("visible");&lt;br /&gt;&lt;br /&gt;add(two);&lt;br /&gt;&lt;br /&gt;Button b1 = new Button("One");&lt;br /&gt;Button b2 = new Button("Two");&lt;br /&gt;&lt;br /&gt;add(b1);&lt;br /&gt;&lt;br /&gt;add(b2);&lt;br /&gt;&lt;br /&gt;Checkbox c1 = new Checkbox("Required");&lt;br /&gt;Checkbox c2 = new Checkbox();&lt;br /&gt;&lt;br /&gt;add(c1);&lt;br /&gt;&lt;br /&gt;add(c2);&lt;br /&gt;&lt;br /&gt;CheckboxGroup cg = new CheckboxGroup();&lt;br /&gt;&lt;br /&gt;Checkbox c3 = new Checkbox("PentiumIII",true,cg);&lt;br /&gt;&lt;br /&gt;Checkbox c4 = new Checkbox("Machintosh",false,cg);&lt;br /&gt;&lt;br /&gt;Checkbox c5 = new Checkbox("487 machine",cg,false);&lt;br /&gt;&lt;br /&gt;add(c3);&lt;br /&gt;&lt;br /&gt;add(c4);&lt;br /&gt;add(c5);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;&lt;textarea name= "unique_name" rows="3" cols="30"&gt;/* &lt;Applet code=card width=300&lt;br /&gt;height=400&gt; &lt;/applet&gt; */ &lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;public class card extends Applet implements ActionListener , MouseListener&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;String s="PP";&lt;br /&gt;&lt;br /&gt;CardLayout c;&lt;br /&gt;&lt;br /&gt;Button one,two;&lt;br /&gt;&lt;br /&gt;Panel p,p1,p2;&lt;br /&gt;&lt;br /&gt;Checkbox ch,ch1,ch2,ch3;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;one = new Button("one");&lt;br /&gt;&lt;br /&gt;two = new Button("two");&lt;br /&gt;&lt;br /&gt;add(one);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;add(two);&lt;br /&gt;&lt;br /&gt;c = new CardLayout();&lt;br /&gt;&lt;br /&gt;p = new Panel();&lt;br /&gt;p.setLayout(c);&lt;br /&gt;&lt;br /&gt;ch = new Checkbox("Required");&lt;br /&gt;&lt;br /&gt;ch1 = new Checkbox("Enable");&lt;br /&gt;&lt;br /&gt;p1 = new Panel();&lt;br /&gt;&lt;br /&gt;p1.add(ch);&lt;br /&gt;&lt;br /&gt;p1.add(ch1);    &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;ch2 = new Checkbox("Required");&lt;br /&gt;ch3 = new Checkbox("Enable");&lt;br /&gt;&lt;br /&gt;p2 = new Panel();&lt;br /&gt;&lt;br /&gt;p2.add(ch2);&lt;br /&gt;&lt;br /&gt;p2.add(ch3);&lt;br /&gt;&lt;br /&gt;p.add(p1,"First pane");&lt;br /&gt;&lt;br /&gt;p.add(p2,"Second pane");&lt;br /&gt;&lt;br /&gt;add(p);&lt;br /&gt;&lt;br /&gt;one.addActionListener(this);&lt;br /&gt;&lt;br /&gt;two.addActionListener(this);&lt;br /&gt;&lt;br /&gt;addMouseListener(this);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.drawString(s,100,100);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mouseClicked(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mouseEntered(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mousePressed(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;c.next(p);&lt;br /&gt;&lt;br /&gt;s="fired";&lt;br /&gt;&lt;br /&gt;repaint();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;public void mouseExited(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mouseReleased(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void actionPerformed(ActionEvent a)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;if(a.getSource() == one)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;c.show(p,"First pane");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;else&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;c.show(p,"Second pane");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;public class cardlay extends Applet implements ActionListener , MouseListener&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;CardLayout c;&lt;br /&gt;&lt;br /&gt;Button one,two;&lt;br /&gt;&lt;br /&gt;Panel p,p1,p2;&lt;br /&gt;&lt;br /&gt;Checkbox ch,ch1,ch2,ch3;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;one = new Button("one");&lt;br /&gt;&lt;br /&gt;two = new Button("two");&lt;br /&gt;&lt;br /&gt;add(one);&lt;br /&gt;&lt;br /&gt;add(two);&lt;br /&gt;&lt;br /&gt;c = new CardLayout();&lt;br /&gt;&lt;br /&gt;p = new Panel();&lt;br /&gt;p.setLayout(c);&lt;br /&gt;&lt;br /&gt;ch = new Checkbox("Required");&lt;br /&gt;&lt;br /&gt;ch1 = new Checkbox("Enable");&lt;br /&gt;&lt;br /&gt;p1 = new Panel();&lt;br /&gt;&lt;br /&gt;p1.add(ch);&lt;br /&gt;&lt;br /&gt;p1.add(ch1);    &lt;br /&gt;ch2 = new Checkbox("Required");&lt;br /&gt;&lt;br /&gt;ch3 = new Checkbox("Enable");&lt;br /&gt;&lt;br /&gt;p2 = new Panel();&lt;br /&gt;&lt;br /&gt;p2.add(ch2);&lt;br /&gt;&lt;br /&gt;p2.add(ch3);&lt;br /&gt;&lt;br /&gt;p.add(p1,"First");&lt;br /&gt;p.add(p2,"Second");&lt;br /&gt;&lt;br /&gt;add(p);&lt;br /&gt;&lt;br /&gt;one.addActionListener(this);&lt;br /&gt;&lt;br /&gt;two.addActionListener(this);&lt;br /&gt;&lt;br /&gt;addMouseListener(this);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;public void mouseClicked(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mouseEntered(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;public void mousePressed(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;c.next(p);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mouseExited(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;public void mouseReleased(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void actionPerformed(ActionEvent a)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;if(a.getSource() == one)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;c.show(p,"First");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;else&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;c.show(p,"Second");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;public class cho extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Choice ch = new Choice();&lt;br /&gt;ch.add("One");&lt;br /&gt;&lt;br /&gt;ch.add("Two");&lt;br /&gt;&lt;br /&gt;ch.addItem("Three");&lt;br /&gt;&lt;br /&gt;ch.addItem("Four");&lt;br /&gt;&lt;br /&gt;add(ch);&lt;br /&gt;&lt;br /&gt;List l = new List();&lt;br /&gt;&lt;br /&gt;l.add("One");&lt;br /&gt;&lt;br /&gt;l.add("Two");&lt;br /&gt;&lt;br /&gt;l.addItem("Three");&lt;br /&gt;l.addItem("Four");&lt;br /&gt;&lt;br /&gt;add(l);&lt;br /&gt;&lt;br /&gt;List l1 = new List(3);&lt;br /&gt;&lt;br /&gt;l1.add("One");&lt;br /&gt;&lt;br /&gt;l1.add("Two");&lt;br /&gt;&lt;br /&gt;l1.addItem("Three");&lt;br /&gt;&lt;br /&gt;l1.addItem("Four");&lt;br /&gt;&lt;br /&gt;add(l1);&lt;br /&gt;List l2 = new List(3,true);&lt;br /&gt;&lt;br /&gt;l2.add("One");&lt;br /&gt;&lt;br /&gt;l2.add("Two");&lt;br /&gt;&lt;br /&gt;l2.addItem("Three");&lt;br /&gt;&lt;br /&gt;l2.addItem("Four");&lt;br /&gt;&lt;br /&gt;add(l2);&lt;br /&gt;&lt;br /&gt;Scrollbar s1 = new Scrollbar();&lt;br /&gt;&lt;br /&gt;Scrollbar s2 = new Scrollbar(Scrollbar.HORIZONTAL);&lt;br /&gt;Scrollbar s3 = new Scrollbar(Scrollbar.VERTICAL,10,1,1,100);&lt;br /&gt;&lt;br /&gt;add(s1);&lt;br /&gt;&lt;br /&gt;add(s2);&lt;br /&gt;&lt;br /&gt;add(s3);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;public class cho1 extends Applet&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Choice ch = new Choice();&lt;br /&gt;&lt;br /&gt;ch.add("One");&lt;br /&gt;&lt;br /&gt;ch.add("Two");&lt;br /&gt;&lt;br /&gt;ch.add("Three");&lt;br /&gt;&lt;br /&gt;ch.add("Four");&lt;br /&gt;&lt;br /&gt;add(ch);&lt;br /&gt;&lt;br /&gt;List l = new List();&lt;br /&gt;&lt;br /&gt;l.add("One");&lt;br /&gt;l.add("Two");&lt;br /&gt;&lt;br /&gt;l.add("Three");&lt;br /&gt;&lt;br /&gt;l.add("Four");&lt;br /&gt;&lt;br /&gt;add(l);&lt;br /&gt;&lt;br /&gt;List l1 = new List(3);&lt;br /&gt;&lt;br /&gt;l1.add("One");&lt;br /&gt;&lt;br /&gt;l1.add("Two");&lt;br /&gt;&lt;br /&gt;l1.add("Three");&lt;br /&gt;&lt;br /&gt;l1.add("Four");&lt;br /&gt;add(l1);&lt;br /&gt;&lt;br /&gt;List l2 = new List(3,true);&lt;br /&gt;&lt;br /&gt;l2.add("One");&lt;br /&gt;&lt;br /&gt;l2.add("Two");&lt;br /&gt;&lt;br /&gt;l2.add("Three");&lt;br /&gt;&lt;br /&gt;l2.add("Four");&lt;br /&gt;&lt;br /&gt;add(l2);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;public class colors extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.setFont(new Font("Arial",Font.BOLD,20));&lt;br /&gt;&lt;br /&gt;g.drawString("Default color",10,10);&lt;br /&gt;&lt;br /&gt;g.setColor(Color.red.green.yellow.red.cyan);&lt;br /&gt;&lt;br /&gt;g.drawString("Find the color",10,30);&lt;br /&gt;&lt;br /&gt;g.setColor(Color.pink);&lt;br /&gt;&lt;br /&gt;g.drawString("Pink color",10,50);&lt;br /&gt;g.setColor(Color.cyan);&lt;br /&gt;&lt;br /&gt;g.drawString("Cyan color",10,70);&lt;br /&gt;&lt;br /&gt;g.fillArc(80,80,120,120,0,90);&lt;br /&gt;&lt;br /&gt;g.drawString("Squiggle #9",10,130);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class draw1 extends Applet&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.drawOval(60,60,120,120);&lt;br /&gt;&lt;br /&gt;g.fillOval(90,120,50,20);&lt;br /&gt;&lt;br /&gt;g.drawLine(165,125,165,175);&lt;br /&gt;&lt;br /&gt;g.drawArc(110,130,95,95,0,-185);&lt;br /&gt;&lt;br /&gt;g.drawLine(165,175,150,160);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class draw2 extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.setColor(Color.red);&lt;br /&gt;g.fillOval(205,60,30,30);&lt;br /&gt;&lt;br /&gt;g.setColor(Color.orange);&lt;br /&gt;&lt;br /&gt;g.fillRoundRect(180,90,80,80,20,20);&lt;br /&gt;&lt;br /&gt;g.setColor(Color.blue);&lt;br /&gt;&lt;br /&gt;g.fillRect(198,168,10,70);&lt;br /&gt;&lt;br /&gt;g.fillRect(228,168,10,70);&lt;br /&gt;&lt;br /&gt;g.fillRect(140,80,10,40);&lt;br /&gt;&lt;br /&gt;g.fillRect(290,115,10,40);&lt;br /&gt;&lt;br /&gt;g.fillRect(260,115,40,10);&lt;br /&gt;g.fillRect(140,115,40,10);&lt;br /&gt;&lt;br /&gt;g.setColor(Color.magenta);&lt;br /&gt;&lt;br /&gt;g.drawString("Had fun",10,30);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class drawstr extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;String s;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;s = "Welcome to Java" ;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.drawString(s,100,100);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class flowlay extends Applet&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;// FlowLayout f = new FlowLayout(FlowLayout.RIGHT);&lt;br /&gt;&lt;br /&gt;FlowLayout f = new FlowLayout(0,10,10);&lt;br /&gt;&lt;br /&gt;setLayout(f);&lt;br /&gt;&lt;br /&gt;Button b1 = new Button("One");&lt;br /&gt;&lt;br /&gt;Button b2 = new Button("One");&lt;br /&gt;&lt;br /&gt;Button b3 = new Button("One");&lt;br /&gt;Button b4 = new Button("One");&lt;br /&gt;&lt;br /&gt;Button b5 = new Button("One");&lt;br /&gt;&lt;br /&gt;add(b1);&lt;br /&gt;&lt;br /&gt;add(b2);&lt;br /&gt;&lt;br /&gt;add(b3);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class fonts extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Font f1,f2 ,f3;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Font f1 = new Font("Courier",Font.BOLD,8);&lt;br /&gt;&lt;br /&gt;Font f2 = new Font("Times Roman",Font.ITALIC,15);&lt;br /&gt;&lt;br /&gt;Font f3 = new Font("Arial",Font.PLAIN,22);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.setColor(Color.red);&lt;br /&gt;&lt;br /&gt;g.drawString("Normal font",20,10);&lt;br /&gt;&lt;br /&gt;g.setFont(f1);&lt;br /&gt;&lt;br /&gt;g.setColor(Color.green);&lt;br /&gt;&lt;br /&gt;g.drawString("Courier font",20,60);&lt;br /&gt;g.setFont(f2);&lt;br /&gt;&lt;br /&gt;g.setColor(Color.blue);&lt;br /&gt;&lt;br /&gt;g.drawString("Times Roman",20,110);&lt;br /&gt;&lt;br /&gt;g.setFont(f3);&lt;br /&gt;&lt;br /&gt;g.setColor(Color.magenta);&lt;br /&gt;&lt;br /&gt;g.drawString("Arial font",20,160);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class graph extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;setBackground(Color.pink);&lt;br /&gt;&lt;br /&gt;g.drawLine(10,10,10,200);&lt;br /&gt;&lt;br /&gt;g.drawString("Palani",130,130);&lt;br /&gt;g.drawRect(50,50,120,120);&lt;br /&gt;&lt;br /&gt;g.setColor(Color.red);&lt;br /&gt;&lt;br /&gt;g.drawRoundRect(150,150,250,250,30,30);&lt;br /&gt;&lt;br /&gt;g.fillRect(270,270,50,50);&lt;br /&gt;&lt;br /&gt;g.draw3DRect(300,300,10,10,true);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class gridlay extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;GridLayout f = new GridLayout(6,6,1,1);&lt;br /&gt;&lt;br /&gt;setLayout(f);&lt;br /&gt;&lt;br /&gt;Button b1 = new Button("One");&lt;br /&gt;&lt;br /&gt;Button b2 = new Button("One");&lt;br /&gt;Button b3 = new Button("One");&lt;br /&gt;&lt;br /&gt;Button b4 = new Button("One");&lt;br /&gt;&lt;br /&gt;Button b5 = new Button("One");&lt;br /&gt;&lt;br /&gt;add(b1);&lt;br /&gt;&lt;br /&gt;add(b2);&lt;br /&gt;&lt;br /&gt;add(b3);&lt;br /&gt;&lt;br /&gt;add(b4);&lt;br /&gt;add(b5);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;public class img extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;Image i;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;i = getImage(getCodeBase(),"fish.gif");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.drawImage(i,10,10,this);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class order extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;String s ;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;s = " Init " ;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void start()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;s = s + " start ";&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;s = s + " paint ";&lt;br /&gt;&lt;br /&gt;g.drawString(s,100,100);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;public void stop()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;repaint();&lt;br /&gt;&lt;br /&gt;s = "null";&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;public class param extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;String str;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;str=getParameter("n");&lt;br /&gt;&lt;br /&gt;setBackground(Color.cyan);&lt;br /&gt;&lt;br /&gt;str="hai " + str + "How are you";&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.drawString(str,20,20);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;public class poly extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int xp[]={10,20,30};&lt;br /&gt;&lt;br /&gt;int yp[]={10,20,30};&lt;br /&gt;&lt;br /&gt;int n =3;&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.drawPolygon(xp,yp,n);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-7537415932186716321?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/7537415932186716321/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=7537415932186716321' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/7537415932186716321'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/7537415932186716321'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/01/java-example-event-programming_6512.html' title='Java Example Event Programming'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-3128285396739835425</id><published>2008-01-06T22:08:00.000-08:00</published><updated>2008-01-06T22:18:47.514-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example Event Programming-2'/><title type='text'>Java Example Event Programming</title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;PREVIOUS&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Frame Program&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;&lt;textarea name="unique_name" rows="3" cols="30"&gt;/* &lt;applet code="colormenu" width="400" height="400"&gt; &lt;/applet&gt; */ &lt;/textarea name&gt;&lt;br /&gt;&lt;br /&gt;class frammenu extends Frame implements ActionListener&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;MenuBar mb; Menu m1,m2 ;&lt;br /&gt;&lt;br /&gt;MenuItem mi1,mi2,mi3,mi4;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;mb = new MenuBar();&lt;br /&gt;&lt;br /&gt;m1 = new Menu("File");&lt;br /&gt;&lt;br /&gt;m2 = new Menu("Color");&lt;br /&gt;&lt;br /&gt;mi1 = new MenuItem("Exit");&lt;br /&gt;&lt;br /&gt;mi2 = new MenuItem("Blue");&lt;br /&gt;&lt;br /&gt;mi3 = new MenuItem("Red");&lt;br /&gt;&lt;br /&gt;mi4 = new MenuItem("Green");&lt;br /&gt;&lt;br /&gt;mi1.addActionListener(this);&lt;br /&gt;&lt;br /&gt;mi2.addActionListener(this);&lt;br /&gt;&lt;br /&gt;mi3.addActionListener(this);&lt;br /&gt;&lt;br /&gt;mi4.addActionListener(this);&lt;br /&gt;&lt;br /&gt;m1.add(mi1);&lt;br /&gt;&lt;br /&gt;m2.add(mi2); m2.add(mi3); m2.add(mi4);&lt;br /&gt;&lt;br /&gt;mb.add(m1); mb.add(m2);&lt;br /&gt;&lt;br /&gt;setMenuBar(mb);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void actionPerformed(ActionEvent ae)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;if(ae.getSource() == mi2)&lt;br /&gt;&lt;br /&gt;setBackground(Color.blue);&lt;br /&gt;&lt;br /&gt;if(ae.getSource() == mi3)&lt;br /&gt;&lt;br /&gt;setBackground(Color.red);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;public class colormenu extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Frame f = new frammenu();&lt;br /&gt;&lt;br /&gt;f.setSize(400,400);&lt;br /&gt;&lt;br /&gt;f.setVisible(true);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;class fra extends Frame&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;fra()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;super("frame title");&lt;br /&gt;&lt;br /&gt;winadapt w = new winadapt(this);&lt;br /&gt;&lt;br /&gt;addWindowListener(w);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.drawString("This is frame",100,100);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class winadapt extends WindowAdapter&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;fra f1;&lt;br /&gt;&lt;br /&gt;public winadapt(fra f2)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;f1 = f2;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void windowClosing(WindowEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;f1.setVisible(false);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class filedia&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String a[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Frame f = new fra();&lt;br /&gt;&lt;br /&gt;f.setSize(300,300);&lt;br /&gt;&lt;br /&gt;f.setVisible(true);&lt;br /&gt;&lt;br /&gt;FileDialog fd = new FileDialog(f,"File dialog");&lt;br /&gt;&lt;br /&gt;fd.setVisible(true);&lt;br /&gt;&lt;br /&gt;String ffile=fd.getFile();&lt;br /&gt;&lt;br /&gt;String fdir=fd.getDirectory();&lt;br /&gt;&lt;br /&gt;System.out.println("file " + ffile+" " + fdir);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class frame1 extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Frame f;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;f = new Frame();&lt;br /&gt;&lt;br /&gt;f.setSize(100,100);&lt;br /&gt;&lt;br /&gt;f.setVisible(true);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.drawString("this is applet",10,10);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;class fra extends Frame&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.setColor(Color.blue);&lt;br /&gt;&lt;br /&gt;g.drawString("This is frame",50,50);&lt;br /&gt;&lt;br /&gt;g.drawLine(50,50,100,50);&lt;br /&gt;&lt;br /&gt;g.fillOval(100,100,50,50);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class frame2 extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Frame f;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;f = new fra();&lt;br /&gt;&lt;br /&gt;f.setSize(100,100);&lt;br /&gt;&lt;br /&gt;f.setVisible(true);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.drawString("this is applet",10,10);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;class fra extends Frame&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;fra()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;super("frame title");&lt;br /&gt;&lt;br /&gt;winadapt w = new winadapt(this);&lt;br /&gt;&lt;br /&gt;addWindowListener(w);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.drawString("This is frame",100,100);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class winadapt extends WindowAdapter&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;fra f1;&lt;br /&gt;&lt;br /&gt;public winadapt(fra f2)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;f1 = f2;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void windowClosing(WindowEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;f1.setVisible(false);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class frame3 extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Frame f;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;f = new fra();&lt;br /&gt;&lt;br /&gt;f.setSize(100,100);&lt;br /&gt;&lt;br /&gt;f.setVisible(true);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.drawString("this is applet",10,10);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;&lt;textarea name="unique_name" rows="3" cols="30"&gt;/* &lt;applet code=frammenu.class&lt;br /&gt;width=400 height=400&gt; &lt;/applet&gt; */ &lt;/textarea name&gt;&lt;br /&gt;&lt;br /&gt;class fram extends Frame&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;String msg=" ";&lt;br /&gt;&lt;br /&gt;fram()&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;super("Menu Frame");&lt;br /&gt;&lt;br /&gt;MenuBar mb = new MenuBar();&lt;br /&gt;&lt;br /&gt;Menu m1 = new Menu("File");&lt;br /&gt;&lt;br /&gt;Menu m2 = new Menu("Edit");&lt;br /&gt;&lt;br /&gt;MenuItem mi1 = new MenuItem("Open");&lt;br /&gt;MenuItem mi2 = new MenuItem("Save");&lt;br /&gt;&lt;br /&gt;MenuItem mi3 = new MenuItem("Copy");&lt;br /&gt;&lt;br /&gt;MenuItem mi4 = new MenuItem("Paste");&lt;br /&gt;&lt;br /&gt;m1.add(mi1);&lt;br /&gt;&lt;br /&gt;m1.add(mi2);&lt;br /&gt;&lt;br /&gt;m2.add(mi3);&lt;br /&gt;&lt;br /&gt;m2.add(mi4);&lt;br /&gt;&lt;br /&gt;mb.add(m1);&lt;br /&gt;&lt;br /&gt;mb.add(m2);&lt;br /&gt;setMenuBar(mb);&lt;br /&gt;&lt;br /&gt;winadapt w = new winadapt(this);&lt;br /&gt;&lt;br /&gt;addWindowListener(w);&lt;br /&gt;&lt;br /&gt;mi1.addActionListener(new mnuhandler(this));&lt;br /&gt;&lt;br /&gt;mi2.addActionListener(new mnuhandler(this));&lt;br /&gt;&lt;br /&gt;mi3.addActionListener(new mnuhandler(this));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.drawString(msg,100,100);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class mnuhandler implements ActionListener&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;fram f1;&lt;br /&gt;&lt;br /&gt;public mnuhandler(fram f2)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;f1 = f2;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void actionPerformed(ActionEvent ae)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;String msg;&lt;br /&gt;&lt;br /&gt;String s = (String) ae.getActionCommand();&lt;br /&gt;&lt;br /&gt;if(s.equals("Open"))&lt;br /&gt;&lt;br /&gt;msg = "Open";&lt;br /&gt;else if(s.equals("Save"))&lt;br /&gt;&lt;br /&gt;msg ="Save";&lt;br /&gt;&lt;br /&gt;else if(s.equals("Copy"))&lt;br /&gt;&lt;br /&gt;msg = "Copy";&lt;br /&gt;&lt;br /&gt;else&lt;br /&gt;&lt;br /&gt;msg = "Paste";&lt;br /&gt;msg = msg +" selected";&lt;br /&gt;&lt;br /&gt;f1.msg=msg;&lt;br /&gt;&lt;br /&gt;f1.repaint();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;class winadapt extends WindowAdapter&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;fram f1;&lt;br /&gt;&lt;br /&gt;public winadapt(fram f2)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;f1 = f2;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;public void windowClosing(WindowEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;f1.dispose();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class frammenu extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;Frame f;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;f = new fram();&lt;br /&gt;&lt;br /&gt;f.setSize(300,300);&lt;br /&gt;&lt;br /&gt;f.setVisible(true);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class mnu extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Frame f;&lt;br /&gt;&lt;br /&gt;MenuBar mb;&lt;br /&gt;Menu m1,m2;&lt;br /&gt;&lt;br /&gt;MenuItem mi1,mi2,mi3,mi4;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;f = new Frame();&lt;br /&gt;&lt;br /&gt;f.setSize(400,400);&lt;br /&gt;f.setVisible(true);&lt;br /&gt;&lt;br /&gt;mb = new MenuBar();&lt;br /&gt;&lt;br /&gt;m1 = new Menu("files");&lt;br /&gt;&lt;br /&gt;m2 = new Menu("edit");&lt;br /&gt;&lt;br /&gt;mi1 = new MenuItem("new");&lt;br /&gt;mi2 = new MenuItem("open");&lt;br /&gt;&lt;br /&gt;mi3 = new MenuItem("cut");&lt;br /&gt;&lt;br /&gt;mi4 = new MenuItem("paste");&lt;br /&gt;&lt;br /&gt;m1.add(mi1);&lt;br /&gt;&lt;br /&gt;m1.add(mi2);&lt;br /&gt;m2.add(mi3);&lt;br /&gt;m2.add(mi4);&lt;br /&gt;&lt;br /&gt;mb.add(m1);&lt;br /&gt;&lt;br /&gt;mb.add(m2);&lt;br /&gt;f.setMenuBar(mb);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;&gt;Next&gt;&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-3128285396739835425?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/3128285396739835425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=3128285396739835425' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3128285396739835425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3128285396739835425'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/01/java-example-event-programming_06.html' title='Java Example Event Programming'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-6563574542607901463</id><published>2008-01-06T21:36:00.000-08:00</published><updated>2008-01-06T22:07:35.159-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Example Event Programming-1'/><title type='text'>Java Example Event Programming</title><content type='html'>import java.awt.*;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;&lt;textarea name="unique_name" rows="3" cols="30"&gt;/* &lt;applet code="bounds.class" width="400" height="400"&gt; &lt;/applet&gt; */ &lt;/textarea name&gt;&lt;br /&gt;&lt;br /&gt;public class bounds extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Button b1, b2,b3,b4;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;// setLayout(null);&lt;br /&gt;&lt;br /&gt;b1 = new Button("First button");&lt;br /&gt;&lt;br /&gt;b2 = new Button("test");&lt;br /&gt;&lt;br /&gt;b3 = new Button("First button");&lt;br /&gt;&lt;br /&gt;b4 = new Button("test");&lt;br /&gt;&lt;br /&gt;Label l = new Label("same Label");&lt;br /&gt;&lt;br /&gt;l.setBounds(10,10,40,40);&lt;br /&gt;&lt;br /&gt;b1.setBounds(50,50,110,110);&lt;br /&gt;&lt;br /&gt;b2.setBounds(200,200,50,20);&lt;br /&gt;&lt;br /&gt;add(l);&lt;br /&gt;&lt;br /&gt;add(b1);&lt;br /&gt;&lt;br /&gt;add(b2);&lt;br /&gt;&lt;br /&gt;/* setLayout(new FlowLayout());*/&lt;br /&gt;&lt;br /&gt;add(l);&lt;br /&gt;&lt;br /&gt;add(b3);&lt;br /&gt;&lt;br /&gt;add(b4);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;textarea name="unique_name" rows="3" cols="30"&gt;/*&lt;applet code="butt" width="500" height="400"&gt; &lt;/applet&gt; */ &lt;/textarea name&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class butt extends Applet implements ActionListener&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;TextField tx,tx1,tx2;&lt;br /&gt;&lt;br /&gt;Button b1,b2;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;tx = new TextField(20);&lt;br /&gt;&lt;br /&gt;tx1 = new TextField(20);&lt;br /&gt;&lt;br /&gt;tx2 = new TextField(20);&lt;br /&gt;&lt;br /&gt;b1 = new Button(" + ");&lt;br /&gt;&lt;br /&gt;b2 = new Button(" - ");&lt;br /&gt;&lt;br /&gt;b1.addActionListener(this);&lt;br /&gt;&lt;br /&gt;b2.addActionListener(this);&lt;br /&gt;&lt;br /&gt;add(tx);&lt;br /&gt;&lt;br /&gt;add(tx1);&lt;br /&gt;&lt;br /&gt;add(tx2);&lt;br /&gt;&lt;br /&gt;add(b1);&lt;br /&gt;&lt;br /&gt;add(b2);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void actionPerformed(ActionEvent ae)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int a,b,c;&lt;br /&gt;&lt;br /&gt;a = Integer.parseInt(tx1.getText());&lt;br /&gt;&lt;br /&gt;b = Integer.parseInt(tx2.getText());&lt;br /&gt;&lt;br /&gt;if(ae.getSource()==b1)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;c = a + b;&lt;br /&gt;&lt;br /&gt;tx.setText(String.valueOf(c));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;else&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;c = a - b;&lt;br /&gt;&lt;br /&gt;tx.setText(String.valueOf(c));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class check extends Applet implements ItemListener&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Checkbox ch,ch1,ch2,ch3;&lt;br /&gt;&lt;br /&gt;CheckboxGroup chg;&lt;br /&gt;&lt;br /&gt;TextField tx,tx1;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;ch = new Checkbox("Required");&lt;br /&gt;&lt;br /&gt;add(ch);&lt;br /&gt;&lt;br /&gt;ch.addItemListener(this);&lt;br /&gt;&lt;br /&gt;chg = new CheckboxGroup();&lt;br /&gt;&lt;br /&gt;ch1 = new Checkbox("Small",false,chg);&lt;br /&gt;&lt;br /&gt;ch2 = new Checkbox("Medium",false,chg);&lt;br /&gt;&lt;br /&gt;ch3 = new Checkbox("Large",true,chg);&lt;br /&gt;&lt;br /&gt;add(ch1);&lt;br /&gt;&lt;br /&gt;add(ch2);&lt;br /&gt;&lt;br /&gt;add(ch3);&lt;br /&gt;&lt;br /&gt;ch1.addItemListener(this);&lt;br /&gt;&lt;br /&gt;ch2.addItemListener(this);&lt;br /&gt;&lt;br /&gt;ch3.addItemListener(this);&lt;br /&gt;&lt;br /&gt;tx = new TextField(15);&lt;br /&gt;&lt;br /&gt;add(tx);&lt;br /&gt;&lt;br /&gt;tx1 = new TextField(15);&lt;br /&gt;&lt;br /&gt;add(tx1);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void itemStateChanged(ItemEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;if(e.getItemSelectable()==ch1)&lt;br /&gt;&lt;br /&gt;tx.setText("Small selected");&lt;br /&gt;&lt;br /&gt;if(e.getItemSelectable()==ch2)&lt;br /&gt;&lt;br /&gt;tx.setText("Medium selected");&lt;br /&gt;&lt;br /&gt;if(e.getItemSelectable()==ch3)&lt;br /&gt;&lt;br /&gt;tx.setText("Large selected");&lt;br /&gt;&lt;br /&gt;if(e.getItemSelectable()==ch)&lt;br /&gt;&lt;br /&gt;if(ch.getState()==true)&lt;br /&gt;&lt;br /&gt;tx1.setText("Required selected");&lt;br /&gt;&lt;br /&gt;else&lt;br /&gt;&lt;br /&gt;tx1.setText("Required not selected");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;textarea name="unique_name" rows="3" cols="30"&gt;/*&lt;applet code="choice" width="500" height="400"&gt; &lt;/applet&gt; */ &lt;/textarea name&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class choice extends Applet implements ItemListener&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Choice ch;&lt;br /&gt;&lt;br /&gt;TextField tx;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;tx = new TextField(14);&lt;br /&gt;&lt;br /&gt;add(tx);&lt;br /&gt;&lt;br /&gt;ch = new Choice();&lt;br /&gt;&lt;br /&gt;ch.add("Videocon");&lt;br /&gt;&lt;br /&gt;ch.add("BPL");&lt;br /&gt;&lt;br /&gt;ch.add("Onida");&lt;br /&gt;&lt;br /&gt;ch.add("Sony");&lt;br /&gt;&lt;br /&gt;add(ch);&lt;br /&gt;&lt;br /&gt;ch.addItemListener(this);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void itemStateChanged(ItemEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;if(e.getItemSelectable() == ch)&lt;br /&gt;&lt;br /&gt;tx.setText(ch.getSelectedItem());&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;&lt;textarea name="unique_name" rows="3" cols="30"&gt;/*&lt;applet code=drag width=400&lt;br /&gt;height=400&gt; &lt;/applet&gt; */ &lt;/textarea name&gt;&lt;br /&gt;&lt;br /&gt;public class drag extends Applet implements MouseMotionListener&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int x,y;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;addMouseMotionListener(this);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void update(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;paint(g);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.setColor(Color.red);&lt;br /&gt;&lt;br /&gt;g.drawOval(x,y,4,4);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mouseDragged(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;x = e.getX();&lt;br /&gt;&lt;br /&gt;y = e.getY();&lt;br /&gt;&lt;br /&gt;repaint();&lt;br /&gt;&lt;br /&gt;showStatus(x +"," + y);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mouseMoved(MouseEvent e) { }&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class mseadapt extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Button b;&lt;br /&gt;&lt;br /&gt;b = new Button("click me");&lt;br /&gt;&lt;br /&gt;b.addMouseListener(new a());&lt;br /&gt;&lt;br /&gt;add(b);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class a extends MouseAdapter&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void mouseClicked(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;showStatus("clicked");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class mseevents extends Applet implements MouseListener&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;public void init( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;addMouseListener(this);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mouseClicked(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;showStatus("Mouse clicked at " + e.getX( ) +" , " + e.getY( ));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Write above code for other mouse events&lt;br /&gt;&lt;br /&gt;public void mouseEntered(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;showStatus("Mouse entered at " + e.getX( ) +" , " + e.getY( ));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mousePressed(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;showStatus("Mouse pressed at " + e.getX( ) +" , " + e.getY( ));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mouseExited(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;showStatus("Mouse exited at " + e.getX( ) +" , " + e.getY( ));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mouseReleased(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;showStatus("Mouse released at " + e.getX( ) +" , " + e.getY( ));&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;&lt;textarea name="unique_name" rows="3" cols="30"&gt;/*&lt;applet code=drag width=400&lt;br /&gt;height=400&gt; &lt;/applet&gt; */ &lt;/textarea name&gt;&lt;br /&gt;&lt;br /&gt;public class drag extends Applet implements MouseMotionListener&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int x,y,c=0;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;addMouseMotionListener(this);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void update(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;paint(g);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;if(c==0)&lt;br /&gt;&lt;br /&gt;{ g.setColor(Color.blue);&lt;br /&gt;&lt;br /&gt;g.drawLine(x,y,x+1,y+1);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;else&lt;br /&gt;&lt;br /&gt;{ g.setColor(Color.red);&lt;br /&gt;&lt;br /&gt;g.drawOval(x,y,10,10);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mouseDragged(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;c=1;&lt;br /&gt;&lt;br /&gt;x = e.getX(); y = e.getY();&lt;br /&gt;&lt;br /&gt;repaint();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mouseMoved(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;c=0;&lt;br /&gt;&lt;br /&gt;x=e.getX(); y=e.getY();&lt;br /&gt;&lt;br /&gt;repaint();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class txt extends Applet implements ActionListener&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;TextField tx;&lt;br /&gt;&lt;br /&gt;Button b1,b2;&lt;br /&gt;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;tx = new TextField(20);&lt;br /&gt;&lt;br /&gt;b1 = new Button("Display");&lt;br /&gt;&lt;br /&gt;b2 = new Button("Clear");&lt;br /&gt;&lt;br /&gt;b1.addActionListener(this);&lt;br /&gt;&lt;br /&gt;b2.addActionListener(this);&lt;br /&gt;&lt;br /&gt;add(tx);&lt;br /&gt;&lt;br /&gt;add(b1);&lt;br /&gt;&lt;br /&gt;add(b2);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void actionPerformed(ActionEvent a)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;if(a.getSource()==b1)&lt;br /&gt;tx.setText("Welcome to Applet");&lt;br /&gt;&lt;br /&gt;else&lt;br /&gt;&lt;br /&gt;tx.setText("");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-6563574542607901463?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/6563574542607901463/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=6563574542607901463' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/6563574542607901463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/6563574542607901463'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2008/01/java-example-event-programming.html' title='Java Example Event Programming'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-1351360282878619728</id><published>2007-12-25T23:21:00.000-08:00</published><updated>2007-12-25T23:30:28.943-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-16'/><title type='text'>JAVA 2.0 NOTE</title><content type='html'>&lt;p&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt; &lt;/p&gt;&lt;p align="center"&gt;&lt;strong&gt;&gt;&gt;PREVIOUS&gt;&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;17. KEYWORDS IN JAVA&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* class , method, constuctor, subclass , superclass, this, super, final, finalize(), garbage collection, method overriding, package, interface, import, extend, implement, private, public, protected, static , try, catch, finally, throw, throws , thread, multhread, run, suspend, resume, start, stop, synchronization, deadlock, applet. */&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;Bytecode&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Java compiler generates machine independent bytecode instead of machine dependent exe file. So it gives ‘write once run anywhere’ . Due to this, most of the communication programs are done in Java instead of using C++ or VC++.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Class&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The most important feature of the oop is classes. A class defines the shape and behaviour of an object and is a template for multiple object with similar features. Class contains the decl of instance variables and methods.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Constructor&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;A &lt;a href="http://java4interview.blogspot,com/"&gt;constructor&lt;/a&gt; initializes an object immediately upon creation. Once defined, it is automatically called immediately after the object is created before the new operator is completed. It has the same name as class and is similar to method but does not have the return type.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Garbage collection&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;When no references to an object exist, that object is assumed to be no longer needed, and the memory occupied by the object is reclaimed. This technique is called garbage collection.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;finalize( )&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This method is called just prior to garbage collection. It &lt;a href="http://java4interview.blogspot,com/"&gt;means&lt;/a&gt; it is called, when an object goes out of scope.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;New&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;The new operator dynamically allocates memory for the object and returns reference to it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;This&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;this can be used inside any method to refere to the current &lt;a href="http://java4interview.blogspot,com/"&gt;Object&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Method overloading&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;It is possible to have two or more methods with same name but different &lt;a href="http://java4interview.blogspot,com/"&gt;parameters&lt;/a&gt; within the same class. This is called method overloading.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Method Overriding&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Whenever there are methods of the same name both in the base class as well as in the derived class and if that method is called by main, the method in the derived class is always executed. This is called overriding.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Recursion&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;It is a process of defining something in terms of itself.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Static &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When a member is declared as static, it can be accessed before any objects of its class are created and without reference to any object.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Final variable&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;used to declare constant variable . final float PI=3.14&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Inheritance&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Inheritance is the method of creating new class based on the already existing class. The new class derived is called as sub class or derived class which has all features of the existing class and its own. The existing class is called as super class or base class.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java4interview.blogspot,com/"&gt;Adv :&lt;/a&gt; resuablity of code, accessibility of variables and methods of the base class&lt;br /&gt;&lt;br /&gt;by the derived class.&lt;br /&gt;&lt;br /&gt;If the class is derived from more than one class , then it is called as multiple inheritance. This is not available in Java.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Extend&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;extend keyword is used to create a subclass from a basic class.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Super&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;super has two forms. First it calls the superclass’s constructor. The second is used to access a member of the superclass that has been hidden by a member of a subclass.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Thread&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;A thread is a line of execution. Using multithreading, we can run the different parts of the program at a time.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Synchoronized.&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;This keyword is used with a method to enable synchronization. It contains an object which allows only one thread to&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Network&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;A set of computers and peripherals physically connected together to enable sharing of resources and communication. Java network can be done either by Datagram which contains DatagramPacket for container of data and DatagramSocket which contains send and receive methods or TCP/IP which contains Socket class for client and Serversocket for server.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;RMI&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;It allows an object running in a system to access a method that runs on another system. It is used to create distributed application in Java. In this rmic compiler is used to create Stub class and Skeleton classes for client and server respectively. Rmiregistry is used to map the name of server.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Beans&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Beans are software component that are reusable in variety of environments. After creating beans, it can be added to toolbar of microsoft office, browser, etc.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Servlets &lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Servlets are small program that are executed on the web server to extend the functionality of the server. It contains two packages javax.servlet and javax.servlet.http&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;New in Java 2.0&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Swing – contains tabbed panes, scroll panes, picture button, etc.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Collections&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;More security mechanisms&lt;br /&gt;&lt;br /&gt;JIT – to create exe file instead of bytecode&lt;br /&gt;&lt;br /&gt;Can play wav,au,midi and sudio files&lt;br /&gt;&lt;br /&gt;Drag and drop capabilities&lt;br /&gt;&lt;br /&gt;wait( ) , sleep( ) and suspend( ) are deprecated in Java 2.0&lt;br /&gt;&lt;br /&gt;Java Plug-in directos browser to use JRE rather than JVM&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;&gt;NEXT&gt;&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/p&gt;&lt;div align="center"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-1351360282878619728?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/1351360282878619728/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=1351360282878619728' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1351360282878619728'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1351360282878619728'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-20-note_68.html' title='JAVA 2.0 NOTE'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-2653606080955711745</id><published>2007-12-25T22:08:00.000-08:00</published><updated>2007-12-25T22:37:37.439-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-15'/><title type='text'>JAVA 2.0 NOTE</title><content type='html'>&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;&gt;PREVIOUS&gt;&gt;&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;a name="servlets"&gt;&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;&lt;div align="left"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;strong&gt;Servlets&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Servlets are small programs that execute on the server side of a Web connection, used to extend the functionality of a Web Server.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;JSDK&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Java Servlet Development Kit (JSDK) contains class libraries to create servlets. It contains the utility servletrunner to test the servlets. The basic life cycles of servlets are init( ), service( ) and destroy( ).&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;strong&gt;&lt;/strong&gt;&lt;strong&gt;The steps to create a servlets are&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Create and compile the servlet source code.&lt;br /&gt;&lt;br /&gt;Start the servletrunner utility.&lt;br /&gt;&lt;br /&gt;Start a Web browser and reuest the servlet.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Adv of servlets over CGI :&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Performance is better. Creating a separate process to handle each client reuest isn't necessry.&lt;br /&gt;Servlets are platform-independent, because they are written in Java.&lt;br /&gt;&lt;br /&gt;The Java Security Manager on the server enforces a set of restrictions to protect the resources on a server machine.&lt;br /&gt;&lt;br /&gt;The full functionality of Java class is available to the servlet. It can communicate with applets, databases or other software via sockets and RMI.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Example :&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;Step 1 :&lt;/strong&gt; colorGet.html&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;/center&gt;&lt;center&gt;&lt;form name="form1" action="'&lt;http://localhost:8080/servlet/colorgetservlet" method="get"&gt;&lt;b&gt;color : &lt;/b&gt;&lt;br /&gt;&lt;select size="1" name="color"&gt; &lt;option value="Red"&gt;Red&lt;/option&gt; &lt;option value="Blue"&gt;Blue&lt;/option&gt;&lt;/select&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;input type=" submit" value="submit"&gt;&lt;br /&gt;&lt;/form&gt;&lt;/center&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 2 :&lt;/strong&gt; &lt;/div&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;strong&gt;colorGetSelvlet.java&lt;br /&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="left"&gt;import java.io.* ;&lt;br /&gt;import javax.servlet.*;&lt;br /&gt;import javax.servlet.http.*;&lt;br /&gt;public class colorGetServlet extends HttpServlet&lt;br /&gt;{&lt;br /&gt;public void doGet (HttpServlet request, HttpServletResponse response)&lt;br /&gt;throws ServletException, IOException&lt;br /&gt;{&lt;br /&gt;String color = request.getParameter("color");&lt;br /&gt;response.setContentType("text/html");&lt;br /&gt;PrintWriter pw = response.getWriter( );&lt;br /&gt;pw.println("&lt;b&gt; The selected color is : " );&lt;br /&gt;pw.println(color);&lt;br /&gt;pw.close( );&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Step 3: compile the above program colorGetServlet.java&lt;br /&gt;&lt;br /&gt;Step 4 : start servlet runner by c:\javawebbrowser2.0\jserv&lt;br /&gt;&lt;br /&gt;Step 5: Display the web page in the browser. Select a color and submit.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;center&gt;&lt;br /&gt;&lt;strong&gt;&gt;&gt;&gt;NEXT&gt;&gt;&gt;&lt;/strong&gt;&lt;/center&gt;&lt;center&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/center&gt;&lt;center&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/center&gt;&lt;center&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/center&gt;&lt;center&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/center&gt;&lt;center&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/center&gt;&lt;center&gt;&lt;/center&gt;&lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-2653606080955711745?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/2653606080955711745/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=2653606080955711745' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/2653606080955711745'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/2653606080955711745'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-20-note_25.html' title='JAVA 2.0 NOTE'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-1499759197261681174</id><published>2007-12-19T00:29:00.000-08:00</published><updated>2007-12-25T22:05:53.428-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-14'/><title type='text'></title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;&gt;PREVIOUS&gt;&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;a name="swing"&gt;&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;15. Swing&lt;/span&gt; &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Swing is a set of classes that provides more powerful and flexible components than are possible with the AWT. In addition to buttons, check boxes and labels, Swing supplies severals components including tabbed panes, scroll panes, trees, picture buttons, combo box , etc.&lt;br /&gt;Unlike AWT components, Swing components are platform independent since they are written in Java. They are called as lightweight components. Swing related classes are contained in javax.swing and its subpackages.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;JApplet &lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Applets&lt;/a&gt; that use Swing must be subclasses of JApplet, which extends Applet. JApplet is rich in functionality than Applets and provides various panes such as content pane, glass pane and root pane. To add a component, obtain the pane then call add( ) method for the pane of the JApplet.&lt;br /&gt;Container getContentPane( ) to obtain the content pane&lt;br /&gt;&lt;br /&gt;void add(comp) to add a component in content pane&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;span style="font-size:130%;"&gt;Comp&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;label&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Constructor&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;JLabel(Icon I)&lt;br /&gt;JLabel(String s)&lt;br /&gt;JLable(String s, Icon I, int align)&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Methods&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Icon getIcon( )&lt;br /&gt;String getText( )&lt;br /&gt;void setIcon(Icon I)&lt;br /&gt;void setText(String s&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Comp&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Text Field&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Constructor&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;JTextField( )&lt;br /&gt;JTextField(int cols)&lt;br /&gt;JTextField(String s)&lt;br /&gt;JTextField(String s, int cols)&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Methods&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;.........................&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Comp&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;Buttons&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Constructor&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;JButton(Icon i)&lt;br /&gt;JButton(String s)&lt;br /&gt;JButton(String s, Icon I)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Methods&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;................................&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Comp&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;CheckBox&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Constructor&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;JCheckBox(Icon I)&lt;br /&gt;JCheckBox(String s)&lt;br /&gt;JCheckBox(Icon I, boolean)&lt;br /&gt;JChcekBox(String s, boolean)&lt;br /&gt;JCheckBox(String s, Icon I, boolean)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Methods&lt;/span&gt; &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;...........................&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Comp&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Radio Buttons&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Constructor&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;JRadioButton(Icon I)&lt;br /&gt;JRadioButton(String s)&lt;br /&gt;JRadioButton(String s, boolean)&lt;br /&gt;JRadioButton(s, I, boolean)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Methods&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;.........................................&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Comp&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;Combo Box&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Constructor&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;JComboBox( )&lt;br /&gt;JComboBox(Vector v)&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Methods&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;..............................&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Comp&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;Tabbed Panes&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Constructor&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;JTabbedPane( )&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Methods&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;addTab(title, comp)&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Comp&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Scroll Panes&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Constructor&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;JScrollPane(comp)&lt;br /&gt;JScrollPane(int vsb, int hsb)&lt;br /&gt;JScrollPane(comp, vsb, hsb)&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Methods&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;.......................................&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Comp&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Trees&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Constructor&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;JTree(HashTable h)&lt;br /&gt;JTree(Object ob[])&lt;br /&gt;JTree(TreeNode t)&lt;br /&gt;JTree(Vector v)&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;Methods&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;...........................................&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;Comp&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Tables&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Constructor&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;JTable(Obect data[][], Object colheads[])&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;Methods&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;...............................&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Icons&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Method&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Int getIconHeight( )&lt;br /&gt;&lt;/p&gt;&lt;p&gt;int getIconWidth( )&lt;br /&gt;&lt;/p&gt;&lt;p&gt;void paintIcon(comp, Graphics, x, y)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;void setDisabledIcon(icon)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;void setPressedIcon(icon)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;void setSelectedIcon(icon)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;void setRolloverIcon(icon)    Scroll Panes&lt;br /&gt;&lt;/p&gt;&lt;p&gt;JScrollPane(comp, vsb, hsb)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The vsb, hsb constants are&lt;br /&gt;&lt;/p&gt;&lt;p&gt;ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS&lt;br /&gt;&lt;/p&gt;&lt;p&gt;ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED&lt;br /&gt;&lt;/p&gt;&lt;p&gt;ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS&lt;br /&gt;&lt;/p&gt;&lt;p&gt;ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED    &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Example :&lt;br /&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;import javax.swsing.*;&lt;br /&gt;import java.awt.*;&lt;br /&gt;public class Jlabel extends JApplet&lt;br /&gt;{&lt;br /&gt;public void init( )&lt;br /&gt;{&lt;br /&gt;Container cp = getContentPane( );&lt;br /&gt;ImageIcon ii = new ImageIcon("Birds");&lt;br /&gt;JLabel jl = new JLabel("Birds",ii,JLabel.Center);&lt;br /&gt;Cp.add(jl);&lt;br /&gt;}&lt;br /&gt;}        &lt;br /&gt;Example :&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.*;&lt;br /&gt;public class jscroll extends JApplet&lt;br /&gt;{&lt;br /&gt;public void init( )&lt;br /&gt;{&lt;br /&gt;Container CP = getContentPane( );&lt;br /&gt;Jpanel jp = new Jpanel( );&lt;br /&gt;jp.setLayout(new GridLayout(20,20));&lt;br /&gt;int b = 0;&lt;br /&gt;for(int ii = 0; I&lt;20; I++)&lt;br /&gt;{&lt;br /&gt;for(k=0;k&lt;20;k++)&lt;br /&gt;{&lt;br /&gt;jp.add(new JButton("Button " + b));&lt;br /&gt;b++;&lt;br /&gt;}&lt;br /&gt;}    &lt;br /&gt;int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED&lt;br /&gt;int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;JScrollPane jsp = new JscrolPane(jp, v, h) ;&lt;br /&gt;CP.add(jsp, BorderLayout.CENTER);&lt;br /&gt;}&lt;br /&gt;} &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;&gt;NEXT&gt;&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-1499759197261681174?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/1499759197261681174/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=1499759197261681174' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1499759197261681174'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1499759197261681174'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/15.html' title=''/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-3397182117284568084</id><published>2007-12-19T00:21:00.000-08:00</published><updated>2007-12-19T00:23:13.390-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-13'/><title type='text'>JAVA 2.0 NOTE</title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;PREVIOUS&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="rmi"&gt;&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;13. Remote Method Invocation (RMI) &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;RMI allows java object that executes on one machine to invoke a method that executes on another machine. This is the one method of creating distributed application.&lt;br /&gt;&lt;br /&gt;Steps to create client/server application using RMI&lt;br /&gt;&lt;br /&gt;Write source code for interface, server and client program and compile them.&lt;br /&gt;&lt;br /&gt;Generate Stubs and Skeletons classes by compiling server program using RMI compiler&lt;br /&gt;Install files on client and server machines.&lt;br /&gt;&lt;br /&gt;start rmiregistry on server machine to map server name to object reference&lt;br /&gt;&lt;br /&gt;Execute the server program by java server.&lt;br /&gt;&lt;br /&gt;Execute the client program on client machine by java client localhost args&lt;br /&gt;&lt;br /&gt;inter.java&lt;br /&gt;&lt;br /&gt;import java.rmi.*;&lt;br /&gt;&lt;br /&gt;public interface inter extends Remote&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void getdata(int m,int n) throws RemoteException;&lt;br /&gt;&lt;br /&gt;int adddata() throws RemoteException;&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;client.java&lt;br /&gt;&lt;br /&gt;import java.rmi.*;&lt;br /&gt;&lt;br /&gt;public class client&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int a = Integer.parseInt(arg[1]);&lt;br /&gt;&lt;br /&gt;int b = Integer.parseInt(arg[2]);&lt;br /&gt;&lt;br /&gt;int result;&lt;br /&gt;&lt;br /&gt;inter i = (inter) Naming.lookup("rmi://" + arg[0] + "/Addserver");&lt;br /&gt;&lt;br /&gt;System.out.println("client");&lt;br /&gt;&lt;br /&gt;i.getdata(a,b);&lt;br /&gt;&lt;br /&gt;result = i.adddata();&lt;br /&gt;&lt;br /&gt;System.out.println(result);&lt;br /&gt;&lt;br /&gt;}catch(Exception e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("error " + e);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;server.java&lt;br /&gt;&lt;br /&gt;vbnm,import java.rmi.*;&lt;br /&gt;&lt;br /&gt;import java.rmi.server.*;&lt;br /&gt;&lt;br /&gt;public class server extends UnicastRemoteObject implements inter&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;int x,y;&lt;br /&gt;&lt;br /&gt;public server() throws RemoteException&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public int adddata() throws RemoteException&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;return x+y;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void getdata(int m, int n) throws RemoteException&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;x=m; y=n;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;server s = new server();&lt;br /&gt;&lt;br /&gt;Naming.rebind("Addserver",s);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;catch(Exception e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;System.out.println("Exception e");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="beans"&gt;&lt;/a&gt;&lt;br /&gt;14. Java Beans&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;&gt;NEXT&gt;&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-3397182117284568084?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/3397182117284568084/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=3397182117284568084' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3397182117284568084'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3397182117284568084'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-20-note_6240.html' title='JAVA 2.0 NOTE'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-6996756060633834178</id><published>2007-12-19T00:08:00.000-08:00</published><updated>2007-12-19T00:14:17.053-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-12'/><title type='text'>JAVA 2.0 NOTE</title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;PREVIOUS&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;br /&gt;&lt;a name="jdbc"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;12. JDBC-ODBC&lt;br /&gt;&lt;br /&gt;JDBC is a set of Java API for executing SQL statements.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Two-Tier Model&lt;/strong&gt;    &lt;br /&gt;&lt;br /&gt;----------------------&lt;br /&gt;&lt;br /&gt;Client Machine&lt;br /&gt;   &lt;br /&gt;&lt;strong&gt;-----------------------&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;DBMS propictary protocol&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Database server&lt;/strong&gt;  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Three-Tier Model&lt;/strong&gt;  &lt;br /&gt;&lt;br /&gt;Client Machine(GUI)&lt;br /&gt;&lt;br /&gt;HTTP, RMI, CORBA&lt;br /&gt;&lt;br /&gt;Server Machine&lt;br /&gt;   &lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;DBMS-proprictary protocol&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Database Server&lt;/strong&gt;  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Two-Tier Model  &lt;/strong&gt;  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In Two-Tier Model, a Java applet or application talks directly to the database. This requires a JDBC driver that can communicate with the particular database management systems accessed. Users SQL statement is delivered to the database and the results of those statements are sent to the user. This is referred to as client/server configuration.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Three-Tier Model&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In this a middle tier is introduced for fast performance. It sends the SQL statements to the databases. The results of the query are send to middle tier, which sends them to user.    &lt;br /&gt;&lt;br /&gt;1. GetConnection( ) of DriverManager class is used to get connection object.&lt;br /&gt;&lt;br /&gt;2. It prepares Statement Object to prepare SQL statement&lt;br /&gt;&lt;br /&gt;3. The method executeQuery( ) is used to obtain ResultSet and the method executeUpdate( ) is used to for deleting, updating or inserting records.&lt;br /&gt;&lt;br /&gt;4. Rollback( ) and commit( ) are used to undo or permanent save the changes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Example :&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;a) Create a data base students in Ms-Access with table student containing the following fields studid number, sname text, course text and marks number.&lt;br /&gt;&lt;br /&gt;Create a datasource studentdsn in ODBC for the above database&lt;br /&gt;&lt;br /&gt;Write the source file , compile and execute it. import java.sql.*;&lt;br /&gt;&lt;br /&gt;class dbappn&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;static connection con;&lt;br /&gt;&lt;br /&gt;public static void main(String a[ ]) throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;class.forName("sun.jdbc.odbc.JdbcOdbcdriver");&lt;br /&gt;&lt;br /&gt;open( );&lt;br /&gt;&lt;br /&gt;select( );&lt;br /&gt;&lt;br /&gt;insert( );&lt;br /&gt;&lt;br /&gt;delete( );&lt;br /&gt;&lt;br /&gt;update( );&lt;br /&gt;&lt;br /&gt;select( );&lt;br /&gt;&lt;br /&gt;close( );&lt;br /&gt;&lt;br /&gt;}static void open( ) throws SQLException&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*con = DriverManger.getConnection("dsn","username","pwd"); */&lt;br /&gt;&lt;br /&gt;con = DriverManager.getConnection("jdbc:odbc:student","palani","kumar");&lt;br /&gt;&lt;br /&gt;con.setAutoCommit(false);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;static void close( ) throws SQLException&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;con.commit( );&lt;br /&gt;&lt;br /&gt;con.close( );&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;static void select( ) throws SQLException&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Statement stmt = con.createStatement( );&lt;br /&gt;&lt;br /&gt;ResultSet rs = stmt.executeQuery("Select * from student");&lt;br /&gt;&lt;br /&gt;Boolean more = rs.next( );&lt;br /&gt;&lt;br /&gt;If (!more)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("No rows found");&lt;br /&gt;&lt;br /&gt;Return ;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;while(more)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("ID " : " + rs.getString("studid"));&lt;br /&gt;&lt;br /&gt;System.out.println("Name : " + rs.getString("sname"));&lt;br /&gt;&lt;br /&gt;System.out.println("Course : " + rs.getstring("course"));&lt;br /&gt;&lt;br /&gt;System.out.println("Marks : " + rs.getString("marks"));&lt;br /&gt;&lt;br /&gt;more = rs.next( );&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;rs.close( );&lt;br /&gt;&lt;br /&gt;stmt.close( );&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;static void insert( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;try{&lt;br /&gt;&lt;br /&gt;Statement stmt = con.createStatement( );&lt;br /&gt;&lt;br /&gt;int rows = stmt.executeUpdate("Insert into student&lt;br /&gt;&lt;br /&gt;values(100, ‘Subash’,’Java’,80)");con.commit( );&lt;br /&gt;&lt;br /&gt;stmt.close( );&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;System.out.println(rows + " row added");&lt;br /&gt;&lt;br /&gt;} catch(SQLException s) { System.out.println("Error"); }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;static void delete( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;try{&lt;br /&gt;&lt;br /&gt;Statement stmt = con.createStatement( );&lt;br /&gt;&lt;br /&gt;int rows = stmt.executeUpdate("Delete from student&lt;br /&gt;&lt;br /&gt;where id = 100;con.commit( );&lt;br /&gt;&lt;br /&gt;stmt.close( );&lt;br /&gt;&lt;br /&gt;System.out.println(rows + " row deleted");&lt;br /&gt;&lt;br /&gt;} catch(SQLException s) { System.out.println("Error"); }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;static void update( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;try{&lt;br /&gt;&lt;br /&gt;Statement stmt = con.createStatement( );&lt;br /&gt;&lt;br /&gt;int rows = stmt.executeUpdate("Update student&lt;br /&gt;&lt;br /&gt;set marks = 90 where id =100 ;con.commit( );&lt;br /&gt;&lt;br /&gt;stmt.close( );&lt;br /&gt;&lt;br /&gt;System.out.println(rows + " row added");&lt;br /&gt;&lt;br /&gt;} catch(SQLException s) { System.out.println("Error"); }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;&gt;NEXT&gt;&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-6996756060633834178?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/6996756060633834178/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=6996756060633834178' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/6996756060633834178'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/6996756060633834178'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-20-note_9571.html' title='JAVA 2.0 NOTE'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-1360012108774132399</id><published>2007-12-19T00:02:00.000-08:00</published><updated>2007-12-19T00:07:39.050-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-11'/><title type='text'>JAVA 2.0 NOTE</title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;PREVIOUS&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;a name="network"&gt;&lt;/a&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;11. Networking in Java&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Java.net package&lt;br /&gt;&lt;br /&gt;The objectives are&lt;br /&gt;&lt;br /&gt;Network Datagram&lt;br /&gt;&lt;br /&gt;Protocol DatagramPacket&lt;br /&gt;&lt;br /&gt;Socket DatagramSocket&lt;br /&gt;&lt;br /&gt;Client/Server TCP/IP&lt;br /&gt;&lt;br /&gt;Internet (IP) Address Socket&lt;br /&gt;&lt;br /&gt;Domain Name Service ServerSocket&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;InetAddress URL        &lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;Network is a set of computers physically connected together. It enables the sharing of computer&lt;br /&gt;pheriperals and resources by different computers.&lt;br /&gt;&lt;br /&gt;The communication between the computers requires certain set of rules called protocols. Some important protocols are TCP/IP, HTTP, FTP, SMTP and NNTP. Port no 21 is for FTP, 23 is for Telnet, 25 is for e-mail and 80 is for HTTP.&lt;br /&gt;&lt;br /&gt;IP is a low-level routing protocol that breaks data into small packets and sends them to an address across a network. TCP is a higher level protocol that manages string together these packets, sorting and retransmitting them to reliably transmit your data. UDP (user Datagram Protocol) can be used to support fast, connectionless, unreliable transport of packets.&lt;br /&gt;&lt;br /&gt;Socket is the place used to plug in just like electric sockets, from the socket the communication starts.&lt;br /&gt;&lt;br /&gt;Client is the machine, which sends some request to another computer. The computer that does the request is called the Server.&lt;br /&gt;&lt;br /&gt;A proxy server speaks the client side of protocol to another server. A client would connect to a proxy server, which have no restrictions, and the proxy server would in turn communicate for the client.&lt;br /&gt;&lt;br /&gt;Every computer connected to the network has unique address it contains four numbers between 0 and 255 separated by period. Ex is 80.0.0.50&lt;br /&gt;&lt;br /&gt;It is very difficult to remember the IP of the computer. To overcome this problem domain name service (DNS) is used. It maps the IP address by string of characters. Ex is &lt;a href="http://www.microsoft.com/"&gt;www.microsoft.com&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;InetAddress is a class, which is used to encapsulate IP address and DNS.&lt;br /&gt;&lt;br /&gt;InetAddress getLoaclHost( ) throws unknowHostException&lt;br /&gt;&lt;br /&gt;InetAddress getByName (String hostName)&lt;br /&gt;&lt;br /&gt;InetAddress getAllByName (String hostName)    &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;URL&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Uniform Resource Locater. It contains four parts protocol, separated by : and //, host name of IP address, port number, file path.&lt;br /&gt;&lt;br /&gt;For ex &lt;a href="http://www.starwave.com/index.html"&gt;http://www.starwave.com/index.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Constructors of URL throws MalformedURLException&lt;br /&gt;&lt;br /&gt;URL (String urlspecifier)&lt;br /&gt;&lt;br /&gt;URL (String protocolName, String hostName, int port,String path)&lt;br /&gt;&lt;br /&gt;URL (String protocolName, String hostName, String path)&lt;br /&gt;&lt;br /&gt;getPort( ), getHost( ),getFile( ) and toExternalForm( )&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To access content information of a URL, use url.openConnection( ) method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Datagrams&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Datagrams are bundles of information passed between machines. It contains two classes&lt;br /&gt;&lt;br /&gt;DatagramPacket for container of data&lt;br /&gt;&lt;br /&gt;DatagramSocket for send or receive the DatagramPacket&lt;br /&gt;&lt;br /&gt;DatagramPacket constructors are&lt;br /&gt;&lt;br /&gt;DatagramPacket (byte data[ ], int size);&lt;br /&gt;&lt;br /&gt;DatagramPacket (byte data[ ], int size, ipAddress, int port);&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Methods of DatagramPacket are&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;InetAddress getAddress( ), int getPort( ) , byte( ) , getData( ) and&lt;br /&gt;&lt;br /&gt;int getLength( )DatagramSocket constructors are&lt;br /&gt;&lt;br /&gt;DatagramSocket.send (DatagramPacket d);&lt;br /&gt;&lt;br /&gt;DatagramSocket.receive (DatagramPacket p);&lt;br /&gt;&lt;br /&gt;client.java&lt;br /&gt;&lt;br /&gt;import java.net.*;&lt;br /&gt;&lt;br /&gt;class client&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static DatagramSocket ds;&lt;br /&gt;&lt;br /&gt;public static byte buffer[] = new byte[1024];&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public static void main(String arg[]) throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;ds = new DatagramSocket(6);&lt;br /&gt;&lt;br /&gt;while(true)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;String a;&lt;br /&gt;&lt;br /&gt;DatagramPacket p = new DatagramPacket(buffer,buffer.length);&lt;br /&gt;&lt;br /&gt;ds.receive(p);&lt;br /&gt;&lt;br /&gt;a=new String(p.getData(),p.getLength(),1);&lt;br /&gt;&lt;br /&gt;if (a.equals("q"))&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("Server response is shut off now");&lt;br /&gt;&lt;br /&gt;return;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;System.out.println(new String(p.getData(),0,p.getLength()));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}                    &lt;br /&gt;server.java&lt;br /&gt;&lt;br /&gt;import java.net.*;&lt;br /&gt;&lt;br /&gt;class server&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static DatagramSocket ds;&lt;br /&gt;&lt;br /&gt;public static byte buffer[] = new byte[1024];&lt;br /&gt;&lt;br /&gt;public static void main(String a[]) throws Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;InetAddress ia = InetAddress.getByName("rad-tm-04");&lt;br /&gt;&lt;br /&gt;System.out.println(ia);&lt;br /&gt;&lt;br /&gt;ds = new DatagramSocket(123);&lt;br /&gt;&lt;br /&gt;int pos=0;&lt;br /&gt;&lt;br /&gt;while(true)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int c = System.in.read();&lt;br /&gt;&lt;br /&gt;switch(c)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;case 'q':&lt;br /&gt;&lt;br /&gt;System.out.println("Server quits");&lt;br /&gt;&lt;br /&gt;return;&lt;br /&gt;&lt;br /&gt;case '\r':&lt;br /&gt;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case '\n':&lt;br /&gt;&lt;br /&gt;ds.send(new DatagramPacket(buffer,pos,ia,456));&lt;br /&gt;&lt;br /&gt;pos=0;&lt;br /&gt;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;default:&lt;br /&gt;&lt;br /&gt;buffer[pos++] = (byte) c;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}      &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;TCP/IP&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;TCP/IP sockets are used to implement reliable, bidirectional, persistent, point to point, stream based connection between hosts on the Internet.&lt;br /&gt;&lt;br /&gt;It contains two classes. They are Socket and ServerSocket. ServerSocket class is designed to wait for clients to connect and Socket class is used to connect to ServerSocket.&lt;br /&gt;&lt;br /&gt;ServerSocket (int port)&lt;br /&gt;&lt;br /&gt;ServerSocket (int port, int maxqu)&lt;br /&gt;&lt;br /&gt;ServerSocket (int port, int maxqu, InetAddress localAddress)&lt;br /&gt;&lt;br /&gt;ServerSocket has a method accept( ) that waits for client to initiate communication.&lt;br /&gt;&lt;br /&gt;Socket (String hostName, int port)&lt;br /&gt;&lt;br /&gt;Socket (InetAddress ipAddress, int port)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt;&gt;&gt;NEXT&gt;&gt;&lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-1360012108774132399?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/1360012108774132399/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=1360012108774132399' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1360012108774132399'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1360012108774132399'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-20-note_19.html' title='JAVA 2.0 NOTE'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-6353142709213717723</id><published>2007-12-18T23:59:00.000-08:00</published><updated>2007-12-19T00:02:01.500-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-10'/><title type='text'>JAVA 2.0 NOTE</title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;PREVIOUS&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;br /&gt;&lt;a name="wrapper"&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;10. Wrapper Classes - java.lang&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;double doubleValue( )&lt;br /&gt;&lt;br /&gt;float floatValue( )&lt;br /&gt;&lt;br /&gt;long longValue( )&lt;br /&gt;&lt;br /&gt;int intValue( )&lt;br /&gt;&lt;br /&gt;String toString( )&lt;br /&gt;&lt;br /&gt;Boolean boleanValue( )&lt;br /&gt;&lt;br /&gt;char charValue( )&lt;br /&gt;&lt;br /&gt;Double and Float&lt;br /&gt;&lt;br /&gt;boolean isNaN( )&lt;br /&gt;&lt;br /&gt;boolean isInfinite( )&lt;br /&gt;&lt;br /&gt;boolean equals(object obj)&lt;br /&gt;&lt;br /&gt;int hashCode( )&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Integer&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;static int parseInt(String str) throws NumberFormatException&lt;br /&gt;&lt;br /&gt;static String toHexString(int num)&lt;br /&gt;&lt;br /&gt;static String toOctalString(int num)&lt;br /&gt;&lt;br /&gt;static Integer valueOf(String str) throws NumberFormatException&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Character&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;isDigit( )&lt;br /&gt;&lt;br /&gt;isLetter( )&lt;br /&gt;&lt;br /&gt;isUpperCase( )&lt;br /&gt;&lt;br /&gt;isLowerCase( )&lt;br /&gt;&lt;br /&gt;toLowerCase( )&lt;br /&gt;&lt;br /&gt;toUpperCase( )&lt;br /&gt;&lt;br /&gt;toTitleCase( )&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Process&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;void destroy( )&lt;br /&gt;&lt;br /&gt;int exitValue( )&lt;br /&gt;&lt;br /&gt;InputStream getErrorStream( )&lt;br /&gt;&lt;br /&gt;InputStream getInputStream( )&lt;br /&gt;&lt;br /&gt;OutputStream getOutputStream( )    &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Runtime &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;process exec(String progName) throws IOException&lt;br /&gt;&lt;br /&gt;long freeMemory( )&lt;br /&gt;&lt;br /&gt;void gc( )&lt;br /&gt;&lt;br /&gt;static Runtime getRuntime( )&lt;br /&gt;&lt;br /&gt;long totalMemory( )&lt;br /&gt;&lt;br /&gt;void runFinalization( )&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;System&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;static void arraycopy(Object source, int sstart, object target, int tstart, int size);&lt;br /&gt;&lt;br /&gt;static void gc( )&lt;br /&gt;&lt;br /&gt;static void load(String librayfileName)&lt;br /&gt;&lt;br /&gt;void runFinalization( )&lt;br /&gt;&lt;br /&gt;static long currentTimeMillis( )&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Object&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;Object clone( ) throws CloneNotsupportedException&lt;br /&gt;&lt;br /&gt;boolean equals(Object obj)&lt;br /&gt;&lt;br /&gt;void finalize( ) throws Throwable&lt;br /&gt;&lt;br /&gt;int hashCode( )&lt;br /&gt;&lt;br /&gt;int notify( )&lt;br /&gt;&lt;br /&gt;int notifyAll( )&lt;br /&gt;&lt;br /&gt;final void wait( ) throws InterruptedException&lt;br /&gt;&lt;br /&gt;string toString( )&lt;br /&gt;&lt;br /&gt;final Class getClass( )    &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Class&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;static Class forName(String name) throws ClassNotFoundException&lt;br /&gt;&lt;br /&gt;string getName( )&lt;br /&gt;&lt;br /&gt;Class getSuperclass( )&lt;br /&gt;&lt;br /&gt;boolean isInterface( )&lt;br /&gt;&lt;br /&gt;ClassLoader getClassLoader( )&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Math&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;Transcendental sin(d) cos(d) tan(d)&lt;br /&gt;&lt;br /&gt;Exponential exp(d) log(d ) pow(d1,d2) sqrt(d)&lt;br /&gt;&lt;br /&gt;Rounding abs(I) ceil(d) floor(d) max(x,y) min(x,y) round(f)    &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Thread&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;Thread( )&lt;br /&gt;&lt;br /&gt;Thread(ThreadGroup grp,Runnable threadob, String Thname)&lt;br /&gt;&lt;br /&gt;void destroy( ) interrupt( ) stop( ) yield( ) start( ) run( ) resume( ) list( )&lt;br /&gt;&lt;br /&gt;static Thread currentThread( )&lt;br /&gt;&lt;br /&gt;final boolean isAlive( )&lt;br /&gt;&lt;br /&gt;static boolean interrupted( )    &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;ThreadGroup &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;ThreadGroup(String name)&lt;br /&gt;&lt;br /&gt;ThreadGroup(ThreadGroup ob,String name)&lt;br /&gt;&lt;br /&gt;final ThreadGroup getParent( )  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;NEXT&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-6353142709213717723?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/6353142709213717723/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=6353142709213717723' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/6353142709213717723'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/6353142709213717723'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-20-note_1856.html' title='JAVA 2.0 NOTE'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-2182226270649273606</id><published>2007-12-18T23:49:00.000-08:00</published><updated>2007-12-18T23:57:13.594-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-9'/><title type='text'>JAVA 2.0 NOTE</title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&gt;&gt;PREVIOUS&gt;&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;&lt;strong&gt;&lt;span style="font-size:180%;"&gt;9. APPLET&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;a name="applet"&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Applet &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An applet is a dynamic and interactive program that can run inside Web page displayed by a Java-capable browser or applet viewer.&lt;br /&gt;All applets are subclasses of Applet. You should import java.applet and java.awt since all applets run in a window. Applet defines three interfaces Appletcontext, AppletStub and AudioClip.&lt;br /&gt;&lt;br /&gt;/* &lt;applet code="classname.class" width="400" height="100"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/applet&gt;&lt;br /&gt;&lt;br /&gt;*/    &lt;br /&gt;&lt;br /&gt;Applet extends java AWT class Panel, Panel extends Container which extends Component.    &lt;br /&gt;&lt;br /&gt;The init( ) Method&lt;br /&gt;&lt;br /&gt;This method gets called as soon an applet is started. Initialization of all variables, creation of objects, setting of parameters, etc. can be done in this method.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The start( ) method&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;This method is executed after the init mehod. Also used to restart the applet that was stoped.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The stop( ) method &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This method is used to halt the running of an applet. This method is called when a web browser leaves the HTML document containing the applet.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The destroy( ) method&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;This method is used to free the memory occupied by the variables and objects initialized in the&lt;br /&gt;applet. Called by the browser just before the applet is terminated.    &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The paint( ) method&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;This method helps in drawing, writing and creating a colored background or an image on to the applet. This method is called each time your applet’s output must be redrawn. It has one parameter called Graphics.        &lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;The repaint( ) method&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This method is used in case an applet is to be repainted. The repaint method calls update( ) method to clear screen and paint( ) method to redraw the contents of the current frame.    &lt;br /&gt;&lt;br /&gt;resize (width, height)&lt;br /&gt;&lt;br /&gt;Resize the applet window&lt;br /&gt;&lt;br /&gt;showStatus (str)&lt;br /&gt;&lt;br /&gt;Displays the string in the status window of the applet    &lt;br /&gt;&lt;br /&gt;When starting the applet init, start, paint methods and when terminating stop and destroy&lt;br /&gt;methods are called.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;9.a. The Graphics Class in java.awt package&lt;br /&gt;&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;drawString(message,x,y);    &lt;br /&gt;&lt;br /&gt;drawLine (x1,y1,x2,y2);&lt;br /&gt;&lt;br /&gt;drawRect (x1,y1,width,height)&lt;br /&gt;&lt;br /&gt;drawRoundRect (x1,y1,width,height,width1,height1)&lt;br /&gt;&lt;br /&gt;draw3Drect (x1,y1,width,height,boolean)&lt;br /&gt;&lt;br /&gt;drawPolygon (xs,ys,pts)&lt;br /&gt;&lt;br /&gt;drawOval (x1,y1,width,height)&lt;br /&gt;&lt;br /&gt;drawArc (x1,y1,widht,height,angle1,angle2)&lt;br /&gt;&lt;br /&gt;fillRect (x1,y1,width,height)&lt;br /&gt;&lt;br /&gt;fillRoundRect (x1,y1,width,height,width1,height1)&lt;br /&gt;&lt;br /&gt;fillPloygon (xs,ys,pts)&lt;br /&gt;&lt;br /&gt;fillOval (x1,y1,width,height)&lt;br /&gt;&lt;br /&gt;fillArc (x1,y1,widht,height,angle1,angle2)        &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;9.b. Font Class in java.awt package&lt;br /&gt;&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;Font f = new Font ("fontname", format, size);&lt;br /&gt;&lt;br /&gt;Formats are Font.BOLD, Font.ITALIC, and Font.PLAIN&lt;br /&gt;&lt;br /&gt;g.setFont(f)    &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;9.c. Color Class in java.awt package&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;Color.grey, Color.green, Color.yellow, Color.pink, Color.red, Color.blue, Color.magenta,&lt;br /&gt;Color.cyan    &lt;br /&gt;&lt;br /&gt;setColor (color)&lt;br /&gt;&lt;br /&gt;getColor (color)&lt;br /&gt;&lt;br /&gt;setBackground (color)&lt;br /&gt;&lt;br /&gt;getBackground (color)&lt;br /&gt;&lt;br /&gt;setForeground (color)&lt;br /&gt;&lt;br /&gt;getForeground (color)  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;9.d. Images    &lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;getImage (URL,string)&lt;br /&gt;&lt;br /&gt;drawImage (Image,x,y,imageObserver)&lt;br /&gt;&lt;br /&gt;to find URL&lt;br /&gt;&lt;br /&gt;getCodeBase ( ) can be used&lt;br /&gt;&lt;br /&gt;To create image&lt;br /&gt;&lt;br /&gt;createImage (width,height)&lt;br /&gt;&lt;br /&gt;getGraphics ( )  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Clipping&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;A technique by which the drawing area can be restricted to a small portion of the screen.&lt;br /&gt;&lt;br /&gt;Method is clipRect( )&lt;br /&gt;&lt;br /&gt;clipRect(x1,y1,x2,y2);  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Animation&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Animation is technique by the object is moved on the screen In which the original image is&lt;br /&gt;clreared and placed in another place.  &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;9.e. Events&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Mouse Events methods    &lt;br /&gt;&lt;br /&gt;boolean mouseDown(event , x, y)&lt;br /&gt;&lt;br /&gt;boolean mouseDrag(event , x, y)&lt;br /&gt;&lt;br /&gt;boolean mouseEnter(event , x, y)&lt;br /&gt;&lt;br /&gt;boolean mouseExit(event , x, y)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;boolean mouseMove(event , x, y)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;boolean mouseUp(event , x, y)&lt;br /&gt;&lt;br /&gt;boolean mouseDown(event , x, y)&lt;br /&gt;&lt;br /&gt;boolean mouseDown(event , x, y)    &lt;br /&gt;&lt;br /&gt;KeyBoard Events&lt;br /&gt;&lt;br /&gt;boolean keyDown(event , x, y)&lt;br /&gt;&lt;br /&gt;boolean keyUp(event , x, y)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Types of Event handling&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;a)Low Level event&lt;br /&gt;&lt;br /&gt;Low level classes Low level event Listener&lt;br /&gt;&lt;br /&gt;ComponentEvent ComponentListener&lt;br /&gt;&lt;br /&gt;FocusEvent FocusListener&lt;br /&gt;&lt;br /&gt;KeyEvent KeyListener&lt;br /&gt;&lt;br /&gt;ContainerEvent ContainerListener&lt;br /&gt;&lt;br /&gt;MouseEvent MouseListener&lt;br /&gt;&lt;br /&gt;MouseMotionListener&lt;br /&gt;&lt;br /&gt;WindowEvent WindowListener&lt;br /&gt;&lt;br /&gt;InputEvent&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;b) Semantic Events&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Low level classes Low level event Listener&lt;br /&gt;&lt;br /&gt;ActionEvent ActionListener&lt;br /&gt;&lt;br /&gt;AdjustmentEvent AdjustmentListener&lt;br /&gt;&lt;br /&gt;ItemEvent ItemListener&lt;br /&gt;&lt;br /&gt;TextEvent TextListener      &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Example: &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;mport java.awt.event.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;public class mousetest extends Applet implements MouseListener&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void init( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;addMouseListener(this);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void mouseClicked(MouseEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;showStatus("Mouse clicked at " + e.getX( ) +" , " + e.getY( ));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Write above code for other mouse events&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Each component class in the AWT has one addXXXListener( ) method for each event type.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;9.f. ABSTRACT WINDOW TOOLKIT (AWT)  &lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;&lt;a name="thread"&gt;&lt;/a&gt;Component Contructor Methods&lt;br /&gt;&lt;br /&gt;Button&lt;br /&gt;&lt;br /&gt;Button( ) setLabel(String)&lt;br /&gt;&lt;br /&gt;Button("label") getLabel( )&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Label&lt;br /&gt;&lt;br /&gt;Label( ) getText( )&lt;br /&gt;&lt;br /&gt;Label(String) setText(String)&lt;br /&gt;&lt;br /&gt;Label(String, int) getAlignment( )&lt;br /&gt;&lt;br /&gt;SetAlignment(int)&lt;br /&gt;&lt;br /&gt;where Int is alignment. It may be Label.LEFT, Label.RIGHT, Label.CENTER    &lt;br /&gt;&lt;br /&gt;Checkbox&lt;br /&gt;&lt;br /&gt;Checkbox( ) setLabel(string)&lt;br /&gt;&lt;br /&gt;Checkbox(String) getLabel( )&lt;br /&gt;&lt;br /&gt;Checkbox(String,grp,boolean) setState(boolean)&lt;br /&gt;&lt;br /&gt;getLabel( )&lt;br /&gt;&lt;br /&gt;Choice&lt;br /&gt;&lt;br /&gt;Choice( ) getItem(int)&lt;br /&gt;&lt;br /&gt;addItem(String) getItemcount( )&lt;br /&gt;&lt;br /&gt;getSelectedItem( )&lt;br /&gt;&lt;br /&gt;getSelectedIndex( )&lt;br /&gt;&lt;br /&gt;TextComponent&lt;br /&gt;&lt;br /&gt;TextField( ) getText( )&lt;br /&gt;&lt;br /&gt;TextField(String, int) setText(String)&lt;br /&gt;&lt;br /&gt;TextArea( )&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;TextArea(String, int, int) int represents rows and columns&lt;br /&gt;&lt;br /&gt;List&lt;br /&gt;&lt;br /&gt;List( ) getItem(int) int starts from 0&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;List(int,boolean) getItemCount( )&lt;br /&gt;&lt;br /&gt;AddItem(String) select(int)&lt;br /&gt;&lt;br /&gt;getSelectedItem( )&lt;br /&gt;&lt;br /&gt;Scrollbar&lt;br /&gt;&lt;br /&gt;Scrollbar( ) setValue(int)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Scrollbar(orient, value, visible, min, max) getValue( )        &lt;br /&gt;&lt;br /&gt;Layout Manger&lt;br /&gt;&lt;br /&gt;A set of classes used to position the components in a container.    &lt;br /&gt;&lt;br /&gt;FlowLayout&lt;br /&gt;&lt;br /&gt;BorderLayout&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;GridLayout First create instantiate a layout manager class and use setLayout( ) method&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Flow Layout&lt;br /&gt;&lt;br /&gt;Lays components linewise from left to right&lt;br /&gt;&lt;br /&gt;FlowLayout( )&lt;br /&gt;&lt;br /&gt;FlowLayout(align, hgap, vgap)&lt;br /&gt;&lt;br /&gt;Align – FlowLayout.LEFT, FlowLayout.RIGHT, FlowLayout..CENTER&lt;br /&gt;&lt;br /&gt;Grid Layout&lt;br /&gt;&lt;br /&gt;Position the components in the cellf of the grid.&lt;br /&gt;&lt;br /&gt;GridLayout(int rwo, int col)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;GridLayout( int rwo, int col, int hgap, int vgap)&lt;br /&gt;&lt;br /&gt;Border Layout&lt;br /&gt;&lt;br /&gt;Lays components relative to the edges of the container&lt;br /&gt;BorderLayout( )&lt;br /&gt;&lt;br /&gt;BorderLayout(int hgap, int vgap)&lt;br /&gt;&lt;br /&gt;add("direction",item);&lt;br /&gt;&lt;br /&gt;direction may be NORTH, SOUTH,EAST , WEST or CENTER&lt;br /&gt;&lt;br /&gt;Insets(int, int, int, int)&lt;br /&gt;&lt;br /&gt;Used to give spacing around the container        &lt;br /&gt;&lt;br /&gt;Panel&lt;br /&gt;&lt;br /&gt;A panel class is a non-abstract, recursively nestable container.&lt;br /&gt;&lt;br /&gt;Panel( )  &lt;br /&gt;&lt;a name="menus"&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;9.g. Frames, Menus and Dialogs&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;Frame&lt;br /&gt;&lt;br /&gt;Inherited from Frame class&lt;br /&gt;&lt;br /&gt;Frame( )&lt;br /&gt;&lt;br /&gt;Frame(String)    &lt;br /&gt;&lt;br /&gt;Methods&lt;br /&gt;&lt;br /&gt;setVisible(boolean)&lt;br /&gt;&lt;br /&gt;setSize(Dim)&lt;br /&gt;&lt;br /&gt;setLocation(int,int) getLocation( )&lt;br /&gt;&lt;br /&gt;dispose()&lt;br /&gt;&lt;br /&gt;setTitle(String) getTitle( )    &lt;br /&gt;Menus    &lt;br /&gt;&lt;br /&gt;Menubar( )&lt;br /&gt;&lt;br /&gt;Menu(String)&lt;br /&gt;&lt;br /&gt;MenuItem(String)&lt;br /&gt;&lt;br /&gt;CheckboxMenuItem(String)&lt;br /&gt;&lt;br /&gt;SetState(boolean) getState( )&lt;br /&gt;&lt;br /&gt;menu.add(MenuItem)&lt;br /&gt;&lt;br /&gt;menubar.add(menu)&lt;br /&gt;&lt;br /&gt;Frame.setMenubar(menubar)&lt;br /&gt;&lt;br /&gt;Dialog&lt;br /&gt;&lt;br /&gt;Dialog(Frame,boolean)&lt;br /&gt;&lt;br /&gt;Dialog(Frame,String,boolean)&lt;br /&gt;&lt;br /&gt;setResizable(boolean)&lt;br /&gt;&lt;br /&gt;isModal( )&lt;br /&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;import java.applet.*;&lt;br /&gt;&lt;br /&gt;class fram extends Frame&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;String msg=" ";&lt;br /&gt;&lt;br /&gt;fram()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;super("Menu Frame");&lt;br /&gt;&lt;br /&gt;MenuBar mb = new MenuBar();&lt;br /&gt;&lt;br /&gt;Menu m1 = new Menu("File");&lt;br /&gt;Menu m2 = new Menu("Edit");&lt;br /&gt;&lt;br /&gt;MenuItem mi1 = new MenuItem("Open");&lt;br /&gt;&lt;br /&gt;MenuItem mi2 = new MenuItem("Save");&lt;br /&gt;&lt;br /&gt;MenuItem mi3 = new MenuItem("Copy");&lt;br /&gt;MenuItem mi4 = new MenuItem("Paste");&lt;br /&gt;&lt;br /&gt;m1.add(mi1);&lt;br /&gt;&lt;br /&gt;m1.add(mi2);&lt;br /&gt;&lt;br /&gt;m2.add(mi3);&lt;br /&gt;&lt;br /&gt;m2.add(mi4);&lt;br /&gt;&lt;br /&gt;mb.add(m1);&lt;br /&gt;&lt;br /&gt;mb.add(m2);&lt;br /&gt;&lt;br /&gt;setMenuBar(mb);&lt;br /&gt;winadapt w = new winadapt(this);&lt;br /&gt;&lt;br /&gt;addWindowListener(w);&lt;br /&gt;&lt;br /&gt;mnuhandler handler = new mnuhandler(this);&lt;br /&gt;&lt;br /&gt;mi1.addActionListener(handler);&lt;br /&gt;&lt;br /&gt;mi2.addActionListener(handler);&lt;br /&gt;&lt;br /&gt;mi3.addActionListener(handler);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;public void paint(Graphics g)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;g.drawString(msg,100,100);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;class mnuhandler implements ActionListener&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;fram f1;&lt;br /&gt;&lt;br /&gt;public mnuhandler(fram f2)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;f1 = f2;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void actionPerformed(ActionEvent ae)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;String msg;&lt;br /&gt;&lt;br /&gt;String s = (String) ae.getActionCommand();&lt;br /&gt;&lt;br /&gt;if(s.equals("Open"))&lt;br /&gt;&lt;br /&gt;msg = "Open";&lt;br /&gt;&lt;br /&gt;else if(s.equals("Save"))&lt;br /&gt;msg ="Save";&lt;br /&gt;&lt;br /&gt;else if(s.equals("Copy"))&lt;br /&gt;&lt;br /&gt;msg = "Copy";&lt;br /&gt;&lt;br /&gt;else&lt;br /&gt;&lt;br /&gt;msg = "Paste";&lt;br /&gt;&lt;br /&gt;msg = msg +" selected";&lt;br /&gt;&lt;br /&gt;f1.msg=msg;&lt;br /&gt;&lt;br /&gt;f1.repaint();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}    &lt;br /&gt;&lt;br /&gt;class winadapt extends WindowAdapter&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;fram f1;&lt;br /&gt;public winadapt(fram f2)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;f1 = f2;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void windowClosing(WindowEvent e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;f1.dispose();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class frammenu extends Applet&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Frame f;&lt;br /&gt;public void init()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;f = new fram();&lt;br /&gt;&lt;br /&gt;f.setSize(300,300);&lt;br /&gt;&lt;br /&gt;f.setVisible(true);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;&gt;NEXT&gt;&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-2182226270649273606?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/2182226270649273606/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=2182226270649273606' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/2182226270649273606'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/2182226270649273606'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-20-note_9826.html' title='JAVA 2.0 NOTE'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-1437882312150831477</id><published>2007-12-18T23:37:00.000-08:00</published><updated>2007-12-18T23:48:57.342-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-8'/><title type='text'>JAVA 2.0 NOTE</title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&gt;&gt;previous&gt;&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;8. &lt;/span&gt;&lt;/strong&gt;&lt;/em&gt;&lt;a name="Multhithreading in Java"&gt;&lt;/a&gt;&lt;em&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Multhithreading in Java&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;strong&gt;Thread&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;A process is a program in a execution. A thread is a line of execution. Two or more processes running concurrently in a computer is called multitasking. The process can contain multiple threads to execute its different sections. This is called multhreading. Using this, we can run different parts of the programs at a time.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;States of thread&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;There are four states of thread. They are new, runnable, blocked and dead The fig shows the states of the thread.&lt;br /&gt;&lt;br /&gt;start( ) suspend( )/wait( ) / sleep( )&lt;br /&gt;&lt;br /&gt;resume( )&lt;br /&gt;&lt;br /&gt;stop( ) run( ) stop( )&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Adv of thread:&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;1. Can be created faster&lt;br /&gt;&lt;br /&gt;2. Maximum use CPU time&lt;br /&gt;&lt;br /&gt;3. Requires less overhead&lt;br /&gt;&lt;br /&gt;4. Interprocess communication is faster&lt;br /&gt;&lt;br /&gt;Context switching is faster.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Thread is created by&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;a) the class Thread which has the interface Runnable.&lt;br /&gt;&lt;br /&gt;b) creating the objects of the class Thread&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;a) Using runnable interface&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;class c1 implements Runnable&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;} To create a thread&lt;br /&gt;&lt;br /&gt;Thread t = new Thread(this) ;&lt;br /&gt;&lt;br /&gt;Thread t = new Thread(this,"Demo thread’);&lt;br /&gt;&lt;br /&gt;Where this referes the Applet object.&lt;br /&gt;&lt;br /&gt;After thread is created , it will first execute start( ) method then run( ) method is automaticall&lt;br /&gt;called.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;b) Creating Thread Class Objects&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;class c1 extends Thread&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Thread&lt;br /&gt;&lt;br /&gt;Thread(Runnable, String)Thread(ThreadGroup, Runnable, String)&lt;br /&gt;&lt;br /&gt;ThreadGroup&lt;br /&gt;&lt;br /&gt;ThreadGroup(String name)&lt;br /&gt;&lt;br /&gt;ThreadGroup(ThreadGroup ob,String name) Example:&lt;br /&gt;&lt;br /&gt;class thread1 implements Runnable&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Thread t = new Thread(this,"test thread") ;&lt;br /&gt;&lt;br /&gt;System.out.println("Child thread : " + t) ;&lt;br /&gt;&lt;br /&gt;t.start( ) ;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void run( )&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;try{&lt;br /&gt;&lt;br /&gt;for(int I=5; I&gt;0; I--)&lt;br /&gt;&lt;br /&gt;{ System.out.println("child thread"+I);&lt;br /&gt;&lt;br /&gt;Thread.sleep(500);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;} catch(InterruptedException e) { }&lt;br /&gt;&lt;br /&gt;System.out.println("exiting child thread");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void main(String g[ ])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;thread1 th = new thread1( );&lt;br /&gt;&lt;br /&gt;try{&lt;br /&gt;&lt;br /&gt;for(int j=5;j&gt;0;j--)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("Main thread : "+ j);Thread.sleep(1000);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;} catch (InterruptedException e) { }&lt;br /&gt;&lt;br /&gt;System.out.println("Main thread exiting …");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Creating Thread extends Thread class&lt;br /&gt;&lt;br /&gt;class thread2 extends Thread&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;thread2( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;super("test thread") ;&lt;br /&gt;&lt;br /&gt;System.out.println("Child thread : " + this) ;&lt;br /&gt;&lt;br /&gt;start( ) ;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void run( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;try{&lt;br /&gt;&lt;br /&gt;for(int I=5; I&gt;0; I--)&lt;br /&gt;&lt;br /&gt;{ System.out.println("child thread"+I);&lt;br /&gt;&lt;br /&gt;Thread.sleep(500);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;} catch(InterruptedException e) { }&lt;br /&gt;&lt;br /&gt;System.out.println("exiting child thread");&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void main(String g[ ])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;new thread2( );&lt;br /&gt;&lt;br /&gt;try{&lt;br /&gt;&lt;br /&gt;for(int j=5;j&gt;0;j--)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("Main thread : "+ j);Thread.sleep(1000);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;} catch (InterruptedException e) { }&lt;br /&gt;&lt;br /&gt;System.out.println("Main thread exiting …");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Runnable abstracts a unit of executable code. We can construct a thread on any object that&lt;br /&gt;implements Runnable.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The thread methods are start( ), resume( ), sleep( ), suspend( ) , join( ) and toString( )&lt;br /&gt;&lt;br /&gt;.&lt;br /&gt;Synchronization&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Two or more threads accessing the same data simultaneously may lead to loss of data integrity.&lt;br /&gt;Java uses the concept of monitor. A monitor is an object, used as a mutually exclusive lock.&lt;br /&gt;&lt;br /&gt;Java offers interprocess communication through the use of wait( ), notify( ) and notifyall( )&lt;br /&gt;methods of Object class and all are synchronized methods.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Thread Priorities&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The usage of setPriority( ) and getPriority( ) methods are used to set and get the priorities of&lt;br /&gt;thread respectively. The yield( ) method enables provision of CPU’s time to threads with equal priority and prevents monopolization of a single thread. The Thread has final variables declared line – NORM_PRIORITY (5), MINIMUM_PRIORITY (1) and MAXIMUM_PRIORITY (10).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;&gt;NEXT&gt;&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-1437882312150831477?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/1437882312150831477/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=1437882312150831477' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1437882312150831477'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1437882312150831477'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-20-note_4367.html' title='JAVA 2.0 NOTE'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-3655462349167694043</id><published>2007-12-18T23:33:00.000-08:00</published><updated>2007-12-26T00:53:37.211-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-7'/><title type='text'>JAVA 2.0 NOTE</title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/2007/12/java-20-note.html"&gt;&gt;&gt;&gt;PREVIOUS&gt;&gt;&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;7. &lt;/span&gt;&lt;/strong&gt;&lt;a name="Input Output in Java"&gt;&lt;/a&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Input/Output in Java&lt;/span&gt; &lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;Input&lt;br /&gt;&lt;br /&gt;int read( ) throws IOException&lt;br /&gt;&lt;br /&gt;final String readLine( ) throws IOException&lt;br /&gt;&lt;br /&gt;int n = System.out.read( );&lt;br /&gt;&lt;br /&gt;String str = inData.readLine( );&lt;br /&gt;&lt;br /&gt;Here DataInputStream inData = new DataInputStream (System.in);&lt;br /&gt;&lt;br /&gt;Output&lt;br /&gt;&lt;br /&gt;System.out.println( );&lt;br /&gt;&lt;br /&gt;System.out.print( );&lt;br /&gt;&lt;br /&gt;System.out.write (int byte); - console output&lt;br /&gt;&lt;br /&gt;Reading and Writing files&lt;br /&gt;&lt;br /&gt;It throws IOException&lt;br /&gt;&lt;br /&gt;FileInputStream fin = new FileInputStream(filename);&lt;br /&gt;&lt;br /&gt;int fin.read( ) - to read a char from a file&lt;br /&gt;&lt;br /&gt;void fin.close( ) - to close a file&lt;br /&gt;&lt;br /&gt;FileOutputStream fout = new FileOutputStream(filename);&lt;br /&gt;&lt;br /&gt;void fout.write(int I);&lt;br /&gt;&lt;br /&gt;fout.close( );&lt;br /&gt;&lt;br /&gt;String Methods :&lt;br /&gt;String s = new String( );&lt;br /&gt;&lt;br /&gt;char chars[ ] { ‘a’, ‘b’, ‘c’);&lt;br /&gt;&lt;br /&gt;String s1 new String(chars);&lt;br /&gt;&lt;br /&gt;Int s.length( )&lt;br /&gt;&lt;br /&gt;boolean s.equals(s1)&lt;br /&gt;&lt;br /&gt;String s.substring(int,int) ;&lt;br /&gt;&lt;br /&gt;char s.charAt(int);&lt;br /&gt;&lt;br /&gt;String toString(object);&lt;br /&gt;&lt;br /&gt;String s.replace(char,char);&lt;br /&gt;&lt;br /&gt;String s.trim( );&lt;br /&gt;&lt;br /&gt;String s.toLowerCase( );&lt;br /&gt;&lt;br /&gt;String s.toUpperCase( );&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/2007/12/java-20-note_4367.html"&gt;&gt;&gt;&gt;NEXT&gt;&gt;&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-3655462349167694043?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/3655462349167694043/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=3655462349167694043' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3655462349167694043'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3655462349167694043'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-20-note_18.html' title='JAVA 2.0 NOTE'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-8921403703411662037</id><published>2007-12-18T23:22:00.000-08:00</published><updated>2007-12-26T00:44:37.986-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-6'/><title type='text'>JAVA 2.0 NOTE</title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;a href="http://java4interview.blogspot.com/2007/12/5.html"&gt;&lt;strong&gt;&gt;&gt;&gt;PREVIOUS&gt;&gt;&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="Package"&gt;&lt;/a&gt;&lt;strong&gt;&lt;span style="font-size:180%;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="font-size:180%;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#cc0000;"&gt;&lt;strong&gt;&lt;span style="font-size:180%;"&gt;6. Package&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Package contains set of classes in order to ensure that class names are unique. Packages are container of classes used to keep the class name space compartmentalized.&lt;br /&gt;&lt;br /&gt;1.Create a subdirectory, which has the same name as package.&lt;br /&gt;&lt;br /&gt;2. Include package command, along with the package name, as first statement in the program.&lt;br /&gt;&lt;br /&gt;3. Write class declaration&lt;br /&gt;&lt;br /&gt;4. Save file in this directory as "name of class.java"&lt;br /&gt;&lt;br /&gt;5. Compile this file using javac.&lt;br /&gt;&lt;br /&gt;6. To use this program set the CLASSPATH or change to previous directory and use java packname.classname&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If package is created, then we can import all classes in the package by&lt;br /&gt;&lt;br /&gt;Import packname.*; or particular class by&lt;br /&gt;&lt;br /&gt;Import packname.classname;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Example 18 :&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;package pack;&lt;br /&gt;&lt;br /&gt;public class class1&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void greet( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println ("Hello");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;save above in file class1.java in the directory pack.&lt;br /&gt;&lt;br /&gt;Import pack.*;&lt;br /&gt;&lt;br /&gt;class importer&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String s[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;class1.greet( );&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;save it as importer.java in the previous to pack directory and execute it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If Java source file contain package, interface, classes then the order should be&lt;br /&gt;&lt;br /&gt;1.A single package statement (optional)&lt;br /&gt;&lt;br /&gt;2. Any number of import statements (optional)&lt;br /&gt;&lt;br /&gt;3. A single public class declaration (required)&lt;br /&gt;&lt;br /&gt;4. Any number of classes private to the package (optional) &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#990000;"&gt;6. Interfaces :&lt;/span&gt;&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;An &lt;a href="http://java4interview.blogspot.com/"&gt;interface&lt;/a&gt; is a collection of abstract behavior that individual classes can implement. An&lt;br /&gt;interface consists of set of method collections. Using interface, you can specify what a class must do but not how it does it. All methods and final variables in interface must be public.&lt;br /&gt;Multithreading is not available in Java. To overcome this problem, interface is introduced.&lt;br /&gt;&lt;br /&gt;access interface name&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;returntype mehodname(para);&lt;br /&gt;&lt;br /&gt;type final-variable=value;}&lt;br /&gt;&lt;br /&gt;access is either public or default.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Example 19:&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;public interface address&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void add(String add);&lt;br /&gt;&lt;br /&gt;public void name(String name);}&lt;br /&gt;&lt;br /&gt;class A implements address&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void add(String a)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("Inside implemented method");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void name(String n)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("Inside implemented method");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void disp( )&lt;br /&gt;&lt;br /&gt;{ System.out.println("Method of class A");}&lt;br /&gt;&lt;br /&gt;public static void main(String a[ ])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;A a = new A( );&lt;br /&gt;&lt;br /&gt;System.out.println("Inside main of class A which implements&lt;br /&gt;&lt;br /&gt;address interface");a.disp( );&lt;br /&gt;&lt;br /&gt;a.name("swathi");&lt;br /&gt;&lt;br /&gt;a.add("3,sivan koil st");&lt;br /&gt;&lt;br /&gt;System.out.println("==============");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;/p&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/2007/12/java-20-note_18.html"&gt;&gt;&gt;&gt;NEXT&gt;&gt;&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-8921403703411662037?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/8921403703411662037/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=8921403703411662037' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/8921403703411662037'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/8921403703411662037'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-20-note.html' title='JAVA 2.0 NOTE'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-2947812393464513975</id><published>2007-12-18T23:16:00.000-08:00</published><updated>2007-12-26T00:37:08.243-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-5'/><title type='text'></title><content type='html'>&lt;em&gt;&lt;/em&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/2007/12/java-2_18.html"&gt;&gt;&gt;&gt;PREVIOUS&gt;&gt;&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="Exception"&gt;&lt;/a&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="font-size:130%;"&gt;5. Exception &lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;An exception is an abnormal condition or error that occurs during the execution of the program. Exception in java is handled by five keywords – try, catch, finally, throw and throws.&lt;br /&gt;The object class has a subclass called Throwable to handle exception and errors, which has two subclasses Exception and &lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Error&lt;/a&gt;&lt;/strong&gt;.&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;The classes of exception are IOException and RuntimeExveption&lt;br /&gt;&lt;br /&gt;The try and catch fixes the error and prevents the program from terminating abruptly. The finally block will be executed if no catch matches it and always executed. If you use try block, finnaly block or atleast one catch block should be used.&lt;br /&gt;&lt;br /&gt;If you don't want to use try and catch statements then use throws clause. The throws class is responsible to handle the different types of exceptions generated by the program. This clause usually contains a list of types of exceptions that are likely to occur in that program.&lt;br /&gt;The throw clause is used to call exception explicitly. User defined exception can be called by throw clause. User defined exception is created by extending the class Exception.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Examples for simple catch statements&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#993300;"&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Example 14 :&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;class exc4&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String args[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;try{&lt;br /&gt;&lt;br /&gt;int a[5]; a[12]=33;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;catch(ArrayIndexOutOfBoundsException a)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;a[1]=33;&lt;br /&gt;&lt;br /&gt;}System.out.println("After catch/try block");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#003300;"&gt;&lt;strong&gt;Example multiple catch statements If you pass any arguments to main then, second error occur &lt;/strong&gt;&lt;strong&gt;or division by zero will occur. finally is always called. &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Example 15:&lt;br /&gt;&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;class except&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;static void proca(int v)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int k[4];&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println(10/v);&lt;br /&gt;&lt;br /&gt;System.out.println("Inside proca");&lt;br /&gt;&lt;br /&gt;K[10] =2;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;catch(ArithmeticException e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("division by zero");}catch(Exception e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("other than arithmetic exception");}&lt;br /&gt;&lt;br /&gt;finally&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("finaly Exceptin is caught");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void main(String a[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int l = a.length;&lt;br /&gt;&lt;br /&gt;proca(l);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Example to use throws clause.&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Example 16 :&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;class ThrowsException&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String s[ ]) throws ArithmeticException&lt;br /&gt;&lt;br /&gt;{System.out.println("Inside main") ;&lt;br /&gt;&lt;br /&gt;int j = 40/0;&lt;br /&gt;&lt;br /&gt;System.out.println("This stt is not printed");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#006600;"&gt;Example for user defined exception&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;Example 17 :&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;class myexcep extends Exception&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;private int detail;&lt;br /&gt;&lt;br /&gt;myexcep(int a)&lt;br /&gt;&lt;br /&gt;{ detail =a; }&lt;br /&gt;&lt;br /&gt;public String toString( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;return "MyException"+detail;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class exc11&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;static void compute(int a) throws myexcep&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("called compute"+a);&lt;br /&gt;&lt;br /&gt;if (a&gt;0)&lt;br /&gt;&lt;br /&gt;throw new myexcep(a);&lt;br /&gt;&lt;br /&gt;System.out.println("Normal exit");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void main(String arg[])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;try{&lt;br /&gt;&lt;br /&gt;compute(-1);&lt;br /&gt;&lt;br /&gt;compute(20);&lt;br /&gt;&lt;br /&gt;}catch(myexcep e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("My excep caught"+e);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#660000;"&gt;Some Unchecked runtime exceptions are&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;ArithmeticException&lt;br /&gt;&lt;br /&gt;ArrayIndexOutOfBoundsException&lt;br /&gt;&lt;br /&gt;ClassCastException&lt;br /&gt;&lt;br /&gt;IndexOutOfBoundsException&lt;br /&gt;&lt;br /&gt;NullPointerException&lt;br /&gt;&lt;br /&gt;NumberFormatException&lt;br /&gt;&lt;br /&gt;SecurityException&lt;br /&gt;&lt;br /&gt;Java’s Built In exceptions are&lt;br /&gt;&lt;br /&gt;ClassNotFoundException&lt;br /&gt;&lt;br /&gt;CloneNotSupportedException&lt;br /&gt;&lt;br /&gt;IllegalAccessException&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/2007/12/java-20-note.html"&gt;&gt;&gt;&gt;NEXT&gt;&gt;&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-2947812393464513975?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/2947812393464513975/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=2947812393464513975' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/2947812393464513975'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/2947812393464513975'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/5.html' title=''/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-2925792848221002594</id><published>2007-12-18T03:50:00.000-08:00</published><updated>2007-12-26T00:26:05.001-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-4'/><title type='text'></title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/2007/12/java-20-notes_18.html"&gt;&gt;&gt;PREVIOUS&gt;&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;JAVA 2.0 NOTES&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;span style="color:#990000;"&gt;4. Inheritance&lt;/span&gt; &lt;/a&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Inheritance is the method of creating new class based on the already existing class. The new class derived is called as sub class or derived class which has all features of the existing class and its own. The existing class is called as super class or base class.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;strong&gt;Adv :&lt;/strong&gt; &lt;/a&gt;reusability of code, accessibility of variables and methods of the base class&lt;br /&gt;by the derived class.&lt;br /&gt;&lt;br /&gt;If the class is derived from more than one class , then it is called as multiple inheritance. This is not available in Java. To overcome this problem use interface.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#993300;"&gt;Method Overriding&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Whenever there are methods of the same name both in the base class as well as in the derived class and if that method is called by main, the method in the derived class is always executed. This is called overriding. See example11.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#993300;"&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Example 11:&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;class A&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;void m( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("This is super class");}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class B extends A&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;void m( ) // it will override super class's method&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println ("This is sub class");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Super&lt;br /&gt;&lt;br /&gt;Super has two forms. First it calls the superclass’s constructor. The second is used to access a member of the superclass that has been hidden by a member of a subclass.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Example 12:&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;class A&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int a = 10;&lt;br /&gt;&lt;br /&gt;void A(int k)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.printn("k is " + k);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void m( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;System.out.println("This is super class");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class B extends A&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int a = 20;&lt;br /&gt;&lt;br /&gt;void m( ) // it will override super class's method&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("This is sub class");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void call( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;super(5); // to call super class's constructor&lt;br /&gt;&lt;br /&gt;m( ) ; // it will call the method in the derived class&lt;br /&gt;&lt;br /&gt;super.m( ); // to call super class's method&lt;br /&gt;&lt;br /&gt;int c = a ;&lt;br /&gt;&lt;br /&gt;int d = super.a ; // to assign super class's varaible.&lt;br /&gt;&lt;br /&gt;System.out.println("c = " + c + " d = " + d );}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class inh&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String args[ ])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;B ob = new B( );&lt;br /&gt;&lt;br /&gt;ob.call( ): // output is c = 20 d = 10}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Final&lt;br /&gt;&lt;br /&gt;final variables - to create constant final float pi =3.14f;&lt;br /&gt;&lt;br /&gt;final int a = 40&lt;br /&gt;&lt;br /&gt;final is used to create constant variable.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;b)&lt;/strong&gt; final modifiers - to prevent overriding&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Final modifiers are those to which no further alteration can be made. We can not override the method using final&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;span style="color:#660000;"&gt;Example 12:&lt;/span&gt; &lt;/a&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;class A&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;final void meth( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("this is the final method can not overridden");&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class B extends A&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;void method( ) //this line will show error.&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("Illegal");}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;c) final class - to prevent inheirtance&lt;br /&gt;&lt;br /&gt;If the class is declared as final , we cannot inherit it. All methods in the final class are final&lt;br /&gt;&lt;br /&gt;final class A&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class B extends A // error cant subclass of A&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Abstract &lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;Sometimes we will want to create a superclass that only defines a generalized form that will be shared by all of its subclasses, leaving it to each subclass to fill in the details.&lt;/p&gt;&lt;p&gt;To declare abstract class&lt;br /&gt;&lt;/p&gt;&lt;p&gt;abstract type name(parameters);&lt;br /&gt;&lt;/p&gt;&lt;p&gt;We must override the abstract method. An abstract class cannot be directly instantiated with the new operator. We cannot declare abstract constructors or abstract static methods.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;span style="color:#660000;"&gt;Example 13 :&lt;/span&gt; &lt;/a&gt;&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;abstract class A&lt;br /&gt;&lt;/p&gt;&lt;p&gt;{&lt;br /&gt;&lt;/p&gt;&lt;p&gt;abstract void callme( );&lt;br /&gt;&lt;/p&gt;&lt;p&gt;void display( )&lt;br /&gt;&lt;/p&gt;&lt;p&gt;{&lt;br /&gt;&lt;/p&gt;&lt;p&gt;System.out.println("This is example for abstract class"):&lt;br /&gt;&lt;/p&gt;&lt;p&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;class B&lt;br /&gt;&lt;/p&gt;&lt;p&gt;{&lt;br /&gt;&lt;/p&gt;&lt;p&gt;void callme( )&lt;br /&gt;&lt;/p&gt;&lt;p&gt;{&lt;br /&gt;&lt;/p&gt;&lt;p&gt;System.out.println("B's implementation of callme");&lt;br /&gt;&lt;/p&gt;&lt;p&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;class abst&lt;br /&gt;&lt;/p&gt;&lt;p&gt;{&lt;br /&gt;&lt;/p&gt;&lt;p&gt;public static void main(String a[])&lt;br /&gt;&lt;/p&gt;&lt;p&gt;{&lt;br /&gt;&lt;/p&gt;&lt;p&gt;B b = new B( );&lt;br /&gt;&lt;/p&gt;&lt;p&gt;b.callme( );&lt;br /&gt;&lt;/p&gt;&lt;p&gt;b.disp( );&lt;br /&gt;&lt;/p&gt;&lt;p&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/2007/12/5.html"&gt;&gt;&gt;NEXT&gt;&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-2925792848221002594?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/2925792848221002594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=2925792848221002594' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/2925792848221002594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/2925792848221002594'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-2_18.html' title=''/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-7298861184524480925</id><published>2007-12-18T03:19:00.000-08:00</published><updated>2007-12-26T00:18:30.019-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-3'/><title type='text'>JAVA 2.0 NOTES</title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;a href="http://java4interview.blogspot.com/2007/12/java-2.html"&gt;&gt;&gt;PREVIOUS&gt;&gt;&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;strong&gt;&lt;span style="font-size:130%;color:#990000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-size:130%;color:#990000;"&gt;JAVA 2.0 NOTES&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Garbage collection&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;When no reference to object exits, the object no longer needed, the memory occupied by the object is reclaimed. This is called garbage collection. Java periodically does garbage collection.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Finalizer :&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Finalizer method is the exact opposite of constructor method. They are called just before the object is garbage collected and its memory is reclaimed. All &lt;a href="http://java4interview.blogspot.com/"&gt;cleanup&lt;/a&gt; operations are performed in this method.&lt;br /&gt;protected void finalize( )&lt;br /&gt;{ }&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="color:#660000;"&gt;&lt;strong&gt;&lt;em&gt;Methods overloading &lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;&lt;em&gt;&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;Methods overloading is creating different &lt;a href="http://java4interview.blogspot.com/"&gt;methods&lt;/a&gt; with same name but with different parameters. This is the one type of creating polymorphism in Java&lt;br /&gt;Example for method overloading and constructor overloading&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;&lt;p&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Example 9:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;Box( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int depth;&lt;br /&gt;&lt;br /&gt;int width;&lt;br /&gt;&lt;br /&gt;int height;&lt;br /&gt;&lt;br /&gt;Box(int w, int d, int h)&lt;br /&gt;&lt;br /&gt;{witdth = w; height = h; depth = d;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Box(int a)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;witdth = a; height = a; depth = a;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Box( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;witdth = 1; height = 1; depth = 1;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;void show( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println(width * height * depth);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void show(int a)&lt;br /&gt;&lt;br /&gt;{System.out.println("Width = " + w);&lt;br /&gt;&lt;br /&gt;System.out.println("Depth = " + d);&lt;br /&gt;&lt;br /&gt;System.out.println("Height = " + h);&lt;br /&gt;&lt;br /&gt;System.out.println("Cube is " + (width * height * depth )) ;}}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class boxdemo&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String args[ ])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;Box b1 = new Box(3,4,5);&lt;br /&gt;&lt;br /&gt;Box b2 = new Box(5);&lt;br /&gt;&lt;br /&gt;Box b3 = new Box( );b1.show(1);&lt;br /&gt;&lt;br /&gt;b2.show( );b3.show( );&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#993300;"&gt;Method Overriding&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Method overriding is creating a method in the derived class that has the same name arguments&lt;br /&gt;as in the superclass. This new method hides the superclass method.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Recursion&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Recursion is the process of defining something in terms of itself. A method that calls itself is said to be recursive.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Example 10:&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;class factorial&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int fact(int n)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int result;if(n==1) return 1;&lt;br /&gt;&lt;br /&gt;result = fact(n----1) * n;&lt;br /&gt;&lt;br /&gt;return result;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class recurse&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;public static void main(String a[ ])&lt;br /&gt;&lt;br /&gt;{factorial f = new factorial( );&lt;br /&gt;&lt;br /&gt;System.out.println("Fact of 3 is "+f.fact(3));&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Nested Class&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;It is possible to nest a class definition within another and treat the nested class like any other&lt;br /&gt;method of that class. An inner class is a nested class whose instance exists within an instance of&lt;br /&gt;its enclosing class and has direct access to the instance members of its enclosing instance.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;span style="color:#993300;"&gt;class enclosingClass&lt;/span&gt; &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;{&lt;br /&gt;&lt;br /&gt;class innserClass&lt;br /&gt;&lt;br /&gt;{}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Example :&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;class outclass&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;int a =10;&lt;br /&gt;&lt;br /&gt;public void m1( )&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("This is inner class method");&lt;br /&gt;&lt;br /&gt;inclass in = new inclass( );&lt;br /&gt;&lt;br /&gt;in.m2( );&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class inclass&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public void m2( )&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.out.println("This is inner class method");&lt;br /&gt;&lt;br /&gt;System.out.println("a = "+ a);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void main(String arg[ ])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;outclass out = new outclass( );&lt;br /&gt;&lt;br /&gt;out.m1( );&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/2007/12/java-2_18.html"&gt;&gt;&gt;&gt;NEXT&gt;&gt;&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-7298861184524480925?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/7298861184524480925/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=7298861184524480925' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/7298861184524480925'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/7298861184524480925'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-20-notes_18.html' title='JAVA 2.0 NOTES'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-8030046140132507987</id><published>2007-12-18T03:04:00.000-08:00</published><updated>2007-12-26T00:13:12.637-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-2'/><title type='text'>JAVA 2.0 Notes</title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;a href="http://java4interview.blogspot.com/2007/12/java-20-notes.html"&gt;&gt;&gt;PREVIOUS&gt;&gt;&gt;&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="font-size:130%;color:#990000;"&gt;JAVA 2.0 Notes&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="PROGRAM CONSTRUCTS"&gt;&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;&lt;span style="font-size:130%;"&gt;2.&lt;/span&gt; PROGRAM CONSTRUCTS&lt;/span&gt;&lt;/strong&gt; &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;They are divided into&lt;br /&gt;&lt;br /&gt;Sequence&lt;br /&gt;&lt;br /&gt;Selection - if, switch&lt;br /&gt;&lt;br /&gt;Iteration - while, do..while, for&lt;br /&gt;&lt;br /&gt;Misc - break, exit, continue, and return&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; &lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;If&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;If (condition)&lt;br /&gt;{&lt;br /&gt;set of statements1;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;set of statments2 ;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Example 3:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;class if&lt;br /&gt;{&lt;br /&gt;public static void main(String a[ ])&lt;br /&gt;{&lt;br /&gt;int a=5,b=10;&lt;br /&gt;if (a&gt;b)&lt;br /&gt;System.out.println("A is big");&lt;br /&gt;else&lt;br /&gt;System.out.println("B is big");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;p&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;b)&lt;/a&gt;&lt;/strong&gt; for&lt;br /&gt;for (var=value1; condition; iteration)&lt;br /&gt;{&lt;br /&gt;statements;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#993300;"&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;strong&gt;Example 4:&lt;/strong&gt;&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;class for&lt;br /&gt;{&lt;br /&gt;public static void main(String a[ ])&lt;br /&gt;{&lt;br /&gt;for(int a=0; a&lt;10;&gt;c)&lt;/strong&gt; while and do..while&lt;br /&gt;while(condition) do&lt;br /&gt;{ {&lt;br /&gt;statements; statements;&lt;br /&gt;} } while(condition);&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;span style="color:#660000;"&gt;Example 5:&lt;/span&gt; &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;class dowhile&lt;br /&gt;{&lt;br /&gt;public static void main(String a[ ])&lt;br /&gt;{&lt;br /&gt;int a=5 ;&lt;br /&gt;do&lt;br /&gt;{System.out.println("A is big");&lt;br /&gt;a--;&lt;br /&gt;} while(a&gt;0);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;d)&lt;/strong&gt; switch&lt;br /&gt;switch (expr)&lt;br /&gt;{&lt;br /&gt;case value1:&lt;br /&gt;statements1 ; break;&lt;br /&gt;case value2:&lt;br /&gt;statements2 ; break;&lt;br /&gt;:&lt;br /&gt;:&lt;br /&gt;case valuen:&lt;br /&gt;statementsn; break;&lt;br /&gt;default:&lt;br /&gt;statements ;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;span style="color:#660000;"&gt;Example 6:&lt;/span&gt; &lt;/a&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;class switch&lt;br /&gt;{&lt;br /&gt;public static void main(String a[ ])&lt;br /&gt;{&lt;br /&gt;int a=5 ;&lt;br /&gt;switch(a)&lt;br /&gt;{&lt;br /&gt;case 0:&lt;br /&gt;System.out.println("Zero"); break;case 1:&lt;br /&gt;System.out.println("One"); break;case 2:&lt;br /&gt;System.out.println("Two"); break;default:&lt;br /&gt;System.out.println("greater than 2");}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;e)&lt;/strong&gt; break, continue and exit&lt;br /&gt;break will transfer the control out of the loop, in continue , the rest of the lines are ignored and loop continue after the next iteration. The exit function will stop the program execution.&lt;br /&gt;&lt;br /&gt;&lt;a name="CLASSES AND METHODS"&gt;&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="color:#660000;"&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;strong&gt;3. CLASSES AND METHODS &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;Classes&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The most important feature of the OOP is classes. A class defines the shape and behavior of an object and is a template for multiple object with similar features. It is a logical construct upon which the entire java language is built because it defines the shape and nature of the object.&lt;br /&gt;&lt;br /&gt;To create a class, a source file with the class keyword in it, followed by a name and pair of curly braces for the body.&lt;br /&gt;&lt;br /&gt;access class classname&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;type instance-variable;&lt;br /&gt;type method(parameters)&lt;br /&gt;{&lt;br /&gt;body of method;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Once class is created, an instance of class is created by new keyword. The instance of class is used to access the variables and methods that form part of the class. The dot operator is used to get the value of the class variable (object.variable).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Instance Variable :&lt;/span&gt;&lt;/strong&gt; Data is encapsulated in a class by declaring varables inside the class&lt;br /&gt;declaration. Variables declared in this scope are called as Instance variables.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Class Variable :&lt;/span&gt; &lt;/strong&gt;Class variables are global to class and all the instances of the class. To declare class variable static keyword is used.&lt;br /&gt;&lt;br /&gt;The access of class may be public, private, abstract or final.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Methods&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Methods are functions that operate on instances of classes in which they are defined. Method definition has four parts. They are name of the method, return type , list of parameters and body of the method.&lt;br /&gt;&lt;br /&gt;returntype methodname (type arg1, type arg2,…)&lt;br /&gt;{&lt;br /&gt;Statements;&lt;br /&gt;}&lt;br /&gt;To call a method&lt;br /&gt;methodname( ) or&lt;br /&gt;obj.methodname(para1, para2,…) ;&lt;br /&gt;An example for a class which has a class and method&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Example 7:&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;class area&lt;br /&gt;{&lt;br /&gt;int len=10, bra=20;&lt;br /&gt;void calc( )&lt;br /&gt;{&lt;br /&gt;int ara = len * bra;&lt;br /&gt;System.out.println("The area is " + ara);&lt;br /&gt;}&lt;br /&gt;public static void main(String a[ ])&lt;br /&gt;{&lt;br /&gt;area a = new area( );&lt;br /&gt;a.calc( );&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;strong&gt;Access Specifiers: &lt;/strong&gt;&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Public :&lt;/span&gt;&lt;/strong&gt; If any method or variable is declared as public, it is visible to all&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;classes.Private :&lt;/span&gt;&lt;/strong&gt; If any method or variable is declared as private , it is visible to&lt;br /&gt;&lt;br /&gt;classes in which it is declared.Protected : It is visible in class and all its subclasses.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;p&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Package :&lt;/a&gt;&lt;/strong&gt; It is indicated by the lack of any access modifier in a declaration.&lt;br /&gt;&lt;br /&gt;It has an increased protection and narrowed visibility.Final : It can not overridden by subclass&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Abstract :&lt;/span&gt;&lt;/strong&gt; in abstract class without body, must be overridden by subclass.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Static :&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt; It is automatically called when creating instance of class.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;This:&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;The this keyword is used inside any instance method to the current object.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Constructor &lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;A constructor method is a special kind of method that determines how an object is initialized when created. They have the same name as the class but do not have any return type. Consturctor can also be overloaded.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#660000;"&gt;Example 8:&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;class cons&lt;br /&gt;{&lt;br /&gt;int I; int j;&lt;br /&gt;cons(int a, int b)&lt;br /&gt;{ I=a; j=b; }&lt;br /&gt;void print( )&lt;br /&gt;{System.out.println("the addition of " + I + "and " + j + " is " +(I+j)); }public static void main(String s[ ] )&lt;br /&gt;{&lt;br /&gt;cons c = new cons(10,10);&lt;br /&gt;c.print( );&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/2007/12/java-20-notes_18.html"&gt;&gt;&gt;&gt;NEXT&gt;&gt;&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-8030046140132507987?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/8030046140132507987/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=8030046140132507987' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/8030046140132507987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/8030046140132507987'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-2.html' title='JAVA 2.0 Notes'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-4229301308040877929</id><published>2007-12-18T02:49:00.000-08:00</published><updated>2007-12-25T23:40:59.350-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA 2.0 NOTE-1'/><title type='text'>JAVA 2.0 Notes</title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&gt;&gt;PREVIOUS&gt;&gt;&gt;&lt;/strong&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#990000;"&gt;JAVA 2.0 Notes &lt;/span&gt;&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;1. &lt;/span&gt;&lt;/strong&gt;&lt;/em&gt;&lt;a name="introduction"&gt;&lt;/a&gt;&lt;span style="color:#993300;"&gt;&lt;em&gt;&lt;strong&gt;INTRODUCTION&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Java&lt;/a&gt; is an Object-Oriented, multi-threaded programming language developed by Sun Microsystems in 1991. It is designed to be small, simple and portable. The popularity of the Java is due to 3 key elements powerful programming language, applets and rich set of significant object classes.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Adv of Java&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Simple&lt;br /&gt;&lt;br /&gt;Secure&lt;br /&gt;&lt;br /&gt;Portable&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Object&lt;/a&gt; Oriented&lt;br /&gt;&lt;br /&gt;Robust&lt;br /&gt;&lt;br /&gt;Multithreaded&lt;br /&gt;&lt;br /&gt;Interpreted&lt;br /&gt;&lt;br /&gt;High Performance&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Distributed&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Dynamic Components of &lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;JVM&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In Java development environment, there are two parts, a Java compiler and Java interpreter.&lt;br /&gt;Java compiler generates byte code and interpreter executes the Java program. Eventhough the bytecode is slow, it gives platform independent application.&lt;br /&gt;&lt;br /&gt;Java program is typed in and saved in a file with extension .java. This file is compiled by javac. It creates a file with .class extension. This is executed by Java file without extension. A simple example for a Java program is&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#003300;"&gt;Example 1:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;class first&lt;br /&gt;{&lt;br /&gt;public static void main (String s[ ] )&lt;br /&gt;{&lt;br /&gt;System.out.println("Welcome to Java ") ;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;It was saved in the file first.java and compiled by java first.java&lt;br /&gt;and executed by java first.&lt;br /&gt;&lt;br /&gt;Class declaration is done in the first line of the program by class classname&lt;br /&gt;&lt;br /&gt;Every &lt;a href="http://java4interview.blogspot.com/"&gt;java program &lt;/a&gt;has main( ) method, which was first executed.&lt;br /&gt;void keyword indicates that main( ) does not return any value.&lt;br /&gt;static indicates that main( ) is a class method and can be called without creating an object.&lt;br /&gt;public indicates the method is global.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Data types :&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Integers :&lt;/span&gt;&lt;/strong&gt; &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;long 64&lt;br /&gt;&lt;br /&gt;int 32&lt;br /&gt;&lt;br /&gt;short 16 -32768 to 32767&lt;br /&gt;&lt;br /&gt;byte 8 -128 to 127&lt;br /&gt;&lt;br /&gt;Float&lt;br /&gt;&lt;br /&gt;float 64double 32&lt;br /&gt;&lt;br /&gt;Characters&lt;br /&gt;&lt;br /&gt;char 16 0 to 63536&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;String&lt;br /&gt;&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;Boolean :&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;boolean true or false&lt;br /&gt;&lt;br /&gt;Character Escape Sequences&lt;br /&gt;&lt;br /&gt;\n \t \f \b \\ \’ \" \ddd \uxxxx&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;p&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;span style="color:#660000;"&gt;To declare a variable&lt;/span&gt;&lt;br /&gt;&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;type variable=value,variable=value,…;&lt;br /&gt;&lt;br /&gt;To initialize a variable&lt;br /&gt;&lt;br /&gt;int a=10; String name="palani";&lt;br /&gt;&lt;br /&gt;float sal=5400.50f;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;span style="color:#660000;"&gt;Arrays:&lt;/span&gt;&lt;br /&gt;&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;int arr [12] ;&lt;br /&gt;&lt;br /&gt;char carr[ ] = { ‘a’,’b’,’c’,’d’} ;&lt;br /&gt;&lt;br /&gt;int a[12][10] ;&lt;br /&gt;&lt;br /&gt;char name[10][10][10] ;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#660000;"&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;Type casting:&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;When one type of data is assigned to be another type of variable, an automatic type conversion&lt;br /&gt;will take place.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;strong&gt;&lt;span style="color:#003300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;p&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;span style="color:#003300;"&gt;For example&lt;/span&gt;&lt;br /&gt;&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;byte a=10; int c = a + 10;&lt;br /&gt;&lt;br /&gt;Here, a is converted to int automatically.&lt;br /&gt;&lt;br /&gt;To manually convert a type use (type) value&lt;br /&gt;&lt;br /&gt;For example float f = (float) a/ float(b) ; if a, b are integers.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;span style="color:#003300;"&gt;Example 2:&lt;/span&gt; &lt;/a&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;class cast&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public static void main(String args[ ])&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;byte&lt;/a&gt;&lt;/strong&gt; a = 10, b = 20 ;&lt;br /&gt;&lt;br /&gt;int c = 15, d = 2 ;&lt;br /&gt;&lt;br /&gt;float f1 = c/d; // f1 is 7.0&lt;br /&gt;&lt;br /&gt;float f2 = (float) c / (float) d ; // f2 is 7.5&lt;br /&gt;&lt;br /&gt;c = b + 10 ; // b is automatically converted to int&lt;br /&gt;&lt;br /&gt;/* b = b + 10 ; Error : cannot assign int to byte */&lt;br /&gt;&lt;br /&gt;b = (byte) (b + 10);&lt;br /&gt;&lt;br /&gt;System.out.println("f1 =" + f1 " + "f2 = " + f2 " + "c = " + c + "b = "+b);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;&lt;span style="color:#660000;"&gt;Operators &lt;/span&gt;&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;&lt;p&gt;1) Arithmetic - + - * / %&lt;br /&gt;&lt;br /&gt;2) Relational - &lt; &gt; &lt;= &gt;= !=&lt;br /&gt;&lt;br /&gt;3) Logical - &amp;amp;&amp;amp; !=&lt;br /&gt;&lt;br /&gt;4) Assignment - =&lt;br /&gt;&lt;br /&gt;5) Comparision - = =&lt;br /&gt;&lt;br /&gt;6) Incre/Decrement - ++ --&lt;br /&gt;&lt;br /&gt;7) Bitwise operator - ~ &amp;amp; ^ &gt;&gt; &gt;&gt;&gt; &lt;&lt; &amp;amp;= != ^= 8) Conditional - ? : Comments : // Single line comment /* */ Multiline line comment /** */ &lt;a href="http://java4interview.blogspot.com/"&gt;Document line &lt;/a&gt;comment .&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;em&gt;&lt;a href="http://java4interview.blogspot.com/2007/12/java-2.html"&gt;&lt;strong&gt;&gt;&gt;&gt;NEXT&gt;&gt;&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/em&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-4229301308040877929?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/4229301308040877929/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=4229301308040877929' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/4229301308040877929'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/4229301308040877929'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-20-notes.html' title='JAVA 2.0 Notes'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-7678980166318535649</id><published>2007-12-18T02:22:00.000-08:00</published><updated>2007-12-18T02:48:14.167-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Points learnt from Java mock exams'/><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;&lt;span style="font-size:130%;"&gt;Points learnt from Java mock exams&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;a) To get the width of an applet within the init method: int width = this.getSize().w;&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;int width=getSize().w;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;b) int x = evt.getX(); returns the horizontal location to the varaible x at the time of the event.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;c) You can't add ActionListener to a TextArea but can be added to TextField. You can't add WindowListener and ContainerListener to TextField&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;d) class Test{&lt;br /&gt;static int a = 1;&lt;br /&gt;public static void main(String arg[]) {&lt;br /&gt;int a;&lt;br /&gt;System.out.println(a);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Even though there is a static variable named a, the local variable takes the precedence. So a compilation error occurs saying, 'a' may not be initialized&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;e) void loopTest() {&lt;br /&gt;int x=0;&lt;br /&gt;one: while(x &lt;&gt;3) break two;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;will not compile because "two" is not associated with any loop&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;f) Panel p = new Applet(); //this is true&lt;br /&gt;&lt;br /&gt;JPanel p = new JApplet(); //this is not true&lt;br /&gt;&lt;br /&gt;see API for details.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;g) byte x=-1;&lt;br /&gt;x = x&gt;&gt;&gt;5;&lt;br /&gt;illegal because result of x&gt;&gt;&gt;5 is int and can't be assigned to x which is byte.&lt;br /&gt;it can be corrected as&lt;br /&gt;byte x=-1;&lt;br /&gt;x=(byte)(x&gt;&gt;&gt;5)//legal&lt;br /&gt;&lt;br /&gt;int x=100; float y = 100.0f;&lt;br /&gt;if(x==y) {System.out.println("equal");}//converts int to float&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;output :&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;equal&lt;br /&gt;&lt;br /&gt;byte b=2;&lt;br /&gt;byte b1=3;&lt;br /&gt;b=b*b1;//illegal&lt;br /&gt;&lt;br /&gt;will not compile because before multipying both b and b1 will be converted to int and int can't be assigned to byte.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;h)String s="Hello there";&lt;br /&gt;String sub = s.substring(6);//sub="there"&lt;br /&gt;String seg = s.substring(7,10);//seg="her";&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;creating a character array :&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;String s = "Hello there";&lt;br /&gt;char[] arr;&lt;br /&gt;arr=s.toCharArray();&lt;br /&gt;System.out.println(arr[1]);//prints ""e"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;creating String from character array :&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;char[] c={'H','e','l','l','o'};&lt;br /&gt;String s = String.copyValueOf(c);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;i)You can have any number of main method inside a class. You can also overload it. After all it is also a method. But remember that main is a static method.&lt;br /&gt;&lt;br /&gt;j) class test {&lt;br /&gt;static int i[];&lt;br /&gt;public static void main(String arg[]) {&lt;br /&gt;System.out.println(i[2]); //gives NullPointerException&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;k)&lt;br /&gt;&lt;br /&gt;int k[][]=new int[10][20];&lt;br /&gt;System.out.println(k.length); //prints 10&lt;br /&gt;int k[][]={{1,2,3,4},{1,2,3},{5,4,6,4}};&lt;br /&gt;System.out.println(k.length); //prints 3&lt;br /&gt;&lt;br /&gt;l)Another way of initializing array&lt;br /&gt;int num[] = new int[]{1,2,3};&lt;br /&gt;&lt;br /&gt;m)Assigning one object to another (example from Thinking in Java)&lt;br /&gt;1 Class Number {&lt;br /&gt;&lt;br /&gt;2 int i;&lt;br /&gt;&lt;br /&gt;3 }&lt;br /&gt;&lt;br /&gt;4 public class Assignment {&lt;br /&gt;&lt;br /&gt;5 public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;6 Number n1 = new Number();&lt;br /&gt;&lt;br /&gt;7 Number n2 = new Number();&lt;br /&gt;&lt;br /&gt;8 n1.i = 9;&lt;br /&gt;&lt;br /&gt;9 n2.i = 47;&lt;br /&gt;&lt;br /&gt;10 System.out.println("1: n1.i: " + n1.i + ", n2.i: " + n2.i);&lt;br /&gt;&lt;br /&gt;11 n1 = n2;&lt;br /&gt;&lt;br /&gt;12 System.out.println("2: n1.i: " + n1.i +&lt;br /&gt;", n2.i: " + n2.i);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;13 n1.i = 27;&lt;br /&gt;&lt;br /&gt;14 System.out.println("3: n1.i: " + n1.i + ", n2.i: " + n2.i);&lt;br /&gt;&lt;br /&gt;15 }&lt;br /&gt;&lt;br /&gt;16 }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;1: n1.i: 9, n2.i: 47&lt;br /&gt;&lt;br /&gt;2: n1.i: 47, n2.i: 47&lt;br /&gt;&lt;br /&gt;3: n1.i: 27, n2.i: 27&lt;br /&gt;&lt;br /&gt;Changing the n1 object, changes the n2 object. This is because both n1 and n2 contain the same reference, which is pointing to the same object. Instead, if u change line number 11 to n1.i = n2.i;&lt;br /&gt;&lt;br /&gt;The output will be&lt;br /&gt;&lt;br /&gt;1: n1.i: 9, n2.i: 47&lt;br /&gt;&lt;br /&gt;2: n1.i: 47, n2.i: 47&lt;br /&gt;&lt;br /&gt;3: n1.i: 27, n2.i: 47&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-7678980166318535649?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/7678980166318535649/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=7678980166318535649' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/7678980166318535649'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/7678980166318535649'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/points-learnt-from-java-mock-exams-to.html' title=''/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-5219454990763342099</id><published>2007-12-12T04:55:00.000-08:00</published><updated>2007-12-12T05:09:08.775-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Abstract Class and Interface'/><title type='text'>Abstract Class and Interface</title><content type='html'>&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Abstract Class and Interface &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;What is the difference between interface and an abstract class?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. An abstract class can contain no abstract methods also i.e. abstract class may contain concrete methods. A Java Interface can contain only method declarations and public static final constants and doesn't contain their implementation. The classes which implement the Interface must provide the method definition for all the methods present.&lt;br /&gt;&lt;br /&gt;2. Abstract class definition begins with the keyword "abstract" keyword followed by Class definition. An Interface definition begins with the keyword "interface".&lt;br /&gt;&lt;br /&gt;3. Abstract classes are useful in a situation when some general methods should be implemented and specialization behavior should be implemented by subclasses. Interfaces are useful in a situation when all its properties need to be implemented by subclasses.&lt;br /&gt;&lt;br /&gt;4. All variables in an Interface are by default - public static final while an abstract class can have instance variables.&lt;br /&gt;&lt;br /&gt;5. An interface is also used in situations when a class needs to extend an other class apart from the abstract class. In such situations its not possible to have multiple inheritance of classes. An interface on the other hand can be used when it is required to implement one or more interfaces. Abstract class does not support Multiple Inheritance whereas an Interface supports multiple Inheritance.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;6. An Interface can only have public members whereas an abstract class can contain private as well as protected members.&lt;br /&gt;&lt;br /&gt;7. A class implementing an interface must implement all of the methods defined in the interface, while a class extending an abstract class need not implement any of the methods defined in the abstract class.&lt;br /&gt;&lt;br /&gt;8. The problem with an interface is, if you want to add a new feature (method) in its contract, then you MUST implement those method in all of the classes which implement that interface. However, in the case of an abstract class, the method can be simply implemented in the abstract class and the same can be called by its subclass.&lt;br /&gt;&lt;br /&gt;9. Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast10.Interfaces are often used to describe the peripheral abilities of a class, and not its central identity,&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;E.g.&lt;/em&gt;&lt;/strong&gt; an Automobile class mightimplement the Recyclable interface, which could apply to many otherwise totally unrelated objects.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Note:&lt;/span&gt;&lt;/strong&gt; There is no difference between a fully abstract class (all methods declared as abstract and all fields are public static final) and an interface.Note: If the various objects are all of-a-kind, and share a common state and behavior, then tend towards a common base class. If all they share is a set of method signatures, then tend towards an interface.Similarities: Neither Abstract classes nor Interface can be instantiated.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What does it mean that a method or class is abstract?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An abstract class cannot be instantiated. Only its subclasses can be instantiated. A class that has one or more abstract methods must be declared abstract. A subclass that does not provide an implementation for its inherited abstract methods must also be declared abstract.&lt;br /&gt;&lt;br /&gt;You indicate that a class is abstract with the abstract keyword like this:public abstract class AbstractClassAbstract classes may contain abstract methods. A method declared abstract is not actually implemented in the class. It exists only to be overridden in subclasses. Abstract methods may only be included in abstract classes.&lt;br /&gt;&lt;br /&gt;However, an abstract class is not required to have any abstract methods, though most of them do. Each subclass of an abstract class must override the abstract methods of its superclassesor itself be declared abstract. Only the method’s prototype is provided in the class definition. Also, a final method can not be abstract and vice versa. Methods specified in an interface are implicitly abstract. . It has no body. For example,public abstract float getInfo()&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What must a class do to implement an interface?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The class must provide all of the methods in the interface and identify the interface in its implements clause.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is an abstract method?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An abstract method is a method whose implementation is deferred to a subclass.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;What is interface? How to support multiple inhertance in Java?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;Or&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;What is a cloneable interface and how many methods does it contain?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;An Interface are implicitly abstract and public. Interfaces with empty bodies are called marker interfaces having certain property or behavior.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;Examples:&lt;/span&gt;&lt;/strong&gt;java.lang.Cloneable,java.io.Serializable,java.util.EventListener. An interface body can contain constant declarations, method prototype declarations, nested class declarations, and nested interface declarations.Interfaces provide support for multiple inheritance in Java. A class that implements the interfaces is bound to implement all the methods defined in Interface.Example of Interface:public interface sampleInterface {public void functionOne();public long CONSTANT_ONE = 1000;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is an abstract class?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Or&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Can you make an instance of an abstract class?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Abstract classes can contain abstract and concrete methods. Abstract classes cannot be instantiated directly i.e. we cannot call the constructor of an abstract class directly nor we can create an instance of an abstract class by using “Class.forName().newInstance()” (Here we get java.lang.InstantiationException). However, if we create an instance of a class that extends an Abstract class, compiler will initialize both the classes. Here compiler will implicitly call the constructor of the Abstract class.&lt;br /&gt;&lt;br /&gt;Any class that contain an abstract method must be declared “abstract” and abstract methods can have definitions only in child classes. By overriding and customizing the abstract methods in more than one subclass makes “Polymorphism” and through Inheritance we define body to the abstract methods. Basically an abstract class serves as a template. Abstract class must be extended/subclassed for it to be implemented. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated. Abstract class is a class that provides some general functionality but leaves specific implementation to its inheriting classes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Example&lt;/em&gt;&lt;/strong&gt; of Abstract class:&lt;br /&gt;&lt;br /&gt;abstract class AbstractClassExample&lt;br /&gt;{protected String name;&lt;br /&gt;public String getname()&lt;br /&gt;{ return name&lt;br /&gt;;&lt;br /&gt;}&lt;br /&gt; public abstract void function()&lt;br /&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#006600;"&gt;Example:&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt; Vehicle is an abstract class and Bus Truck, car etc are specific implementations.&lt;br /&gt;&lt;br /&gt;No! You cannot make an instance of an abstract class. An abstract class has to be sub-classed.If you have an abstract class and you want to use a method which has been implemented, you mayneed to subclass that abstract class, instantiate your subclass and then call that method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is meant by "Abstract Interface"?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Firstly, an interface is abstract. That means you cannot have any implementation in an interface. All the methods declared in an interface are abstract methods or signatures of the methods.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;How to define an Interface?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In Java Interface defines the methods but does not implement them. Interface can include constants.A class that implements the interfaces is bound to implement all the methods defined in Interface.Example of Interface:public interface SampleInterface {public void functionOne();public long CONSTANT_ONE = 1000; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Can Abstract Class have constructors?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Can interfaces have constructors?Abstract class's can have a constructor, but you cannot access it through the object, since you cannot instantiate abstract class. To access the constructor create a sub class and extend the abstract class which is having the constructor.Examplepublic abstract class Abstract.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;Example &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;{public AbstractExample(){&lt;br /&gt;System.out.println("In AbstractExample()")&lt;br /&gt;;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;public class Test extends AbstractExample&lt;br /&gt;{&lt;br /&gt;public static void main(String args[]){Test obj=new Test();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;If &lt;strong&gt;interface &amp;amp; abstract&lt;/strong&gt; &lt;strong&gt;class&lt;/strong&gt; have same methods and those methods contain no implementation, which one would you prefer?Obviously one should ideally go for an interface, as we can only extend one class. Implementing an interface for a class is very much effective rather than extending an abstract class because we can extend some other useful class for this subclass.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-5219454990763342099?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/5219454990763342099/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=5219454990763342099' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/5219454990763342099'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/5219454990763342099'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/abstract-class-and-interface.html' title='Abstract Class and Interface'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-1993246882108048159</id><published>2007-12-12T04:49:00.000-08:00</published><updated>2007-12-12T04:53:09.672-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Multi Threading'/><title type='text'>Java Multi Threading</title><content type='html'>&lt;strong&gt;&lt;em&gt;Java Multi Threading&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;1) What are the two types of multitasking?&lt;br /&gt;&lt;br /&gt;Ans :&lt;br /&gt;1.process-based&lt;br /&gt;&lt;br /&gt;2.Thread-based&lt;br /&gt;&lt;br /&gt;2) What are the two ways to create the thread?&lt;br /&gt;&lt;br /&gt;Ans :&lt;br /&gt; 1.by implementing Runnable&lt;br /&gt;&lt;br /&gt;2.by extending Thread&lt;br /&gt;&lt;br /&gt;3) What is the signature of the constructor of a thread class?&lt;br /&gt;&lt;br /&gt;Ans : Thread(Runnable threadob,String threadName)&lt;br /&gt;&lt;br /&gt;4) What are all the methods available in the Runnable Interface?&lt;br /&gt;&lt;br /&gt;Ans : run()&lt;br /&gt;&lt;br /&gt;5) What is the data type for the method isAlive() and this method is available in which class?&lt;br /&gt;&lt;br /&gt;Ans : boolean, Thread&lt;br /&gt;&lt;br /&gt;6) What are all the methods available in the Thread class?&lt;br /&gt;&lt;br /&gt;Ans :&lt;br /&gt;1.isAlive()&lt;br /&gt;&lt;br /&gt;2.join()&lt;br /&gt;&lt;br /&gt;3.resume()&lt;br /&gt;&lt;br /&gt;4.suspend()&lt;br /&gt;&lt;br /&gt;5.stop()&lt;br /&gt;&lt;br /&gt;6.start()&lt;br /&gt;&lt;br /&gt;7.sleep()&lt;br /&gt;&lt;br /&gt;8.destroy()&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;7) What are all the methods used for Inter Thread communication and what is the class in which these methods are defined?&lt;br /&gt;&lt;br /&gt;Ans :&lt;br /&gt;1. wait(),notify() &amp;amp; notifyall()&lt;br /&gt;2. Object class&lt;br /&gt;&lt;br /&gt;8) What is the mechanisam defind by java for the Resources to be used by only one Thread at a time?&lt;br /&gt;&lt;br /&gt;Ans : Synchronisation&lt;br /&gt;&lt;br /&gt;9) What is the procedure to own the moniter by many threads?&lt;br /&gt;&lt;br /&gt;Ans : not possible&lt;br /&gt;&lt;br /&gt;10) What is the unit for 1000 in the below statement? ob.sleep(1000)&lt;br /&gt;&lt;br /&gt;Ans : long milliseconds&lt;br /&gt;&lt;br /&gt;11) What is the data type for the parameter of the sleep() method?&lt;br /&gt;&lt;br /&gt;Ans : long&lt;br /&gt;&lt;br /&gt;12) What are all the values for the following level?&lt;br /&gt;&lt;br /&gt;max-priority&lt;br /&gt;&lt;br /&gt;min-priority&lt;br /&gt;&lt;br /&gt;normal-priority&lt;br /&gt;&lt;br /&gt;Ans : 10,1,5&lt;br /&gt;&lt;br /&gt;13) What is the method available for setting the priority?&lt;br /&gt;&lt;br /&gt;Ans : setPriority()&lt;br /&gt;&lt;br /&gt;14) What is the default thread at the time of starting the program?&lt;br /&gt;&lt;br /&gt;Ans : main thread&lt;br /&gt;&lt;br /&gt;15) The word synchronized can be used with only a method.&lt;br /&gt;&lt;br /&gt;True/ False&lt;br /&gt;&lt;br /&gt;Ans : False&lt;br /&gt;&lt;br /&gt;16) Which priority Thread can prompt the lower primary Thread?&lt;br /&gt;&lt;br /&gt;Ans : Higher Priority&lt;br /&gt;&lt;br /&gt;17) How many threads at a time can access a monitor?&lt;br /&gt;&lt;br /&gt;Ans : one&lt;br /&gt;&lt;br /&gt;18) What are all the four states associated in the thread?&lt;br /&gt;&lt;br /&gt;Ans : 1. new 2. runnable 3. blocked 4. dead&lt;br /&gt;&lt;br /&gt;19) The suspend()method is used to teriminate a thread?&lt;br /&gt;&lt;br /&gt;True /False&lt;br /&gt;&lt;br /&gt;Ans : False&lt;br /&gt;&lt;br /&gt;20) The run() method should necessary exists in clases created as subclass of thread?&lt;br /&gt;&lt;br /&gt;True /False&lt;br /&gt;&lt;br /&gt;Ans : True&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;21) When two threads are waiting on each other and can't proceed the programe is said to be in&lt;br /&gt;a deadlock?&lt;br /&gt;&lt;br /&gt;True/False&lt;br /&gt;&lt;br /&gt;Ans : True&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;22) Which method waits for the thread to die ?&lt;br /&gt;&lt;br /&gt;Ans : join() method&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;23) Which of the following is true?&lt;br /&gt;&lt;br /&gt;1) wait(),notify(),notifyall() are defined as final &amp;amp; can be called only from with in a synchronized method&lt;br /&gt;&lt;br /&gt;2) Among wait(),notify(),notifyall() the wait() method only throws IOException&lt;br /&gt;&lt;br /&gt;3) wait(),notify(),notifyall() &amp;amp; sleep() are methods of object class&lt;br /&gt;&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;1 &amp;amp; 2&lt;br /&gt;1,2 &amp;amp; 3 Ans : D&lt;br /&gt;&lt;br /&gt;24) Garbage collector thread belongs to which priority?&lt;br /&gt;&lt;br /&gt;Ans : low-priority&lt;br /&gt;&lt;br /&gt;25) What is meant by timeslicing or time sharing?&lt;br /&gt;&lt;br /&gt;Ans : Timeslicing is the method of allocating CPU time to individual threads in a priority&lt;br /&gt;schedule.&lt;br /&gt;&lt;br /&gt;26) What is meant by daemon thread? In java runtime, what is it's role?&lt;br /&gt;&lt;br /&gt;Ans : Daemon thread is a low priority thread which runs intermittently in the background doing the garbage collection operation for the java runtime system.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-1993246882108048159?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/1993246882108048159/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=1993246882108048159' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1993246882108048159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/1993246882108048159'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-multi-threading.html' title='Java Multi Threading'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-8156263202314180512</id><published>2007-12-12T04:45:00.000-08:00</published><updated>2007-12-12T04:48:35.413-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Inheritance'/><title type='text'>Java Inheritance</title><content type='html'>&lt;strong&gt;Java Inheritance&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;1) What is the difference between superclass &amp;amp; subclass?&lt;br /&gt;Ans : A super class is a class that is inherited whereas subclass is a class that does the inheriting.&lt;br /&gt;2) Which keyword is used to inherit a class?&lt;br /&gt;Ans : extends&lt;br /&gt;&lt;br /&gt;3) Subclasses methods can access superclass members/ attributes at all times?&lt;br /&gt;                   True/False&lt;br /&gt;&lt;br /&gt;Ans : False&lt;br /&gt;&lt;br /&gt;4) When can subclasses not access superclass members?&lt;br /&gt;&lt;br /&gt;Ans : When superclass is declared as private.&lt;br /&gt;&lt;br /&gt;5) Which class does begin Java class hierarchy?&lt;br /&gt;&lt;br /&gt;Ans : Object class&lt;br /&gt;&lt;br /&gt;6) Object class is a superclass of all other classes?&lt;br /&gt;&lt;br /&gt;True/FalseAns : True&lt;br /&gt;&lt;br /&gt;7) Java supports multiple inheritance?&lt;br /&gt;&lt;br /&gt;True/FalseAns : False&lt;br /&gt;&lt;br /&gt;8) What is inheritance?&lt;br /&gt;&lt;br /&gt;Ans : Deriving an object from an existing class. In the other words, Inheritance is the process of&lt;br /&gt;inheriting all the features from a class&lt;br /&gt;&lt;br /&gt;9) What are the advantages of inheritance?&lt;br /&gt;&lt;br /&gt;Ans : Reusability of code and accessibility of variables and methods of the superclass by subclasses.&lt;br /&gt;&lt;br /&gt;10) Which method is used to call the constructors of the superclass from the subclass?&lt;br /&gt;&lt;br /&gt;Ans : super(argument)&lt;br /&gt;&lt;br /&gt;11) Which is used to execute any method of the superclass from the subclass?&lt;br /&gt;&lt;br /&gt;Ans : super.method-name(arguments)&lt;br /&gt;&lt;br /&gt;12) Which methods are used to destroy the objects created by the constructor methods?&lt;br /&gt;&lt;br /&gt;Ans : finalize()&lt;br /&gt;&lt;br /&gt;13) What are abstract classes?&lt;br /&gt;&lt;br /&gt;Ans : Abstract classes are those for which instances can’t be created.&lt;br /&gt;&lt;br /&gt;14) What must a class do to implement an interface?&lt;br /&gt;&lt;br /&gt;Ans: It must provide all of the methods in the interface and identify the interface in its implements clause.&lt;br /&gt;&lt;br /&gt;15) Which methods in the Object class are declared as final?&lt;br /&gt;&lt;br /&gt;Ans : getClass(), notify(), notifyAll(), and wait()&lt;br /&gt;&lt;br /&gt;16) Final methods can be overridden.&lt;br /&gt;&lt;br /&gt;True/FalseAns : False&lt;br /&gt;&lt;br /&gt;17) Declaration of methods as final results in faster execution of the program?&lt;br /&gt;&lt;br /&gt;True/FalseAns: True&lt;br /&gt;&lt;br /&gt;18) Final variables should be declared in the beginning?&lt;br /&gt;&lt;br /&gt;True/FalseAns : True&lt;br /&gt;&lt;br /&gt;19) Can we declare variable inside a method as final variables? Why?&lt;br /&gt;&lt;br /&gt;Ans : Cannot because, local variable cannot be declared as final variables.&lt;br /&gt;&lt;br /&gt;20) Can an abstract class may be final?&lt;br /&gt;&lt;br /&gt;Ans : An abstract class may not be declared as final.&lt;br /&gt;&lt;br /&gt;21) Does a class inherit the constructors of it's super class?&lt;br /&gt;&lt;br /&gt;Ans: A class does not inherit constructors from any of it's super classes.&lt;br /&gt;&lt;br /&gt;22) What restrictions are placed on method overloading?&lt;br /&gt;&lt;br /&gt;Ans: Two methods may not have the same name and argument list but different return types.&lt;br /&gt;&lt;br /&gt;23) What restrictions are placed on method overriding?&lt;br /&gt;&lt;br /&gt;Ans : Overridden methods must have the same name , argument list , and return type. The&lt;br /&gt;overriding method may not limit the access of the method it overridees.The overriding method may not throw any exceptions that may not be thrown by the overridden method.&lt;br /&gt;&lt;br /&gt;24) What modifiers may be used with an inner class that is a member of an outer class?&lt;br /&gt;&lt;br /&gt;Ans : a (non-local) inner class may be declared as public, protected, private, static, final or abstract.&lt;br /&gt;&lt;br /&gt;25) How this() is used with constructors?&lt;br /&gt;&lt;br /&gt;Ans: this() is used to invoke a constructor of the same class&lt;br /&gt;&lt;br /&gt;26) How super() used with constructors?&lt;br /&gt;&lt;br /&gt;Ans : super() is used to invoke a super class constructor&lt;br /&gt;&lt;br /&gt;27) Which of the following statements correctly describes an interface?&lt;br /&gt;&lt;br /&gt;a)It's a concrete class&lt;br /&gt;&lt;br /&gt;b)It's a superclass&lt;br /&gt;&lt;br /&gt;c)It's a type of abstract class&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ans: c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;28) An interface contains __ methods&lt;br /&gt;&lt;br /&gt;a)Non-abstract&lt;br /&gt;&lt;br /&gt;b)Implemented&lt;br /&gt;&lt;br /&gt;c)unimplemented&lt;br /&gt;&lt;br /&gt;Ans:c&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-8156263202314180512?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/8156263202314180512/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=8156263202314180512' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/8156263202314180512'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/8156263202314180512'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-inheritance.html' title='Java Inheritance'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-3990160551626349672</id><published>2007-12-12T04:33:00.000-08:00</published><updated>2007-12-12T04:43:12.081-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='String'/><title type='text'>String in Java</title><content type='html'>&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;String in Java&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Handling character strings in Java is supported through two final classes:&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;String and StringBuffer. The String class implements immutable character strings, which are read-only once the string has been created and initialized, whereas the StringBuffer class implements dynamic character strings. All string literals in Java programs, are implemented as instances of String class. Strings in Java are 16-bit Unicode.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Note :&lt;/em&gt;&lt;/strong&gt; In JDK 1.5+ you can use StringBuilder, which works exactly like StringBuffer, but it is faster and not thread-safe&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;The easiest way of creating a String object is using a string literal:&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;String str1 = "I cant be changed once created!";&lt;br /&gt;&lt;br /&gt;A string literal is a reference to a String object. Since a string literal is a reference, it can be manipulated like any other String reference. i.e. it can be used to invoke methods of String class.&lt;br /&gt;For example,&lt;br /&gt;&lt;br /&gt;Int myLength = “Hello world”.length();&lt;br /&gt;&lt;br /&gt;The Java language provides special support for the string concatenation operator ( + ), which has been overloaded for Strings objects. String concatenation is implemented through the StringBuffer class and its append method.&lt;br /&gt;&lt;br /&gt;For example,&lt;br /&gt;&lt;br /&gt;String finalString = “Hello” + “World”&lt;br /&gt;Would be executed as&lt;br /&gt;String finalString = new StringBuffer().append(“Hello”).append(“World”).toString();&lt;br /&gt;The Java compiler optimizes handling of string literals. Only one String object is shared by all string having same character sequence. Such strings are said to be interned, meaning that they share a unique String object. The String class maintains a private pool where such strings are interned.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;For example,&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;String str1=”Hello”;&lt;br /&gt;&lt;br /&gt;String str2=”Hello”;&lt;br /&gt;&lt;br /&gt;If(str1 == str2)&lt;br /&gt;&lt;br /&gt;System.out.println(“Equal”);&lt;br /&gt;&lt;br /&gt;Would print Equal when run.&lt;br /&gt;&lt;br /&gt;Since the String objects are immutable. Any operation performed on one String reference will never have any effect on other references denoting the same object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;strong&gt;Constructors&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;String class provides various types of constructors to create String objects. Some of them are,&lt;br /&gt;String()&lt;br /&gt;Creates a new String object whose content is empty i.e. “”.&lt;br /&gt;String(String s)&lt;br /&gt;Creates a new String object whose content is same as the String object passed as an argument.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; Constructor creates a new string means it does not intern the String. Interned String object reference can be obtained by using intern() method of the String class&lt;br /&gt;String also provides constructors that take byte and char array as argument and returns String object.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;String equality&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;String class overrides the equals() method of the Object class. It compares the content of the two string object and returns the boolean value accordingly.&lt;br /&gt;&lt;br /&gt;For example,&lt;br /&gt;&lt;br /&gt;String str1=”Hello”;&lt;br /&gt;&lt;br /&gt;String str2=”Hello”;&lt;br /&gt;&lt;br /&gt;String str3=new String(”Hello”) //Using constructor.&lt;br /&gt;&lt;br /&gt;If(str1 == str2)&lt;br /&gt;&lt;br /&gt;System.out.println(“Equal 1”);&lt;br /&gt;&lt;br /&gt;Else&lt;br /&gt;&lt;br /&gt;System.out.println(“Not Equal 1”);&lt;br /&gt;&lt;br /&gt;If(str1 == str3)&lt;br /&gt;&lt;br /&gt;System.out.println(“Equal 2”);&lt;br /&gt;&lt;br /&gt;Else&lt;br /&gt;&lt;br /&gt;System.out.println(“I am constructed using constructor, hence&lt;br /&gt;not interned”);&lt;br /&gt;&lt;br /&gt;If( str1.equals(str3) )&lt;br /&gt;&lt;br /&gt;System.out.println(“Equal 3”);&lt;br /&gt;&lt;br /&gt;Else&lt;br /&gt;&lt;br /&gt;System.out.println(“Not Equal 3”);&lt;br /&gt;&lt;br /&gt;The output would be,&lt;br /&gt;&lt;br /&gt;Equal 1&lt;br /&gt;&lt;br /&gt;Not Equal 2&lt;br /&gt;&lt;br /&gt;Equal 3&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Note that == compares the references not the actual contents of the String object; Where as equals method compares actual contents of two String objects.&lt;br /&gt;String class also provides another method equalsIgnoreCase() which ignores the case of contents while comparing.&lt;br /&gt;&lt;br /&gt;Apart from these methods String class also provides compareTo methods.&lt;br /&gt;&lt;br /&gt;int compareTo(String str2)&lt;br /&gt;&lt;br /&gt;This method compares two Strings and returns an int value. It returns value 0, if this string is equal to the string argument a value less than 0, if this string is less than the string argument&lt;br /&gt;a value greater than 0, if this string is greater than the string argument&lt;br /&gt;&lt;br /&gt;int compareTo(Object object)&lt;br /&gt;&lt;br /&gt;This method behaves exactly like the first method if the argument object is actually a String object; otherwise, it throws a ClassCastException.&lt;br /&gt;&lt;br /&gt;String Manipulations&lt;br /&gt;&lt;br /&gt;Reading characters from String:&lt;br /&gt;&lt;br /&gt;char charAt(index i)&lt;br /&gt;&lt;br /&gt;Returns char at specified index. An index ranges from 0 to length() -1.&lt;br /&gt;&lt;br /&gt;Searching characters in String&lt;br /&gt;&lt;br /&gt;String class provides indexOf method which searches for the specified character inside the string object. This method has been overloaded. If the search is successful, then it returns the index of the char otherwise -1 is returned.&lt;br /&gt;&lt;br /&gt;int indexOf(int c)&lt;br /&gt;&lt;br /&gt;Returns the index of first occurrence of the argument char.&lt;br /&gt;&lt;br /&gt;int indexOf(int c, int fromIndex)&lt;br /&gt;&lt;br /&gt;Finds the index of the first occurrence of the argument character in a string, starting at the index specified in the second argument.&lt;br /&gt;&lt;br /&gt;int indexOf(String str)&lt;br /&gt;&lt;br /&gt;Finds the start index of the first occurrence of the substring argument in a String.&lt;br /&gt;&lt;br /&gt;int indexOf(String str, int fromIndex)&lt;br /&gt;&lt;br /&gt;Finds the start index of the first occurrence of the substring argument in a String, starting at the index specified in the second argument.&lt;br /&gt;&lt;br /&gt;The String class also provides methods to search for a character or string in backward direction. These methods are given below.&lt;br /&gt;&lt;br /&gt;int lastIndexOf(int ch)&lt;br /&gt;&lt;br /&gt;int lastIndexOf(int ch, int fromIndex)&lt;br /&gt;&lt;br /&gt;int lastIndexOf(String str)&lt;br /&gt;&lt;br /&gt;int lastIndexOf(String str, int fromIndex)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Replacing characters in String&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The replace method of String can be used to replace all occurrences of the specified character with given character.&lt;br /&gt;&lt;br /&gt;String replace(char oldChar, int newchar)&lt;br /&gt;&lt;br /&gt;Getting substrings&lt;br /&gt;&lt;br /&gt;String class provides substring method to extract specified portion of the given String. This method has been overloaded.&lt;br /&gt;&lt;br /&gt;String substring(int startIndex)&lt;br /&gt;&lt;br /&gt;String substring(int startIndex, int endIndex)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; A new String object containing the substring is created and returned. The original String won’t be affected.&lt;br /&gt;&lt;br /&gt;If the index value is not valid, a StringIndexOutOfBoundsException is thrown.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Conversions&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;String class provides set of static overloaded valueOf method to convert primitives and object into strings.&lt;br /&gt;&lt;br /&gt;static String valueOf(Object obj)&lt;br /&gt;&lt;br /&gt;static String valueOf(char[] character)&lt;br /&gt;&lt;br /&gt;static String valueOf(boolean b)&lt;br /&gt;&lt;br /&gt;static String valueOf(char c)&lt;br /&gt;&lt;br /&gt;static String valueOf(int i)&lt;br /&gt;&lt;br /&gt;static String valueOf(long l)&lt;br /&gt;&lt;br /&gt;static String valueOf(float f)&lt;br /&gt;&lt;br /&gt;static String valueOf(double d)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Manipulating Character Case&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;String class provides following methods to manipulate character case in String.&lt;br /&gt;&lt;br /&gt;String toUpperCase()&lt;br /&gt;&lt;br /&gt;String toUpperCase(Locale locale)&lt;br /&gt;&lt;br /&gt;String toLowerCase()&lt;br /&gt;&lt;br /&gt;String toLowerCase(Locale locale)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Note :&lt;/em&gt;&lt;/strong&gt; Original String object is returned if none of the characters changed, otherwise new String object is constructed and returned.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Miscellaneous methods&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;String trim()&lt;br /&gt;&lt;br /&gt;This method removes white space from the front and the end of a String.&lt;br /&gt;&lt;br /&gt;int length()&lt;br /&gt;&lt;br /&gt;Returns length of the String.&lt;br /&gt;&lt;br /&gt;String intern()&lt;br /&gt;&lt;br /&gt;This method returns interned String object, if already present in the String pool. Otherwise this String is added into the pool, and then interned reference is returned.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-3990160551626349672?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/3990160551626349672/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=3990160551626349672' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3990160551626349672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3990160551626349672'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/string-in-java-handling-character.html' title='String in Java'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-2549799654943440865</id><published>2007-12-12T04:17:00.000-08:00</published><updated>2007-12-12T04:32:43.016-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Exceptions'/><title type='text'>Java Exceptions</title><content type='html'>&lt;strong&gt;&lt;em&gt;Java Exceptions&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;Explain the user defined Exceptions?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;User defined Exceptions are custom Exception classes defined by the user for specific purpose. A user defined exception can be created by simply sub-classing an Exception class or a subclass of an Exception class. This allows custom exceptions to be generated (using throw clause) and caught in the same way as normal exceptions.Example:class CustomException extends Exception {}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What classes of exceptions may be caught by a catch clause?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types. Errors are generally irrecoverable conditions.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is the difference between exception and error?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Error's are irrecoverable exceptions. Usually a program terminates when an error is encountered.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is the difference between throw and throws keywords?&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;The throw keyword denotes a statement that causes an exception to be initiated. It takes the Exception object to be thrown as an argument. The exception will be caught by an enclosing try-catch block or propagated further up the calling hierarchy. The throws keyword is a modifier of a method that denotes that an exception may be thrown by the method. An exception can be rethrown.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What class of exceptions are generated by the Java run-time system?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The Java runtime system generates Runtime Exceptions and Errors.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is the base class for Error and Exception?&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Throwable.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What are Checked and Unchecked Exceptions?&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Making an exception checked forces client programmers to deal with the exception may be thrown. Checked exceptions must be caught at compile time.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Example:&lt;/em&gt;&lt;/strong&gt; IOException.Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked.&lt;br /&gt;&lt;br /&gt;With an unchecked exception, however, the compiler doesn't force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. Example: ArrayIndexOutOfBoundsException. Errors are often irrecoverable conditions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;Does the code in finally block get executed if there is an exception and a return statement in a catch block?&lt;br /&gt;Or&lt;br /&gt;What is the purpose of the finally clause of a try-catch-finally statement?&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught. If an exception occurs and there is a return statement in catch block, the finally block is still executed.&lt;br /&gt;&lt;br /&gt;The finally block will not be executed when the System.exit(0) statement is executed earlier or on system shut down earlier or the memory is used up earlier before the thread goes to finally block.&lt;br /&gt;&lt;br /&gt;try{&lt;br /&gt;//some statements&lt;br /&gt;}catch&lt;br /&gt;{//statements when exception is caught&lt;br /&gt;}finally{&lt;br /&gt;//statements executed whether exception occurs or not&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Does the order of placing catch statements matter in the catch block?&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Yes, it does. The FileNoFoundException is inherited from the IOException. So FileNoFoundException is caught before IOException. Exception’s subclasses have to be caught first before the General Exception.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-2549799654943440865?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/2549799654943440865/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=2549799654943440865' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/2549799654943440865'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/2549799654943440865'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-exceptions.html' title='Java Exceptions'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-3566687725374834817</id><published>2007-12-12T04:06:00.000-08:00</published><updated>2007-12-12T04:15:18.775-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Swings'/><title type='text'>Java Swings</title><content type='html'>&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Java Swings&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;What is the difference between Swing and AWT components?&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;AWT components are heavy-weight, whereas Swing components are lightweight. Hence Swing works faster than AWT. Heavy weight components depend on the local windowing toolkit. For example, java.awt.Button is a heavy weight component. Pluggable look and feel possible using java Swing. Also, we can switch from one look and feel to another at runtime in swing which is not possible in AWT.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;Name the containers which use Border Layout as their default layout?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;window, Frame and Dialog classes.Name Container classes.Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane.&lt;br /&gt;&lt;br /&gt;H&lt;strong&gt;&lt;span style="color:#993300;"&gt;ow can a GUI component handle its own events? &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is the difference between the paint() and repaint() methods?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Which package has light weight components?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;javax.Swing package contains light weight components. All components in Swing, except JApplet, JDialog, JFrame and JWindow are lightweight components.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What are peerless components?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The peerless components are called light weight components.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is a Container in a GUI?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Container contains and arranges other components (including other containers) through the use of layout managers, which use specific layout policies to determine where components should go as a function of the size of the container&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;How are the elements of a GridBagLayout organized?&lt;br /&gt;Or&lt;br /&gt;What is a layout manager and what are different types of layout managers available in java Swing?&lt;br /&gt;Or&lt;br /&gt;How are the elements of different layouts organized?&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;A layout manager is an object that is used to organize components in a container. The different layouts available are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBagLayout.FlowLayout:&lt;br /&gt;&lt;br /&gt;The elements of a FlowLayout are organized in a top to bottom, left to right fashion.BorderLayout: The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container.CardLayout:&lt;br /&gt;The elements of a CardLayout are stacked, on top of the other, like a deck of cards.GridLayout:&lt;br /&gt;&lt;br /&gt;The elements of a GridLayout are of equal size and are laid out using the square of a grid.GridBagLayout:&lt;br /&gt;&lt;br /&gt;The elements of a GridBagLayout are organized according to a grid. However, the elements may be different sizes and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What advantage do Java's layout managers provide over traditional windowing systems?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Since Java's layout managers aren't tied to absolute sizing and positioning, they are able to accommodate platform-specific differences among windowing systems.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What method is used to specify a container's layout?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The setLayout() method is used to specify a container's layout. For example, setLayout(new FlowLayout()); will be set the layout as FlowLayout.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Which Container method is used to cause a container to be laid out and redisplayed?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;validate()Name Component subclasses that support painting.The Canvas, Frame, Panel, and Applet classes support painting.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is the purpose of the enableEvents() method?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The enableEvents() method is used to enable an event for a particular component. Normally, an event is enabled when a listener is added to an object for a particular event. The enableEvents() method is used by objects that handle events by overriding their event-dispatch methods.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is the difference between a Window and a Frame?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The Frame class extends Window to define a main application window that can have a menu bar.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What do heavy weight components mean?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Heavy weight components like Abstract Window Toolkit (AWT) depend on the local windowing toolkit. For example, java.awt .Button is a heavy weight component.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is the difference between a Scrollbar and a ScrollPane?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A Scrollbar is just a Component, but not a Container. A ScrollPane is a Container. A ScrollPane handles its own events and performs its own scrolling.What is the preferred size of a component?The preferred size of a component is the minimum component size that will allow the component to display normally.Which containers use a FlowLayout as their default layout?The Panel and Applet classes use the FlowLayout as their default layout.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-3566687725374834817?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/3566687725374834817/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=3566687725374834817' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3566687725374834817'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3566687725374834817'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-swings.html' title='Java Swings'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-2055889984056540836</id><published>2007-12-12T03:42:00.000-08:00</published><updated>2007-12-12T04:04:58.466-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads'/><title type='text'>Java Threads</title><content type='html'>&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Java Threads&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#cc0000;"&gt;What are different ways in which a thread can enter the waiting state?&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc0000;"&gt;&lt;/span&gt;&lt;br /&gt;A thread can enter the waiting state by the following ways:&lt;br /&gt;&lt;br /&gt;1. Invoking its sleep() method,&lt;br /&gt;&lt;br /&gt;2. By blocking on I/O&lt;br /&gt;&lt;br /&gt;3. By unsuccessfully attempting to acquire an object's lock&lt;br /&gt;&lt;br /&gt;4. By invoking an object's wait() method.&lt;br /&gt;&lt;br /&gt;5. It can also enter the waiting state by invoking its (deprecated) suspend() method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;What is the difference between yielding and sleeping?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When a task invokes its yield() method, it returns to the ready state, either from waiting, running or after its creation. When a task invokes its sleep() method, it returns to the waiting state from a running state.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;&lt;strong&gt;How to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;&lt;strong&gt;Or&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;&lt;strong&gt;Extending Thread class or implementing Runnable Interface. Which is better?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;You have two ways to do so. First, making your class "extends" Thread class. The other way is making your class implement "Runnable" interface. The latter is more advantageous, cause when you are going for multiple inheritance, then only interface can help. . If you are already inheriting a different class, then you have to go for Runnable Interface.&lt;br /&gt;&lt;br /&gt;Otherwise you can extend Thread class. Also, if you are implementing interface, it means you have to implement all methods in the interface. Both Thread class and Runnable interface are provided for convenience and use them as per the requirement. But if you are not extending any class, better extend Thread class as it will save few lines of coding. Otherwise performance wise, there is no distinguishable difference. A thread is in the ready state after it has been created and started.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is mutual exclusion? How can you take care of mutual exclusion using Java threads?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Mutual exclusion is a phenomenon where no two processes can access critical regions of memory at the same time. Using Java multithreading we can arrive at mutual exclusion. For mutual exclusion, you can simply use the synchronized keyword and explicitly or implicitly provide an Object, any Object, to synchronize on. The synchronized keyword can be applied to a class, to a method, or to a block of code. There are several methods in Java used for communicating mutually exclusive threads such as wait( ), notify( ), or notifyAll( ). For example, the notifyAll( ) method wakes up all threads that are in the wait list of an object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is the difference between preemptive scheduling and time slicing?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then re-enters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#993300;"&gt;What invokes a thread's run() method?&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;After a thread is started, via its start() method of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is the purpose of the wait(), notify(), and notifyAll() methods?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The wait(), notify() and notifyAll() methods are used to provide an efficient way for thread inter-communication.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is thread? What are the high-level thread states?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Or&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What are the states associated in the thread?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A thread is an independent path of execution in a system. The high-level thread states are ready, running, waiting and dead.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is deadlock?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When two threads are waiting for each other and can’t proceed until the first thread obtains a lock on the other thread or vice versa, the program is said to be in a deadlock.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;How does multithreading take place on a computer with a single CPU?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What are synchronized methods and synchronized statements?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Can Java object be locked down for exclusive use by a given thread?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Or&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What happens when a thread cannot acquire a lock on an object?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Yes. You can lock an object by putting it in a "synchronized" block. The locked object is inaccessible to any thread other than the one that explicitly claimed it. If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What’s the difference between the methods sleep() and wait()?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The sleep method is used when the thread has to be put aside for a fixed amount of time. Ex: sleep(1000), puts the thread aside for exactly one second. The wait method is used to put the thread aside for up to the specified time. It could wait for much lesser time if it receives a notify() or notifyAll() call. Ex: wait(1000), causes a wait of up to one second. The method wait() is defined in the Object and the method sleep() is defined in the class Thread.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is the difference between process and thread?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A thread is a separate path of execution in a program. A Process is a program in execution.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is daemon thread and which method is used to create the daemon thread?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Daemon threads are threads with low priority and runs in the back ground doing the garbage collection operation for the java runtime system. The setDaemon() method is used to create a daemon thread. These threads run without the intervention of the user.&lt;br /&gt;&lt;br /&gt;To determine if a thread is a daemon thread, use the accessor method isDaemon()When a standalone application is run then as long as any user threads are active the JVM cannot terminate, otherwise the JVM terminates along with any daemon threads which might be active.&lt;br /&gt;&lt;br /&gt;Thus a daemon thread is at the mercy of the runtime system. Daemon threads exist only to serve user threads.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What do you understand by Synchronization?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;OrWhat is synchronization and why is it important?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;OrDescribe synchronization in respect to multithreading?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;OrWhat is synchronization?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;With respect to multithreading, Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access a particular resource at a time.&lt;br /&gt;&lt;br /&gt;In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption which may otherwise lead to dirty reads and significant errors.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;synchronizing a function:&lt;br /&gt;&lt;br /&gt;public synchronized void Method1 ()&lt;br /&gt;{&lt;br /&gt;// method code.&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;E.g.&lt;br /&gt;&lt;br /&gt;synchronizing a block of code inside a function:&lt;br /&gt;public Method2 ()&lt;br /&gt;{&lt;br /&gt;synchronized (this)&lt;br /&gt;{&lt;br /&gt;// synchronized code here.&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;When you will synchronize a piece of your code?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When you expect that your shared code will be accessed by different threads and these threads may change a particular data causing data corruption, then they are placed in a synchronized construct or a synchronized method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;Why would you use a synchronized block vs. synchronized method?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Synchronized blocks place locks for shorter periods than synchronized methods.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What is an object's lock and which objects have locks?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Answer: An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;Can a lock be acquired on a class?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#993300;"&gt;What state does a thread enter when it terminates its processing?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When a thread terminates its processing, it enters the dead state.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;How would you implement a thread pool?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Public class ThreadPool implements ThreadPoolIntThis class is an generic implementation of a thread pool, which takes the following input&lt;br /&gt;&lt;br /&gt;a) Size of the pool to be constructed&lt;br /&gt;&lt;br /&gt;b) Name of the class which implements Runnable and constructs a thread pool with active threads that are waiting for activation.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Once the threads have finished processing they come back and wait once again in the pool.This thread pool engine can be locked i.e. if some internal operation is performed on the pool then it is preferable that the thread engine be locked. Locking ensures that no new threads are issued by the engine.&lt;br /&gt;&lt;br /&gt;However, the currently executing threads are allowed to continue till they come back to the passivePool.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#993300;"&gt;&lt;strong&gt;Is there a separate stack for each thread in Java?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Yes. Every thread maintains its own separate stack, called Runtime Stack but they share the same memory. Elements of the stack are the method invocations, called activation records or stack frame. The activation record contains pertinent information about a method like local variables.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-2055889984056540836?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/2055889984056540836/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=2055889984056540836' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/2055889984056540836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/2055889984056540836'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/java-threads-what-are-different-ways-in.html' title='Java Threads'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-5197346150166469661</id><published>2007-12-12T03:04:00.000-08:00</published><updated>2007-12-12T03:16:22.361-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Wrapper Classes'/><title type='text'>Wrapper Classes</title><content type='html'>&lt;strong&gt;&lt;span style="color:#cc6600;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc6600;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;&lt;strong&gt;What are Wrapper Classes?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Describe the wrapper classes in Java.Wrapper classes are classes that allow primitive types to be accessed as objects.&lt;br /&gt;&lt;br /&gt;Wrapper class is wrapper around a primitive data type.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;&lt;strong&gt;&lt;em&gt;Following table lists the primitive types and the corresponding wrapper classes:&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Primitive&lt;br /&gt;&lt;br /&gt;Wrapper&lt;br /&gt;&lt;br /&gt;Boolean&lt;br /&gt;&lt;br /&gt;java.lang.Boolean&lt;br /&gt;&lt;br /&gt;Byte&lt;br /&gt;&lt;br /&gt;java.lang.Byte&lt;br /&gt;&lt;br /&gt;Char&lt;br /&gt;&lt;br /&gt;java.lang.Character&lt;br /&gt;&lt;br /&gt;double&lt;br /&gt;&lt;br /&gt;java.lang.Double&lt;br /&gt;&lt;br /&gt;Float&lt;br /&gt;&lt;br /&gt;java.lang.Float&lt;br /&gt;&lt;br /&gt;Intjava.lang.Integer&lt;br /&gt;&lt;br /&gt;Longjava.lang.Long&lt;br /&gt;&lt;br /&gt;Shortjava.lang.Short&lt;br /&gt;&lt;br /&gt;Void&lt;br /&gt;&lt;br /&gt;java.lang.Void&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-5197346150166469661?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/5197346150166469661/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=5197346150166469661' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/5197346150166469661'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/5197346150166469661'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/12/wrapper-classes.html' title='Wrapper Classes'/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-4848024844091479069</id><published>2007-11-06T03:06:00.000-08:00</published><updated>2007-11-06T03:11:35.319-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='HIBERNATE'/><title type='text'></title><content type='html'>&lt;strong&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:180%;" &gt;&lt;span style="font-weight: normal; font-style: italic; color: rgb(153, 0, 0);"&gt;&lt;br /&gt;HIBERNATE&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. What is  Hibernate?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;§ Object/Relational (OR) Mapping  Tool.&lt;br /&gt;Object-relational mapping is, mapping object-oriented programming  objects to relational databases managed by MYSQL, Oracle, DB2, Sybase, and other  relational database managers (RDBMS).&lt;br /&gt;§ Helps in Transparent  Persistence.&lt;br /&gt;Object-relational mapping products have the ability to directly  manipulate the data stored in the relational database using object oriented  programming. This is in contrast to the database sub-language used by Embedded  SQL or call interface used by JDBC or ODBC.&lt;br /&gt;§ An object-relational mapping  product is likely to reduce programmer code and, through caching, improve  performance.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;strong&gt;2. Why use  Hibernate?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Hibernate provides a lot of advantages over  the traditional method of interacting with the database.&lt;br /&gt;§ &lt;strong&gt;Ease of  interaction with the Database:&lt;/strong&gt;&lt;br /&gt;Hibernate maps plain old java  objects(that have simple getter/setter methods for the attributes in the table)  to the tables already created in the database using the .hbm.xml files (also  called mapping files), provides queries to insert, update, delete etc. data in  the tables though it does not help in creating tables.&lt;br /&gt;&lt;strong&gt;§ JDBC Calls  not required:&lt;/strong&gt;&lt;br /&gt;A hibernate. properties file, which has details about  the database, needs to be created. While configuring Hibernate, this properties  file is looked up for connecting to the database without the user having to make  the JDBC calls and thereby avoids the hard coding of IP, port, username,  password etc in the code. The driver for the database needs to be  included.&lt;br /&gt;&lt;strong&gt;§ The Hibernate Query Language (HQL):&lt;br /&gt;&lt;/strong&gt;Database  related queries should be written in this language and Hibernate converts it to  a query that is supported by the underlying Database.&lt;br /&gt;&lt;strong&gt;Advantages of  using HQL: &lt;/strong&gt;&lt;br /&gt;o HQL facilitates writing database independent queries.  These are converted to SQL queries specific to the underlying database at  runtime. Learning SQL specific to the database is not a must.&lt;br /&gt;o Makes the  application program very loosely coupled with the underlying  database.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;3. Tools that support  Hibernate:&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;XDoclet&lt;br /&gt;AndroMDA&lt;br /&gt;Middlegen&lt;br /&gt;Spring  FrameWork&lt;br /&gt;All these tools help us generate the objects and/or mapping  documents used in Hibernate.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4. Using  Hibernate:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;To use Hibernate the following documents need to be  in place.&lt;br /&gt;Note:-Samples of these files can be found in the attachment named  source.zip&lt;br /&gt;§ The jar files specific to Hibernate. (details are given  below)&lt;br /&gt;§ Hibernate.properties file.&lt;br /&gt;§ Bean Class which is a POJO (Plain  Old Java Object) which represents the Table.&lt;br /&gt;§ Mapping Document which is a  XML.&lt;br /&gt;§ The Application Program.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4.1 The Jar  files:&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Having obtained the Hibernate package, include the  following jar files in the Classpath. The jar files are:&lt;br /&gt;§ hibernate2.jar  ;&lt;br /&gt;§ ehcache-0.7.jar ;&lt;br /&gt;§ cglib-full-2.0.1.jar ;&lt;br /&gt;§ xerces-2.4.0.jar  ;&lt;br /&gt;§ dom4j-1.5.jar ;&lt;br /&gt;§ jta.jar ;&lt;br /&gt;§ j2ee.jar ;&lt;br /&gt;§  commons-collections-2.1.jar ;&lt;br /&gt;§  mysql-connector-java-3.0.14-production-bin.jar ;&lt;br /&gt;Most of these jar files can  be found in the lib folder of the package. MySQL-connector and J2EE .jar files  need to be procured. MySQL Connector is being used since the DB used in the  application is MYSQL. The driver for the MySQL Database can be found in this  jar. Hence depending on the Database that the application demands, corresponding  driver needs to be procured.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4.2 Table in the  Database:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Tables need to be created before running the  application. Hibernate does not help in creating tables. Its main purpose is to  make the transient data persistent with least trouble. The table that is used in  the example has the following fields:&lt;br /&gt;&lt;br /&gt;§ SerialNo: - Serial Number, which  is the primary key and is an auto increment.&lt;br /&gt;§ FirstName:- First name of the  employee&lt;br /&gt;§ LastName: - Last name of the employee.&lt;br /&gt;&lt;br /&gt;Note: - The database  that is used is MySQL. The database is not on the local machine. It is in the  network.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The DDL used for creating the Table  is:&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;“Create table tblEmpDetails (&lt;br /&gt;SerialNo int primary key  auto_increment,&lt;br /&gt;FirstName varchar (15),&lt;br /&gt;LastName varchar  (15));”&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4.3 Hibernate. properties  file:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Databases usually have various details linked to them. All  these are reflected in the file hibernate.properties. This file holds details  like:&lt;br /&gt;§ IP Address of the Database.&lt;br /&gt;§ User ID.&lt;br /&gt;§ Password&lt;br /&gt;§ Dialect(  This is specific to the database , and can be obtained from the hibernate  API)&lt;br /&gt;§ Other details like connection-pool, show-sql, etc.&lt;br /&gt;This file comes  with the Hibernate package in the folder src. It needs to be modified to suit  the applications requirements.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4.4 Defining Persistent Domain  Object:&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;This is basically the bean class that has simple  getter/setter methods for the attributes that are specified in the table.  Inorder to persist data, the bean class is instantiated and using the setter  methods, data is set. The object is then saved to the database. The Persistent  Domain object in the example is EmpDetails.java. Mapping of the bean class to  the table happens in the .hbm.xml file also called the mapping file explained  next.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4.5 Hibernate mapping File:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Mapping  files in Hibernate are basically XML files. The various tags and their functions  are given below. An xml file corresponding to the bean and the table is given in  the attachment (EmpDetails.hbm.xml). The DTD-(Document Type Definition)-for the  xml file is predefined and can be found in the hibernate package in the folder  src\net\sf\hibernate. While compiling the XML document, the application searches  for the DTD in the URL specified. If it fails to locate it then it searches for  it in the hibernate package itself. The various tags that were used are given  below.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-4848024844091479069?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/4848024844091479069/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=4848024844091479069' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/4848024844091479069'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/4848024844091479069'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/11/1_2501.html' title=''/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-8772900978224069849</id><published>2007-11-06T03:02:00.000-08:00</published><updated>2007-11-06T03:06:39.087-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='EJB'/><title type='text'></title><content type='html'>&lt;span style="font-style: italic; color: rgb(204, 0, 0);font-size:180%;" &gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;EJB&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(204, 0, 0);"&gt;1.1 UNDERSTANDING THE EJB ARCHITECTURE &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There should be a tight coupling  between the Web Tier and the EJB Tier.&lt;br /&gt;This is accomplished by the IService  and the ServiceImpl.&lt;br /&gt;&lt;br /&gt;All the EJB calls must be in the IService interface.  These methods in the Interface must be implemented in the ServiceImpl  class.&lt;br /&gt;The constructor of the ServiceImpl, gets the handle to the remote  through the BusinessServiceFactory and the ServiceLocator classes. The  ServiceLocator gets the handle through the JNDI name. ServiceLocator looks up  and reads the services-config.xml file and retrieves the JNDI Name of the  Services corresponding to the name. From the JNDI name it gives the handle to  the EJB. If the handle is in cache, then it is returned from cache. Otherwise, a  new handle is created. This handle is used by the rest of all methods to contact  the EJB Tier (Façade). Façade gives the handle to the FacadeEJB.&lt;br /&gt;&lt;br /&gt;The  EJBHelper will help to create handles to the LocalEJBs. There can be more than  one LocalEJB. Every ‘LocalEJB’ will have its corresponding ‘Local’. The  EJBHelper gets a handle to the Local which in turn gives a call to the LocalEJB.  Every method in the FacadeEJB gets the handle to the appropriate Local via the  EJBHelper. And then corresponding call is made with this handle. There can also  be many Helper classes for every LocalEJB so that the functionalities are split  up and diversified.&lt;br /&gt;&lt;br /&gt;When the number of EJB methods is finite or limited,  we need not go for LocalEJB. The functionalities can b accomplished by having  one EJB. In that case, the Façade becomes the Remote and all the functionalities  are implemented in the EJB(only one created).&lt;br /&gt;&lt;br /&gt;The LocalEJBs and the  Helper classes can have private methods for simplification of the work to be  performed. These private methods are explicitly for those classes that  implement.&lt;br /&gt;&lt;br /&gt;Flow is like this.&lt;br /&gt;&lt;br /&gt;IService à ServiceImpl à Façade à  FacadeEJB à Local à LocalEJB à Helper Classes (if any)&lt;br /&gt;&lt;br /&gt;Façade pattern is  followed when the redirection of EJB calls are required.&lt;br /&gt;There can be more  than one LocalEJb. Different calls can be in different Ejbs. Different LocalEJBs  can be created for different purposes. From FacadeEJB, the calls can be made to  the appropriate EJB.&lt;br /&gt;There can be many EJB calls. Instead of mounting all the  EJB calls, in one Local EJB, they can be split and more LocalEJBs and helper  classes can be created.&lt;br /&gt;&lt;br /&gt;1.2 CREATION OF ISERVICE&lt;br /&gt;&lt;br /&gt;Create a new  Java interface in util package named as I&lt;modulename&gt;Service. Copy the whole  code from the existing IuserService and paste it in the newly created Iservice  class and change the name of the class to the I&lt;modulename&gt;Service. Remove all  the methods.&lt;br /&gt;&lt;br /&gt;Ex.&lt;br /&gt;public interface IWorkFlowService&lt;br /&gt;extends  IService&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;1.3 CREATION OF SERVICEIMPL&lt;br /&gt;&lt;br /&gt;Create a new Java  class in web package named as &lt;modulename&gt;ServiceImpl. Copy the whole code from  the existing UserServiceImpl and paste it in the newly created ServiceImpl.  Change the name of the class to the newly created class. Modify the constructor  appropriately as in UserServiceImpl. Remove all the other methods.&lt;br /&gt;&lt;br /&gt;Ex.  Text written in &lt;this color=""&gt;needs to be changed appropriately to your  ServiceImpl&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public WorkFlowServiceImpl()&lt;br /&gt;{&lt;br /&gt;//Get the instance  of Service Locator&lt;br /&gt;_serviceLocator =  ServiceLocator.getInstance();&lt;br /&gt;&lt;br /&gt;//Initialize the service  Locator&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;_serviceLocator.init();&lt;br /&gt;}&lt;br /&gt;catch  (ServiceLocatorException  e2)&lt;br /&gt;{&lt;br /&gt;e2.printStackTrace();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;//Get the handle to  the Home&lt;br /&gt;_workflowHome =&lt;br /&gt;(WorkFlowFacadeHome)  _serviceLocator&lt;br /&gt;.getRemoteHome(WorkFlowServiceImpl.SERVICE_NAME,&lt;br /&gt;WorkFlowFacadeHome.class);&lt;br /&gt;}&lt;br /&gt;catch  (ServiceLocatorException e1)&lt;br /&gt;{&lt;br /&gt;if  (_log.isDebugEnabled())&lt;br /&gt;{&lt;br /&gt;_log.debug("Service Exception: Service" +&lt;br /&gt;"  not located");&lt;br /&gt;}&lt;br /&gt;e1.printStackTrace();&lt;br /&gt;&lt;br /&gt;}//handle  Exception&lt;br /&gt;&lt;br /&gt;//Obtain the Remote Interface from the Home  Reference&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;_workflowRemote = _workflowHome.create();&lt;br /&gt;}&lt;br /&gt;catch  (RemoteException e)&lt;br /&gt;{&lt;br /&gt;// e.printStackTrace();&lt;br /&gt;//To be Replaced with  Logging Code&lt;br /&gt;}&lt;br /&gt;catch (CreateException e)&lt;br /&gt;{&lt;br /&gt;//  e.printStackTrace();&lt;br /&gt;//To be replaced with Logging  code&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;1.4 CREATION OF FACADE&lt;br /&gt;&lt;br /&gt;Create a new Java class  in the ejb package named as &lt;modulename&gt;Façade.&lt;br /&gt;Copy the code from the  existing UserFacade and paste it in the newly created class. Change the name of  the class. Except for the EJB methods, remove all the other methods.&lt;br /&gt;All your  methods in Facade must throw RemoteException.&lt;br /&gt;&lt;br /&gt;Ex.&lt;br /&gt;public ProcessTO  fetchAllSteps()&lt;br /&gt;throws RemoteException,WorkFlowException;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1.5  CREATION OF FAÇADE EJB&lt;br /&gt;&lt;br /&gt;Create a new Java class in the ejb package named  as &lt;modulename&gt;FacadeEJB. Copy the code from UserFacadeEJB to the newly created  class. Change the name of the class. Except for the EJB methods like ejbCreate,  ejbPassivate, ejbRemove, setSessionContext, replaceWithRealBusinessMethod …  remove all the other methods.&lt;br /&gt;&lt;br /&gt;If you need to create LocalEJBs, then do  the following. If you need to go for ServiceDelegates go to section  1.10.&lt;br /&gt;&lt;br /&gt;1.6 CREATION OF LOCAL&lt;br /&gt;&lt;br /&gt;Create a new Java class in the ejb  package named as &lt;modulename&gt;Local.&lt;br /&gt;Copy the existing code from the UserLocal  to the newly created class. Change the name of the class. Remove all the  methods.&lt;br /&gt;&lt;br /&gt;1.7 CREATION OF LOCAL EJBs&lt;br /&gt;&lt;br /&gt;Create a new class in the ejb  package named as &lt;modulename&gt;LocalEJB. Copy the code from UserLocalEJB and paste  it. Change the name of the newly created class. Remove all the methods except  for the EJB specific methods like ejbCreate, ejbPassivate, ejbRemove,  setSessionContext, replaceWithRealBusinessMethod, …&lt;br /&gt;&lt;br /&gt;1.8 CREATION OF  FAÇADE HOME&lt;br /&gt;&lt;br /&gt;Create a new class in the ejb package named as  &lt;modulename&gt;FacadeHome .Copy the code from UserFacadeHome and paste it. Change  the name of the newly created class. Change the return type of the create()  method appropriately.&lt;br /&gt;&lt;br /&gt;Ex.&lt;br /&gt;public WorkFlowFacade create()&lt;br /&gt;throws  RemoteException, CreateException;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1.9 CREATION OF  EJBHELPER&lt;br /&gt;&lt;br /&gt;Create the Java class in the ejb package named as  &lt;modulename&gt;EJBHelper&lt;br /&gt;Copy the code from UserEJBHelper and paste it. Change  the name of the newly created class. Modify the existing method  appropriately.&lt;br /&gt;Ex.&lt;br /&gt;localHome =  (WorkFlowLocalHome)&lt;br /&gt;ServiceLocator.getInstance()&lt;br /&gt;getLocalHome(WorkFlowConstants.&lt;br /&gt;WORKFLOW_LOCAL_SERVICE);&lt;br /&gt;&lt;br /&gt;Note:  WorkFlowConstants is a constants file created in util package.&lt;br /&gt;&lt;br /&gt;1.10  CREATION OF META-INF, ejb-jar.xml and weblogic-jar.xml&lt;br /&gt;&lt;br /&gt;Create a new  folder under the ejb package “META-INF”.&lt;br /&gt;&lt;br /&gt;Create a new XML file named as  weblogic-jar.xml.&lt;br /&gt;Copy the code in weblogic-jar.xml of ejb package of User  module.&lt;br /&gt;Paste it in the newly created xml file. Change the entries in the xml  file, for the EJB being created by replacing the UserLocalEJB entries and remove  the entries for TeamLocalEJB.&lt;br /&gt;&lt;br /&gt;Ex.&lt;br /&gt;FACADEEJB&lt;br /&gt;&lt;br /&gt;&lt;weblogic-enterprise-bean&gt;&lt;br /&gt;&lt;ejb-name&gt;&lt;br /&gt;WorkFlowFacadeEJB&lt;br /&gt;&lt;/ejb-name&gt;&lt;br /&gt;&lt;stateless-session-descriptor&gt;&lt;br /&gt;&lt;pool&gt;&lt;br /&gt;&lt;/pool&gt;&lt;br /&gt;&lt;stateless-clustering&gt;&lt;br /&gt;&lt;/stateless-clustering&gt;&lt;br /&gt;&lt;/stateless-session-descriptor&gt;&lt;br /&gt;&lt;transaction-descriptor&gt;&lt;br /&gt;&lt;/transaction-descriptor&gt;&lt;br /&gt;&lt;jndi-name&gt;&lt;br /&gt;WorkFlowFacadeEJB&lt;br /&gt;&lt;/jndi-name&gt;&lt;br /&gt;&lt;/weblogic-enterprise-bean&gt;&lt;br /&gt;LOCALEJB&lt;br /&gt;&lt;weblogic-enterprise-bean&gt;&lt;br /&gt;&lt;ejb-name&gt;&lt;br /&gt;WorkFlowLocalEJB&lt;br /&gt;&lt;/ejb-name&gt;&lt;br /&gt;&lt;stateless-session-descriptor&gt;&lt;br /&gt;&lt;pool&gt;&lt;br /&gt;&lt;/pool&gt;&lt;br /&gt;&lt;stateless-clustering&gt;&lt;br /&gt;&lt;/stateless-clustering&gt;&lt;br /&gt;&lt;/stateless-session-descriptor&gt;&lt;br /&gt;&lt;transaction-descriptor&gt;&lt;br /&gt;&lt;/transaction-descriptor&gt;&lt;br /&gt;&lt;local-jndi-name&gt;&lt;br /&gt;WorkFlowLocalEJB&lt;br /&gt;&lt;/local-jndi-name&gt;&lt;br /&gt;&lt;/weblogic-enterprise-bean&gt;&lt;br /&gt;&lt;br /&gt;Create  a new XML file named as ejb-jar.xml&lt;br /&gt;Copy the code in ejb-jar.xml of ejb  package of User module.&lt;br /&gt;Paste it in the newly created xml file. Change the  entries in the xml file, for the EJB being created by replacing the UserLocalEJB  entries and remove the entries for TeamLocalEJB.&lt;br /&gt;&lt;br /&gt;Create 2 new  &lt;session&gt;entries for FacadeEJB and LocalEJB  respectively.&lt;br /&gt;Ex.&lt;br /&gt;FACADEEJB&lt;br /&gt;&lt;session&gt;&lt;br /&gt;&lt;ejb-name&gt;&lt;br /&gt;WorkFlowFacadeEJB&lt;br /&gt;&lt;/ejb-name&gt;&lt;br /&gt;&lt;home&gt;&lt;br /&gt;com.gm.pqms.domain.workflow.ejb.WorkFlowFacadeHome&lt;br /&gt;&lt;/home&gt;&lt;br /&gt;&lt;remote&gt;&lt;br /&gt;com.gm.pqms.domain.workflow.ejb.WorkFlowFacade&lt;br /&gt;&lt;/remote&gt;&lt;br /&gt;&lt;ejb-class&gt;&lt;br /&gt;com.gm.pqms.domain.workflow.ejb.WorkFlowFacadeEJB&lt;br /&gt;&lt;/ejb-class&gt;&lt;br /&gt;&lt;session-type&gt;&lt;br /&gt;Stateless&lt;br /&gt;&lt;/session-type&gt;&lt;br /&gt;&lt;transaction-type&gt;&lt;br /&gt;Bean&lt;br /&gt;&lt;/transaction-type&gt;&lt;br /&gt;&lt;/session&gt;&lt;br /&gt;LOCALEJB&lt;br /&gt;&lt;session&gt;&lt;br /&gt;&lt;ejb-name&gt;&lt;br /&gt;WorkFlowLocalEJB&lt;br /&gt;&lt;/ejb-name&gt;&lt;br /&gt;&lt;local-home&gt;&lt;br /&gt;com.gm.pqms.domain.workflow.ejb.WorkFlowLocalHome&lt;br /&gt;&lt;/local-home&gt;&lt;br /&gt;&lt;local&gt;&lt;br /&gt;com.gm.pqms.domain.workflow.ejb.WorkFlowLocal&lt;br /&gt;&lt;/local&gt;&lt;br /&gt;&lt;ejb-class&gt;&lt;br /&gt;com.gm.pqms.domain.workflow.ejb.WorkFlowLocalEJB&lt;br /&gt;&lt;/ejb-class&gt;&lt;br /&gt;&lt;session-type&gt;&lt;br /&gt;Stateless&lt;br /&gt;&lt;/session-type&gt;&lt;br /&gt;&lt;transaction-type&gt;&lt;br /&gt;Bean&lt;br /&gt;&lt;/transaction-type&gt;&lt;br /&gt;&lt;/session&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Open  the BusinessServiceFactory.java in arch.util package for editing. Add a new  constant to the existing constants for &lt;modulenme_service&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ex.&lt;br /&gt;public static final String WORKFLOW_SERVICE = "WORKFLOW_SERVICE";&lt;br /&gt;&lt;br /&gt;Add a new entry in the file for ServiceImpl as follows  .&lt;br /&gt;&lt;br /&gt;Ex.&lt;br /&gt;classMap.put(BusinessServiceFactory.WORKFLOW_SERVICE,  "com.gm.pqms.domain.workflow.web.WorkFlowServiceImpl");&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1.11  MODIFICATION OF EXISTING XML FILES&lt;br /&gt;Open build.xml in WebRoot/WEB-INF package  for editing.&lt;br /&gt;Add a new &lt;antcall&gt;&lt;/antcall&gt;for the ejb  created.&lt;br /&gt;&lt;br /&gt;Ex.&lt;br /&gt;&lt;antcall target="compile-ejbs-weblogic"&gt;&lt;br /&gt;&lt;br /&gt;&lt;param name="package-name" value="workflow"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/antcall&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Open  application.xml in the same package for editing.&lt;br /&gt;Add a new entry  &lt;ejb-client.jar&gt;for the ejb  created.&lt;br /&gt;&lt;br /&gt;Ex.&lt;br /&gt;&lt;module&gt;&lt;br /&gt;&lt;ejb&gt;workflow-ejb.jar&lt;/ejb&gt;&lt;br /&gt;&lt;/module&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Open  service-config.xml file in the arch.util package for editing.&lt;br /&gt;Add a new  entry for the ejb  created.&lt;br /&gt;&lt;br /&gt;Ex.&lt;br /&gt;&lt;service&gt;&lt;br /&gt;&lt;name&gt;WORKFLOW_SERVICE&lt;/name&gt;&lt;br /&gt;&lt;jndiname&gt;WorkFlowFacadeEJB&lt;/jndiname&gt;&lt;br /&gt;&lt;/service&gt;&lt;br /&gt;&lt;br /&gt;&lt;service&gt;&lt;br /&gt;&lt;name&gt;WORKFLOW_LOCAL_SERVICE&lt;/name&gt;&lt;br /&gt;&lt;jndiname&gt;WorkFlowLocalEJB&lt;/jndiname&gt;&lt;br /&gt;&lt;/service&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--  END --&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;P.S : Every method in the FacadeEJB must be included in  IService, ServiceImpl, Façade, FacadeEJB, Local and LocalEJB.&lt;/ejb-client.jar&gt;&lt;/modulenme_service&gt;&lt;/session&gt;&lt;/modulename&gt;&lt;/modulename&gt;&lt;/modulename&gt;&lt;/modulename&gt;&lt;/modulename&gt;&lt;/modulename&gt;&lt;/this&gt;&lt;/modulename&gt;&lt;/modulename&gt;&lt;/modulename&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-8772900978224069849?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/8772900978224069849/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=8772900978224069849' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/8772900978224069849'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/8772900978224069849'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/11/ejb-1.html' title=''/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-3876903675522310751</id><published>2007-11-06T02:58:00.000-08:00</published><updated>2007-11-06T03:02:37.222-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JVM faqs2'/><title type='text'></title><content type='html'>&lt;span style="font-size:180%;"&gt;&lt;strong style="font-weight: normal; font-style: italic;"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;JVM FAQs&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;&lt;br /&gt;1.What is JVM?&lt;br /&gt;&lt;/span&gt;A Java Virtual Machine is a  runtime environment required for execution of a Java application.Every Java  application runs inside a runtime instance of some concrete implementation of  abstract specifications of JVM.It is JVM which is crux of 'platform independent'  nature of the language.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;2.What is a JVM  consisted of?&lt;/span&gt;&lt;br /&gt;Each time a Java Application is executed then an  instance of JVM ,responsible for its running,is created.A JVM instance is  described in terms of subsystems, memory areas, data types, and instructions.The  block diagram given below,depicts a view of Internal Architecture of JVM  :&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;3.What is a class loader and what is its  responsibilities?&lt;br /&gt;&lt;/span&gt;The Class loader is a subsystem of a JVM which is  responsible,predominantly for loading classes and interfaces in the system.Apart  from this,a class loader is responsible for the following  activities:-Verification of imported types(classes and interfaces)-Allocating  memory for class variables and initializing them to default values.Static fields  for a class are created and these are set to standard default values but they  are not explicitly initialized.The method tables are constructed for the  class.-Resolving symbolic references from type to direct references The class  loaders can be of two types: a bootstrap or primordial class loader and user  defined class loaderEach JVM has a bootstrap class loader which loads trusted  classes , including classes from Java API.JVM specs do not tell how to locate  these classes and is left to implementation designers.A Java application with  user defined class loader objects can customize class loading.These load  untrustworthy classes and not an intrinsic part of JVM.They are written in  Java,converted to class files and loaded into the JVM and installed like any  other objects.If you want to read this in more details then read Chapter 8,"The  Linking Model" of Inside Java 2 Virtual Machine by Bill Venners.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4.  &lt;a href="http://interviewjava.blogspot.com/2007/04/what-is-heap-and-stack.html" target="_blank"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;What is heap and  stack?&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;br /&gt;&lt;/span&gt;The heap is the part of  memory of JVM where all objects reside.The stack is consisted of stack  frames.When a thread invokes a method,the JVM pushes a new frame onto that  thread's Java stack.Each stack frame is consisted of operand stack and the local  variable array.All arguments,local variables,intermediate computations and  return values if any are kept in these stack corresponding to the method  invoked.The stack frame on the top of the stack is called the active stack  frame,which is the current place of execution.When the method completes, the  virtual machine pops and discards the frame for that  method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;5. How is your Java program  executed inside JVM?&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;When JVM executes a Java application, a  runtime instance of JVM is born.This runtime instance invoke main() method of  Java application.The main() method of an application serves as the starting  point for that application's initial thread. The initial thread can in turn fire  off other threads.This thread has a program counter(PC) and Java stack.Whenever  main() method is invoked, a stack frame is pushed onto the stack,this then  becomes the active tack frame.The program counter in the new Java stack frame  will point to the beginning of the method.If there are more method invocations  within main() method then this process of pushing new stack frame onto the stack  for each method call is repeated as and when they are invoked.When a method  returns, the active frame is popped from the stack and the one below becomes the  active stack frame.The PC is set to the instruction after the method call and  the method continues.There is only one heap corresponding to an instance of JVM  and all objects created are stored here.This heap is shared by all threads  created in an application.Inside the Java virtual machine, threads come in two  flavors: daemon and non- daemon. A daemon thread is ordinarily a thread used by  the virtual machine itself, such as a thread that performs garbage collection.  The application, however, can mark any threads it creates as daemon threads. The  initial thread of an application--the one that begins at main()--is a non-  daemon thread.A Java application continues to execute (the virtual machine  instance continues to live) as long as any non-daemon threads are still running.  When all non-daemon threads of a Java application terminate, the virtual machine  instance will exit. If permitted by the security manager, the application can  also cause its own demise by invoking the exit() method of class Runtime or  System.When main() returns,it terminates the application's only non-daemon  thread, which causes the virtual machine instance to exit.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;6. What is Java class file's magic number?&lt;/span&gt;&lt;br /&gt;A Magic Number of a  class file is a unique identifier for tools to quickly differentiate class files  from non class files.The first four bytes of each Java class file has the magic  value as 0xCAFEBABE.And the answer to why this number,I do not actually know but  there may be very few sensible and acceptable options possible constructed from  letters A-F which can surely not be 'CAFEFACE' or 'FADECAFE'....&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java4interview.blogspot.com/" target="_blank"&gt;7. How JVM performs Thread Synchronization?&lt;/a&gt;&lt;br /&gt;JVM associates a  lock with an object or a class to achieve mutilthreading. A lock is like a token  or privilege that only one thread can "possess" at any one time. When a thread  wants to lock a particular object or class, it asks the JVM.JVM responds to  thread with a lock maybe very soon, maybe later, or never. When the thread no  longer needs the lock, it returns it to the JVM. If another thread has requested  the same lock, the JVM passes the lock to that thread.If a thread has a lock,no  other thread can access the locked data until the thread that owns the lock  releases it.The JVM uses locks in conjunction with monitors. A monitor is  basically a guardian in that it watches over a sequence of code, making sure  only one thread at a time executes the code.Each monitor is associated with an  object reference. It is the responsibility of monitor to watch an arriving  thread must obtain a lock on the referenced object.When the thread leaves the  block,it releases the lock on the associated object.A single thread is allowed  to lock the same object multiple times.JVM maintains a count of the number of  times the object has been locked. An unlocked object has a count of zero. When a  thread acquires the lock for the first time, the count is incremented to one.  Each time the thread acquires a lock on the same object, a count is incremented.  Each time the thread releases the lock, the count is decremented. When the count  reaches zero, the lock is released and made available to other threads.In Java  language terminology, the coordination of multiple threads that must access  shared data is called synchronization. The language provides two built-in ways  to synchronize access to data: with synchronized statements or synchronized  methods.The JVM does not use any special opcodes to invoke or return from  synchronized methods. When the JVM resolves the symbolic reference to a method,  it determines whether the method is synchronized. If it is, the JVM acquires a  lock before invoking the method. For an instance method, the JVM acquires the  lock associated with the object upon which the method is being invoked. For a  class method, it acquires the lock associated with the class to which the method  belongs. After a synchronized method completes, whether it completes by  returning or by throwing an exception, the lock is released.Two opcodes,  monitorenter and monitorexit are used by JVM for accomplishing this task.When  monitorenter is encountered by the Java virtual machine, it acquires the lock  for the object referred to by objectref on the stack. If the thread already owns  the lock for that object, a count is incremented. Each time monitorexit is  executed for the thread on the object, the count is decremented. When the count  reaches zero, the monitor is released.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;8.How JVM performs Garbage Collection?&lt;/span&gt;&lt;br /&gt;Whenever a reference  to an object on heap lies dangling or no longer in use then it becomes eligible  for being garbage collected by JVM.JVM specifications do not force any specific  kind of garbage collection algorithm though there are several algorithms like  reference counting,tracing,compacting,copying,generational etc. in place.It is  very important that garbage collection should be efficient and non interfering  in execution of Java programs.There is a trade off between ease of  implementation versus better performance while implementing garbage collection  feature for a JVM.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;9. How to profile heap  usage?&lt;/span&gt;&lt;br /&gt;Try using -Xaprof to get a profile of the allocations (objects  and sizes) of your application.Also try -agentlib:hprof=heap=all (or other  option, try -agentlib:hprof=help for a list).&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;10. What will you do if VM exits while printing  "OutOfMemoryError" and increasing max heap size doesn't help?&lt;br /&gt;&lt;/span&gt;The Java  HotSpot VM cannot expand its heap size if memory is completely allocated and no  swap space is available. This can occur, for example, when several applications  are running simultaneously. When this happens, the VM will exit after printing a  message similar to the following.Exception java.lang.OutOfMemoryError: requested  bytesIf you see this symptom, consider increasing the available swap space by  allocating more of your disk for virtual memory and/or by limiting the number of  applications you run simultaneously. You may also be able to avoid this problem  by setting the command-line flags -Xmx and -Xms to the same value to prevent the  VM from trying to expand the heap. Note that simply increasing the value of -Xmx  will not help when no swap space is available.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;11. Should one pool objects to help Garbage  Collector?Should one call System.gc() periodically?&lt;br /&gt;&lt;/span&gt;The answer is  No!Pooling objects will cause them to live longer than necessary. The garbage  collection methods will be much more efficient if you let it do the memory  management. The strong advice is taking out object pools.Don't call System.gc(),  HotSpot will make the determination of when its appropriate and will generally  do a much better job.&lt;br /&gt;&lt;br /&gt;12. &lt;a href="http://interviewjava.blogspot.com/2007/04/application-has-lot-of-threads-and-is.html" target="_blank"&gt;An application has a lot of threads and is running out of memory,  why?&lt;/a&gt;&lt;br /&gt;You may be running into a problem with the default stack size for  threads. In Java SE 6, the default on Sparc is 512k in the 32-bit VM, and 1024k  in the 64-bit VM. On x86 Solaris/Linux it is 320k in the 32-bit VM and 1024k in  the 64-bit VM.On Windows, the default thread stack size is read from the binary  (java.exe). As of Java SE 6, this value is 320k in the 32-bit VM and 1024k in  the 64-bit VM.You can reduce your stack size by running with the -Xss option.  For example:java -server -Xss64kNote that on some versions of Windows, the OS  may round up thread stack sizes using very coarse granularity. If the requested  size is less than the default size by 1K or more, the stack size is rounded up  to the default; otherwise, the stack size is rounded up to a multiple of 1  MB.64k is the least amount of stack space allowed per thread.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;13. If your program is I/O bound or running in native  methods, do these activities engage JVM?&lt;br /&gt;&lt;/span&gt;The answer is 'No'.If the  program is I/O bound or running in native methods, then the VM is not involved  in the consumption of CPU time. The VM technology will engage CPU for running  bytecodes. Typical examples of time spent not running bytecode are graphical  operations that make heavy use of native methods, and I/O operations such as  reading and writing data to network sockets or database files.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://java4interview.blogspot.com/"&gt;14. What is the difference between interpreted code and compiled  code?&lt;/a&gt;&lt;br /&gt;An interpreter produces a result from a program, while a compiler  produces a program written in assembly language and in case of Java from  bytecodes.The scripting languages like JavaScript,Python etc. require  Interpreter to execute them.So a program written in scripting language will  directly be executed with interpreter installed on that computer,if it is absent  then this program will not execute.While in case of compiled code,an assembler  or a virtual machine in case of Java is required to convert assembly level code  or bytecodes into machine level instructions/commands.Generally, interpreted  programs are slower than compiled programs, but are easier to debug and  revise.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;15. Why Java based GUI intensive  program has performance issues?&lt;/span&gt;&lt;br /&gt;GUI intensive Java application mostly  run underlying OS specific native libraries which is time and more CPU cycles  consuming.&lt;br /&gt;The overall performance of a Java application depends on four  factors:&lt;br /&gt;The design of the application&lt;br /&gt;The speed at which the virtual  machine executes the Java bytecodes&lt;br /&gt;The speed at which the libraries that  perform basic functional tasks execute (in native code)&lt;br /&gt;The speed of the  underlying hardware and operating system&lt;br /&gt;The virtual machine is responsible  for byte code execution, storage allocation, thread synchronization, etc.  Running with the virtual machine are native code libraries that handle input and  output through the operating system, especially graphics operations through the  window system. Programs that spend significant portions of their time in those  native code libraries will not see their performance on HotSpot improved as much  as programs that spend most of their time executing byte codes.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;16. What is 64 bit Java ?&lt;/span&gt;&lt;br /&gt;A 64-bit version of  Java has been available to Solaris SPARC users since the 1.4.0 release of J2SE.  A 64-bit capable J2SE is an implementation of the Java SDK (and the JRE along  with it) that runs in the 64-bit environment of a 64-bit OS on a 64-bit  processor. The primary advantage of running Java in a 64-bit environment is the  larger address space.This allows for a much larger Java heap size and an  increased maximum number of Java Threads, which is needed for certain kinds of  large or long-running applications. The primary complication in doing such a  port is that the sizes of some native data types are changed. Not surprisingly  the size of pointers is increased to 64 bits. On Solaris and most Unix  platforms, the size of the C language long is also increased to 64 bits. Any  native code in the 32-bit SDK implementation that relied on the old sizes of  these data types is likely to require updating.Within the parts of the SDK  written in Java things are simpler, since Java specifies the sizes of its  primitive data types precisely. However even some Java code needs updating, such  as when a Java int is used to store a value passed to it from a part of the  implementation written in C.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;17. What is the difference between JVM and JRE?&lt;/span&gt;&lt;br /&gt;A Java Runtime  Environment (JRE) is a prerequisite for running Java applications on any  computer.A JRE contains a Java Virtual Machine(JVM),all standard,core java  classes and runtime libraries. It does not contain any development tools such as  compiler, debugger, etc. JDK(Java Development Kit) is a whole package required  to Java Development which essentially contains JRE+JVM,and tools required to  compile and debug,execute Java applications&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-3876903675522310751?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/3876903675522310751/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=3876903675522310751' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3876903675522310751'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3876903675522310751'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/11/jvm-faqs-1.html' title=''/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-190379325236741934</id><published>2007-11-06T02:55:00.000-08:00</published><updated>2007-11-06T02:57:58.483-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='CORE JAVA faqs2'/><title type='text'></title><content type='html'>&lt;span style="font-size:180%;"&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(204, 0, 0);"&gt;&lt;br /&gt;&lt;br /&gt;CORE JAVA faqs2&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Why stop and suspend method are deprecated?&lt;br /&gt;Stop() terminates the thread  abruptly while suspend() method blocks a thread until another thread calls  resume () on it.&lt;br /&gt;Stop () method will leave an object in inconsistent state  because it immediately gives up locks on all other object that it has locked.  For example, during transfer of money from one account to other account if the  transfer thread is stopped, the bank account object is damaged. When a thread  wants to stop another thread, it doesn’t know when it is safe to stop that  thread. So it has been deprecated.&lt;br /&gt;Suspend () method frequently leads to  deadlocks .It can be invoked on a thread externally at any point of time without  the threads consent which is not desired. For this reason it has been  deprecated.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is difference between sleep() ,wait()and suspend() of a Thread  ?&lt;br /&gt;Thread.sleep() sends the current thread into the "Not Runnable" state for  some amount of time. The thread keeps the monitors it has acquired -- i.e. if  the thread is currently in a synchronized block or method no other thread can  enter this block or method. If another thread calls t.interrupt () it will wake  up the sleeping thread.&lt;br /&gt;Note that sleep is a static method, which means that  it always affects the current thread (the one that is executing the sleep  method). A common mistake is to call t.sleep() where t is a different thread;  even then, it is the current thread that will sleep, not the t  thread.&lt;br /&gt;t.suspend() is deprecated. Using it is possible to halt a thread  other than the current thread. A suspended thread keeps all its monitors and  since this state is not interruptible it is deadlock prone.&lt;br /&gt;object.wait()  sends the current thread into the "Not Runnable" state, like sleep(), but with a  twist. Wait is called on a object, not a thread; we call this object the "lock  object." Before lock.wait() is called, the current thread must synchronize on  the lock object; wait() then releases this lock, and adds the thread to the  "wait list" associated with the lock. Later, another thread can synchronize on  the same lock object and call lock.notify(). This wakes up the original, waiting  thread. Basically, wait()/notify() is like sleep()/interrupt(), only the active  thread does not need a direct pointer to the sleeping thread, but only to the  shared lock object.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is "starvation" when used in the context of the Java threading  model?&lt;br /&gt;· Starvation is when the Java runtime (JVM) doesn't allocate time to a  thread to execute. This may be due to a poor scheduling algorithm (like green  Threads under Solaris, where a for loop from 1 to 1 million doing something CPU  intensive wouldn't yield the CPU under Solaris but would under Windows), poor  programming practice (not returning from the paint() method in an applet), or a  hostile attack (like hitting a host with a denial of service attack where the  CPU is busy outside the Java process).&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is a daemon thread?&lt;br /&gt;· Daemon is a thread that has only purpose in  life is to serve others.&lt;br /&gt;· When only daemon threads remain, the program  exits.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is the difference between a “Green thread” and “Native thread”&lt;br /&gt;&lt;br /&gt;·  Green Threads" are the default threads that are provided in the JDK, while the  "Native Threads" are the one provided by the native Operating System.Normally  "Native Threads" provide better performance because they are controlled by the  kernel of the system, allowing the JVM to better use the resources offered by  the system itself.For example, in a multiprocessor system "Green Threads" will  never be able to use Solaris or Linux or Windows specified kernel calls to  optimize the use of the processors.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is an object graph?&lt;br /&gt;&lt;br /&gt;· When used in connection with  serialization, an object graph is a tree structure rooted at the object you have  written to the ObjectOutputStream. The branches and leaves of the tree are all  the objects, which are reachable by following references from the root object.  This structure is maintained by the ObjectOutputStream in order to ensure that  the complete reachable state of the given object is serialized and to handle  cyclic dependencies. The graph is computed on the fly, during the serialization  process.&lt;br /&gt;A side-effect of maintaining this graph is that an object which has  already been written to the stream will not be written again - it will be  replaced by an object stream identifier, simply a number used to point at the  previously object. To force a changed object to be written in its entirety, you  need to reset() the stream, which clears the object graph&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Can a Vector or a Hashtable be serialized and deserialized?&lt;br /&gt;&lt;br /&gt;· Both  these classes implement Serializable, and have been designed for serialization.  So yes, they can be serialized.&lt;br /&gt;· In order to serialize a collection like  Vector or Hashtable, you must also be able to serialize all of the objects  contained in these collections. Otherwise, the collection would not be able to  be completely restored. Your program will throw a NotSerializableException  unless all objects stored in the Vector or Hashtable are also  serializable.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Is writing an object to an ObjectOutputStream a thread-safe  operation?&lt;br /&gt;&lt;br /&gt;· Absolutely not. Serialization, i.e. passing an object  reference to the writeObject () method of ObjectOutputStream, is not an atomic  operation. Serialization involves traversing a graph of objects, each of which  contributes to the state of the object being serialized, saving the state of  each object in turn. This is a time-consuming procedure. If other threads are  allowed to concurrently access or modify any one of the objects in the graph you  could get undefined and unwanted results.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is the advantage of using Externalizable over Serializable?&lt;br /&gt;&lt;br /&gt;·  Externalization allows a class to specify the methods to be used to write the  object's contents to a stream and to read them back. By implementing  Externalizable you can win performance at the cost of flexibility and extra code  to maintain. If you implement Externalizable you stream the data directly  without the need for reflection, which is used in the case of  Serializable.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is JNDI and what is its use?&lt;br /&gt;&lt;br /&gt;· JNDI is Java Naming and Directory  Services provides a standard interface to locate users, machines, networks,  objects and services.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Define a naming service?&lt;br /&gt;&lt;br /&gt;· Associates names with objects, which is  otherwise called binding.&lt;br /&gt;· It provides a facility to find objects based on  names, which is otherwise known as look-up.&lt;br /&gt;· When it is required to locate a  machine on the network, DNS is used to translate the machine name to IP  Address.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is a directory object? Is it different from naming object?&lt;br /&gt;· A  directory object can store attributes with it. A directory metadata contains how  the directory is structured.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What are the standard naming and directory services available?&lt;br /&gt;· LDAP,  NIS (Network Information services) and NDS (Novell Directory Services).&lt;br /&gt;61.  What are the advantages of using JNDI?&lt;br /&gt;· It is unified to system to access  all sorts of directory service information.&lt;br /&gt;· It is single API to access  different directories with different protocols.&lt;br /&gt;· It insulates application  from protocol and implementation details.&lt;br /&gt;· It is extensible. Future provider  of directories can plug in their particular directory services to JNDI without  affecting client code.&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-190379325236741934?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/190379325236741934/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=190379325236741934' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/190379325236741934'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/190379325236741934'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/11/core-java-faqs2-why-stop-and-suspend.html' title=''/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-8142423805844415469</id><published>2007-11-06T02:52:00.000-08:00</published><updated>2007-11-06T02:55:39.462-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='CORE JAVA faqs'/><title type='text'></title><content type='html'>&lt;span style="font-style: italic; font-weight: bold; color: rgb(204, 102, 0);font-size:180%;" &gt;&lt;br /&gt;&lt;br /&gt;CORE JAVA faqs&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;What is the difference between an Interface and Abstract class ?&lt;/span&gt;&lt;br /&gt;· A  class may implement several interfaces where as it can extend only one abstract  class.&lt;br /&gt;· An interface cannot provide any code at all, much less default code  where as an abstract class can provide complete code, default code, and/or just  stubs that has to be overridden.&lt;br /&gt;· Static final constants can use the  interfaces without qualification in classes that implement the interface where  as both static constants and instance variables can use the abstract  classes.&lt;br /&gt;· Interface implementation can be added to any existing third part  classes where as third party classes must be rewritten to extend from the  abstract classes.&lt;br /&gt;· Interfaces are used to often represent peripheral ability  of a class, not central identity where as abstract class defines core identity  of its descendants.&lt;br /&gt;· If various implementations share is method signature  then Interface works best where as If the various implementations are all of a  kind and share a common status and behavior, usually an abstract class works  best.&lt;br /&gt;· Interface is slow where as abstract class is fast in  performance.&lt;br /&gt;· If you add a new method to an interface, you must track down  all implementations of that interface in the universe and provide them with a  concrete implementation of that method where as in case of an abstract class if  you add a new method to an abstract class, you have the option of providing a  default implementation of it. Then all existing code will continue to work  without change.&lt;br /&gt;· You can put shared code into an abstract class, where you  cannot into an interface.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;How do you write user-defined exceptions in Java?&lt;br /&gt;· To write user-defined  exception in java, you exception class should extend Exception base class have  call the super class methods in your own methods.&lt;br /&gt;What is multiple  inheritance? Is it supported in java?&lt;br /&gt;· This means one object having multiple  parents, which is not truly supported in java but supported in C++. But overall  design of java suggests that we can implement multiple inheritances in java  using interfaces.  &lt;/li&gt;&lt;li&gt;What is difference between an inner class and static inner class?&lt;br /&gt;· A  non-static inner class may have object instances that are associated with  instances of the class's outer class. A static inner class does not have any  object instances.&lt;br /&gt;What is an inner class and what is its advantage?&lt;br /&gt;·  Inner class is class, which is defined inside a class as private class and  always bears a reference to the outer class.&lt;br /&gt;o Inner classes can be nested  within the body of a method.&lt;br /&gt;· Scope of inner class is the entire enclosing  class in which the inner class is nested.&lt;br /&gt;· Inner classes can access  attributes and methods in nesting class.&lt;br /&gt;· Each inner class is compiled into  a separate. class file labeled:NestingClass$InnerClass.&lt;br /&gt;· Inner classes can  contain methods that return handles to inner class instances.&lt;br /&gt;· Major  advantage of inner classes is the ability to create adaptor classes that  implement an interface.&lt;br /&gt;o Make all inner classes private to ensure hidden  implementation.&lt;br /&gt;o Rather than handle classes returning inner classes, they  return interfaces.&lt;br /&gt;· Inner classes frequently used with event handling in  applets.  &lt;/li&gt;&lt;li&gt;What is a transient variable?&lt;br /&gt;o The variable, which cannot be serialized,  is known as transient variable.&lt;br /&gt;What are wrapped classes?&lt;br /&gt;o Wrapped  classes are classes that allow primitive types to be accessed as  objects.&lt;br /&gt;What is an immutable object and what are its advantages?&lt;br /&gt;· An  immutable object is an object and any object it references that does not change  after construction. The object is, therefore, immutable for its lifetime.&lt;br /&gt;·  Immutable classes are commonly used to represent strings, colors, and numeric  values.&lt;br /&gt;Advantage:&lt;br /&gt;· They guarantee that their state cannot change after  construction, they are inherently thread-safe.  &lt;/li&gt;&lt;li&gt;What are basic rules, which govern creation of immutable classes?&lt;br /&gt;·  Declare the class final.&lt;br /&gt;· Declare all data private.&lt;br /&gt;· Provide only getter  methods and no setter methods.&lt;br /&gt;· Set all instance data in the  constructor.&lt;br /&gt;· Clone mutable objects for which a reference to them is  returned.&lt;br /&gt;· Clone mutable objects for which a reference to them is  received.&lt;br /&gt;· Implement a deep clone if the default shallow clone is not  correct for a properly behaved immutable object.  &lt;/li&gt;&lt;li&gt;&lt;br /&gt;What is a Java package and how is it used?&lt;br /&gt;· A Java package is a  naming context for classes and interfaces. A package is used to create a  separate name space for groups of classes and interfaces. Packages are also used  to organize related classes and interfaces into a single API unit and to control  accessibility to these classes and interfaces&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What restrictions are placed on method overriding?&lt;br /&gt;· Overridden methods  must have the same name, argument list, and return type.&lt;br /&gt;· The overriding  method may not limit the access of the method it overrides.&lt;br /&gt;· The overriding  method may not throw any exceptions that may not be thrown by the overridden  method.  &lt;/li&gt;&lt;li&gt;What is use of this and super key words?&lt;br /&gt;· ‘this’ is used for referring  to current instance of the object where as ‘super’ is used to refer to variables  and methods of its super class.&lt;br /&gt;· Incase of constructors, this() is used to  invoke a constructor of the same class. super() is used to invoke a superclass  constructor.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is the difference between a static and non-static variable?&lt;br /&gt;· A  static variable is associated with the class as a whole rather than with  specific instances of a class. Non-static variables take on unique values with  each object instance.&lt;br /&gt;What is polymorphism and what are different types of  polymorphism?&lt;br /&gt;· One name, different form and there are three forms.&lt;br /&gt;1.  Method overloading&lt;br /&gt;2. Method overriding through Interfaces&lt;br /&gt;3. Method  overriding through java interfaces.&lt;br /&gt;What is the essence of run-time  polymorphism behavior?&lt;br /&gt;With runtime polymorphism based on method overriding,  the decision as to which version of a method will be executed is based on the  actual type of object whose reference is stored in the reference variable, and  not on the type of the reference variable on which the method is invoked.&lt;br /&gt;The  decisions as to which version of the method to invoke cannot be made at compile  time. That decision must be deferred and made at runtime. This is sometimes  referred to as late binding.&lt;br /&gt;What is a singleton class and how to implement  it? What are the advantages of Singleton class?&lt;br /&gt;Singleton classes are created  to have only one instance.&lt;br /&gt;A singleton may be used to represent some unique  system.&lt;br /&gt;It is generally implemented by keeping the constructor private.&lt;br /&gt;It  should have static members and methods.&lt;br /&gt;The main advantage of singleton class  is memory management( Garbage collection)&lt;br /&gt;Why java prohibits use of  ‘synchronized’ inside a constructor ?&lt;br /&gt;because other threads cannot get a  reference to the object until construction of the object completes. This has got  a performance overhead.&lt;br /&gt;What do you mean by Garbage collection and what are  its advantages and disadvantages?&lt;br /&gt;The purpose of garbage collection is to  identify and discard objects that are no longer needed by a program so that  their resources may be reclaimed.&lt;br /&gt;An object is eligible for garbage  collection when its reference is set to null. Method variables or local  variables are eligible for Garbage collection when they go out of  scope.&lt;br /&gt;Garbage Collection cannot be forced explicitly. JVM may do garbage  collection if it is running short of memory.The call System.gc() does NOT force  the garbage collection but only suggests that the JVM may make an effort to do  garbage collection.&lt;br /&gt;It frees up the heap space and takes care of heap  fragmentation.&lt;br /&gt;It also helps to ensure program integrity as programmers are  unable to crash the JVM by incorrectly freeing the memory accidentally or  purposefully.&lt;br /&gt;The only disadvantage is garbage-collected heap is a  performance overhead.&lt;br /&gt;What do you mean by conservative garbage  collector?&lt;br /&gt;The garbage collectors that cannot distinguish between genuine  object references and look-alikes.&lt;br /&gt;Can an object's finalize () method be  invoked while it is reachable?&lt;br /&gt;An object's finalize() method cannot be  invoked by the garbage collector while the object is still reachable. However,  an object's finalize() method may be invoked by other objects.&lt;br /&gt;How many times  may an object's finalize() method be invoked by the garbage collector and when  it is invoked ?&lt;br /&gt;An object's finalize() method may only be invoked once by the  garbage collector when the object is unreachable.  &lt;/li&gt;&lt;li&gt;Does garbage collection guarantee that a program will not run out of  memory?&lt;br /&gt;Garbage collection does not guarantee that a program will not run out  of memory. It is possible for programs to use up memory resources faster than  they are garbage collected. It is also possible for programs to create objects  that are not subject to garbage collection.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;How does the distributed garbage collection work in java?&lt;br /&gt;· The RMI  subsystem implements a reference counting-based distributed garbage collection  (DGC) algorithm to provide automatic memory management facilities for remote  server objects.&lt;br /&gt;· Basically, DGC works by having the remote server keep track  of all external client references to it at any given time. When a client obtains  a remote reference, it is addded to the remote object's referenced set. The DGC  then marks the remote object as dirty and increases its reference count by one.  When a client drops a reference, the DGC decreases its reference count by one,  and marks the object as clean. When the reference count reaches zero, the remote  object is free of any live client references. It is then placed on the weak  reference list and subject to periodic garbage collection.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is the priority of Garbage collection thread in java ?&lt;br /&gt;This is a  low-priority thread in java.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;How many applications can be run by one run-time instance of JVM ?&lt;br /&gt;One  run-time instance of java application can run only one instance.&lt;br /&gt;When the JVM  terminates ?&lt;br /&gt;The Java Virtual machine terminates when all the non-daemon  threads of java application terminates.&lt;br /&gt;If permitted by the security manager  it can also call System.runtime.ext () for terminating the JVM.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Is it possible to know from the content of a class file whether it is a java  class file or not?&lt;br /&gt;The first four bytes of every java class file is a magic  number “0xCAFEBABE”. So it is very easy to identify whether it is a java class  file or not.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Name the process thru which JVM makes the types available to the running  program?&lt;br /&gt;The Java Virtual Machine makes types available to the running  program through a process of loading, linking, and initialization.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Define loading, linking and initialization of java class ?&lt;br /&gt;&lt;br /&gt;Loading :  Loading is the process of bringing a binary form for a type into the Java  Virtual Machine.&lt;br /&gt;Linking : Linking is the process of incorporating the binary  type data into the runtime state of the virtual machine. Linking is divided into  three sub-steps: verification, preparation, and resolution.&lt;br /&gt;Initialization:  During initialization the class variables are their proper initial  values.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What do you mean by first active use of a class in JVM?&lt;br /&gt;· The invocation  of a constructor on a new instance of the class.&lt;br /&gt;· The creation of an array  that has the class as its an element type.&lt;br /&gt;· The invocation of a method  declared by the class (not inherited from a super class) .&lt;br /&gt;· The use or  assignment of a field declared by the class (not inherited from a superclass or  super interface), except for fields that are both static and final, and are  initialized by a compile-time constant expression.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What are steps involved in loading of a class file into JVM?&lt;br /&gt;· Produce a  stream of binary data that represents the type.&lt;br /&gt;· Parse the stream of binary  data into internal data structures in the method area.&lt;br /&gt;· Create an instance  of class java.lang.Class that represents the type.&lt;br /&gt;Is it possible to detect a  malformed class file during early loading by the class loader?&lt;br /&gt;No it is not  possible. If a class loader encounters a missing or malformed class file during  early loading, it must wait to report that error until the class is first active  use by the program.&lt;br /&gt;What are the different stages of linking after the class  is loaded?&lt;br /&gt;Verification, prepare and resolve are the three phases of  linking.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is verification stage and what are steps involved during  verification?&lt;br /&gt;It ensures that the types obey the semantics of java language  and doesn’t violate the integrity of JVM.&lt;br /&gt;The entire process of detecting any  kind of problem with loaded types is placed under the category of  verification.&lt;br /&gt;Verification of symbolic references and converting them to  direct references.&lt;br /&gt;· checking that final classes are not sub classed&lt;br /&gt;·  checking that final methods are not overridden&lt;br /&gt;· if the type being checked is  a non-abstract class, checking that all the methods declared in any interfaces  implemented by the class are indeed implemented by the class&lt;br /&gt;· Making sure no  incompatible method declarations (such as two methods that have the same name,  the same number, order, and types of parameters, but different return types)  appear between the type and its supertypes.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is done during Preparation Stage?&lt;br /&gt;&lt;br /&gt;The Java Virtual Machine  allocates memory for the class variables and sets them to default initial  values. The class variables are not initialized to their proper initial values  until the initialization phase.&lt;br /&gt;Java Virtual Machine implementations may also  allocate memory for data structures that are intended to improve the performance  of the running program.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What happens during Resolution Phase?&lt;br /&gt;Resolution is the process of  locating classes, interfaces, fields, and methods referenced symbolically from a  types constant pool, and replacing those symbolic references with direct  references.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;How the initialization of class is is different from initialization of  interface?&lt;br /&gt;Initialization of class requires initialization of its super  classes but initialization of interfaces doesn’t require initialization of it  super interfaces.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is a JIT compiler?&lt;br /&gt;JIT compilers are used to convert the java byte  codes to native types on the fly.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is the difference between instance method and class method ?&lt;br /&gt;·  Instance methods require an instance before they can be invoked; class methods  do not.&lt;br /&gt;· Instance methods use dynamic (late) binding; class(static methods)  methods use static (early) binding.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is the difference between a process and Thread?&lt;br /&gt;A process is a  self-contained running program within its own address space while a Thread is a  single sequential flow of control within a process.&lt;br /&gt;Each process has its own  set of variables where as Threads share the same data.&lt;br /&gt;Inter-process  communication is much slower and restrictive as compared to inter-thread  communication is faster.&lt;br /&gt;Creating and destroying Thread is much cheaper in  terms of performance overhead as compared to launching a new process.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is the difference between pre-emptive multi-tasking and co-operative  multi-tasking?&lt;br /&gt;In case of pre-emptive multitasking, the program is  interrupted without consulting first where as in case of co-operative  multitasking; programs are interrupted only when they are willing to yield  control.&lt;br /&gt;Windows 95,NT – pre-emptive multi-tasking where Windows 3.1 is  co-operative multitasking.&lt;br /&gt;Pre-emptive multi-tasking is more effective as  compared co-operative multitasking.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What is difference between creating a thread by extending Thread class and  implementing Runnable?&lt;br /&gt;&lt;br /&gt;Explain the four different states of a  thread&lt;br /&gt;The four different states of a thread are&lt;br /&gt;new: When a thread is  created with new operator .It is not yet running.&lt;br /&gt;Runnable: Once you invoke  the start method on the thread it becomes runnable. It is up to the OS to decide  when to give time to the thread to run. A runnable thread may or may not be  running.&lt;br /&gt;Blocked : Thread enters this state under the following  condition.&lt;br /&gt;Someone calls sleep () on the thread.&lt;br /&gt;Thread calls an operation  that blocks on input/output.&lt;br /&gt;Thread calls wait() method.&lt;br /&gt;Thread tries to  lock an object that is currently locked by another thread.&lt;br /&gt;Dead : The Thread  is dead for one of two reasons.&lt;br /&gt;It dies a natural death because the run  method exits normally.&lt;br /&gt;It dies abruptly because an uncaught exception  terminates the run method.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What happens when there are more than one highest priority threads having  same priority?&lt;br /&gt;In that case only one of the thread is picked up. It is up to  the thread Scheduler to arbitrate between threads of same priority.&lt;br /&gt;There is  no guarantee that all the same priority threads will be fairly treated.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Why do threads block on I/O ?&lt;br /&gt;Threads block on I/O so that other threads  may execute while the I/O operation is performed.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;What are the methods which can only be called from within a Synchronized  method or block ?&lt;br /&gt;Notify (): unblocks one randomly selected thread among the  threads that called wait() on this object.&lt;br /&gt;NoitifyAll() : unblocks the  threads that called wait() on this object.&lt;br /&gt;Wait (): causes the thread to wait  until it is notified.&lt;br /&gt;What is the difference between yield and sleep methods  of Thread?&lt;br /&gt;When a task invokes its yield () method, it returns to the ready  state. When a task invokes its sleep () method, it returns to the waiting  state.&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-8142423805844415469?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/8142423805844415469/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=8142423805844415469' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/8142423805844415469'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/8142423805844415469'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/11/core-java-faqs-what-is-difference.html' title=''/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-3400806830770338099</id><published>2007-11-06T02:49:00.000-08:00</published><updated>2007-11-06T02:52:00.486-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Core JAVA4'/><title type='text'></title><content type='html'>&lt;span style="font-style: italic; color: rgb(204, 0, 0);font-size:180%;" &gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;COLLECTIONS&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(204, 102, 0);"&gt;Q:What is the Collections API?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A:The Collections API is a set of  classes and interfaces that support operations on collections of  objects.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the List interface?&lt;br /&gt;A:&lt;br /&gt;The List  interface provides support for ordered collections of  objects.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the Vector class?&lt;br /&gt;A:&lt;br /&gt;The Vector  class provides the capability to implement a growable array of  objects.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is an Iterator interface?&lt;br /&gt;A:&lt;br /&gt;The  Iterator interface is used to step through the elements of a Collection  .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Which java.util classes and interfaces support event  handling?&lt;br /&gt;A:&lt;br /&gt;The EventObject class and the EventListener interface support  event processing.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the GregorianCalendar  class?&lt;br /&gt;A:&lt;br /&gt;The GregorianCalendar provides support for traditional Western  calendars&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the Locale class?&lt;br /&gt;A:&lt;br /&gt;The Locale  class is used to tailor program output to the conventions of a particular  geographic, political, or cultural region .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the  SimpleTimeZone class?&lt;br /&gt;A:&lt;br /&gt;The SimpleTimeZone class provides support for a  Gregorian calendar .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the Map  interface?&lt;br /&gt;A:&lt;br /&gt;The Map interface replaces the JDK 1.1 Dictionary class and  is used associate keys with values.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the  highest-level event class of the event-delegation model?&lt;br /&gt;A:&lt;br /&gt;The  java.util.EventObject class is the highest-level class in the event-delegation  class hierarchy.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the Collection  interface?&lt;br /&gt;A:&lt;br /&gt;The Collection interface provides support for the  implementation of a mathematical bag - an unordered collection of objects that  may contain duplicates.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the Set  interface?&lt;br /&gt;A:&lt;br /&gt;The Set interface provides methods for accessing the  elements of a finite mathematical set. Sets do not allow duplicate  elements.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the typical use of  Hashtable?&lt;br /&gt;A:&lt;br /&gt;Whenever a program wants to store a key value pair, one can  use Hashtable.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;I am trying to store an object using a  key in a Hashtable. And some other object already exists in that location, then  what will happen? The existing object will be overwritten? Or the new object  will be stored elsewhere?&lt;br /&gt;A:&lt;br /&gt;The existing object will be overwritten and  thus it will be lost.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the difference between  the size and capacity of a Vector?&lt;br /&gt;A:&lt;br /&gt;The size is the number of elements  actually stored in the vector, while capacity is the maximum number of elements  it can store at a given instance of time.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Can a vector  contain heterogenous objects?&lt;br /&gt;A:&lt;br /&gt;Yes a Vector can contain heterogenous  objects. Because a Vector stores everything in terms of  Object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Can a ArrayList contain heterogenous  objects?&lt;br /&gt;A:&lt;br /&gt;Yes a ArrayList can contain heterogenous objects. Because a  ArrayList stores everything in terms of Object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is  an enumeration?&lt;a name="q18"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;An enumeration is an interface  containing methods for accessing the underlying data structure from which the  enumeration is obtained. It is a construct which collection classes return when  you request a collection of all the objects stored in the collection. It allows  sequential access to all the elements stored in the  collection.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Considering the basic properties of Vector  and ArrayList, where will you use Vector and where will you use  ArrayList?&lt;br /&gt;A:&lt;br /&gt;The basic difference between a Vector and an ArrayList is  that, vector is synchronized while ArrayList is not. Thus whenever there is a  possibility of multiple threads accessing the same instance, one should use  Vector. While if not multiple threads are going to access the same instance then  use ArrayList. Non synchronized data structure will give better performance than  the synchronized one.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(204, 102, 0);"&gt;&lt;br /&gt;Q:Can a vector contain heterogenous  objects?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A:Yes a Vector can contain heterogenous objects. Because a  Vector stores everything in terms of Object.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-3400806830770338099?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/3400806830770338099/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=3400806830770338099' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3400806830770338099'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/3400806830770338099'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/11/collections-qwhat-is-collections-api.html' title=''/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-2019506986820496081</id><published>2007-11-06T02:43:00.000-08:00</published><updated>2007-11-06T02:48:59.643-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Core JAVA3'/><title type='text'></title><content type='html'>&lt;span style="font-size:180%;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0); font-style: italic;"&gt;&lt;br /&gt;&lt;br /&gt;Core JAVA&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(204, 0, 0);"&gt;&lt;br /&gt;&lt;br /&gt;Q:What method must be implemented by all threads?&lt;/span&gt;&lt;br /&gt;A:&lt;br /&gt;All tasks must  implement the run() method, whether they are a subclass of Thread or implement  the Runnable interface.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What are synchronized methods  and synchronized statements?&lt;br /&gt;A:&lt;br /&gt;Synchronized methods are methods that are  used to control access to an object. A thread only executes a synchronized  method after it has acquired the lock for the method's object or class.  Synchronized statements are similar to synchronized methods. A synchronized  statement can only be executed after a thread has acquired the lock for the  object or class referenced in the synchronized  statement.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is  Externalizable?&lt;br /&gt;A:&lt;br /&gt;Externalizable is an Interface that extends  Serializable Interface. And sends data into Streams in Compressed Format. It has  two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput  in)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What modifiers are allowed for methods in an  Interface?&lt;br /&gt;A:&lt;br /&gt;Only public and abstract modifiers are allowed for methods  in interfaces.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What are some alternatives to  inheritance?&lt;br /&gt;A:&lt;br /&gt;Delegation is an alternative to inheritance. Delegation  means that you include an instance of another class as an instance variable, and  forward messages to the instance. It is often safer than inheritance because it  forces you to think about each message you forward, because the instance is of a  known class, rather than a new class, and because it doesn't force you to accept  all the methods of the super class: you can provide only the methods that really  make sense. On the other hand, it makes you write more code, and it is harder to  re-use (because it is not a subclass).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What does it  mean that a method or field is "static"?&lt;br /&gt;A:&lt;br /&gt;Static variables and methods  are instantiated only once per class. In other words they are class variables,  not instance variables. If you change the value of a static variable in a  particular object, the value of that variable changes for all instances of that  class.&lt;br /&gt;Static methods can be referenced with the name of the class rather  than the name of a particular object of the class (though that works too).  That's how library methods like System.out.println() work out is a static field  in the java.lang.System class.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the difference  between preemptive scheduling and time slicing?&lt;br /&gt;A:&lt;br /&gt;Under preemptive  scheduling, the highest priority task executes until it enters the waiting or  dead states or a higher priority task comes into existence. Under time slicing,  a task executes for a predefined slice of time and then reenters the pool of  ready tasks. The scheduler then determines which task should execute next, based  on priority and other factors.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the catch or  declare rule for method declarations?&lt;br /&gt;A:&lt;br /&gt;If a checked exception may be  thrown within the body of a method, the method must either catch the exception  or declare it in its throws clause.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Is Empty .java file a  valid source file?&lt;br /&gt;A:&lt;br /&gt;Yes, an empty .java file is a perfectly valid source  file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Can a .java file contain more than one java  classes?&lt;br /&gt;A:&lt;br /&gt;Yes, a .java file contain more than one java classes, provided  at the most one of them is a public class.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Is String a  primitive data type in Java?&lt;br /&gt;A:&lt;br /&gt;No String is not a primitive data type in  Java, even though it is one of the most extensively used object. Strings in Java  are instances of String class defined in java.lang  package.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Is main a keyword in Java?&lt;br /&gt;A:&lt;br /&gt;No, main  is not a keyword in Java.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Is next a keyword in  Java?&lt;br /&gt;A:&lt;br /&gt;No, next is not a keyword.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Is delete a  keyword in Java?&lt;br /&gt;A:&lt;br /&gt;No, delete is not a keyword in Java. Java does not  make use of explicit destructors the way C++ does.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Is  exit a keyword in Java?&lt;br /&gt;A:&lt;br /&gt;No. To exit a program explicitly you use exit  method in System object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What happens if you dont  initialize an instance variable of any of the primitive types in  Java?&lt;br /&gt;A:&lt;br /&gt;Java by default initializes it to the default value for that  primitive type. Thus an int will be initialized to 0, a boolean will be  initialized to false.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What will be the initial value of  an object reference which is defined as an instance variable?&lt;br /&gt;A:&lt;br /&gt;The  object references are all initialized to null in Java. However in order to do  anything useful with these references, you must set them to a valid object, else  you will get NullPointerExceptions everywhere you try to use such default  initialized references.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What are the different scopes  for Java variables?&lt;br /&gt;A:&lt;br /&gt;The scope of a Java variable is determined by the  context in which the variable is declared. Thus a java variable can have one of  the three scopes at any given point in time.1. Instance : - These are typical  object level variables, they are initialized to default values at the time of  creation of object, and remain accessible as long as the object accessible.2.  Local : - These are the variables that are defined within a method. They remain  accessbile only during the course of method excecution. When the method finishes  execution, these variables fall out of scope.3. Static: - These are the class  level variables. They are initialized when the class is loaded in JVM for the  first time and remain there as long as the class remains loaded. They are not  tied to any particular object instance.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the  default value of the local variables?&lt;br /&gt;A:&lt;br /&gt;The local variables are not  initialized to any default value, neither primitives nor object references. If  you try to use these variables without initializing them explicitly, the java  compiler will not compile the code. It will complain abt the local varaible not  being initilized..&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;How many objects are created in the  following piece of code?MyClass c1, c2, c3;c1 = new MyClass ();c3 = new MyClass  ();&lt;br /&gt;A:&lt;br /&gt;Only 2 objects are created, c1 and c3. The reference c2 is only  declared and not initialized.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Can a public class  MyClass be defined in a source file named YourClass.java?&lt;br /&gt;A:&lt;br /&gt;No the source  file name, if it contains a public class, must be the same as the public class  name itself with a .java extension.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Can main method be  declared final?&lt;br /&gt;A:&lt;br /&gt;Yes, the main method can be declared final, in addition  to being public static.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;Q:What will be the output of the  following statement?System.out.println ("1" + 3);&lt;/span&gt;&lt;br /&gt;A:It will print 13.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;Q:What will be the default values of all the elements of an array defined as  an instance variable?&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A:If the array is an array of primitive types, then  all the elements of the array will be initialized&lt;br /&gt;to the default value  corresponding to that primitive type. e.g. All the elements of an array of int  will be initialized to 0, while that of boolean type will be initialized to  false. Whereas if the array is an array of references (of any type), all the  elements will be initialized to null.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-2019506986820496081?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/2019506986820496081/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=2019506986820496081' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/2019506986820496081'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/2019506986820496081'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/11/core-java-qwhat-method-must-be.html' title=''/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-527045470947022400</id><published>2007-11-06T02:40:00.000-08:00</published><updated>2007-11-06T02:43:11.070-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Core JAVA2'/><title type='text'></title><content type='html'>&lt;span style="font-size:180%;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0); font-style: italic;"&gt;&lt;br /&gt;&lt;br /&gt;Core JAVA&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 0, 0); font-weight: bold;"&gt;Q:Why do we need wrapper classes?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A:&lt;br /&gt;It is sometimes easier to deal  with primitives as objects. Moreover most of the collection classes store  objects and not primitive data types. And also the wrapper classes provide many  utility methods also. Because of these resons we need wrapper classes. And since  we create instances of these classes we can store them in any of the collection  classes and pass them around as a collection. Also we can pass them around as  method parameters where a method expects an  object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What are checked exceptions?&lt;br /&gt;A:&lt;br /&gt;Checked  exception are those which the Java compiler forces you to catch. e.g.  IOException are checked Exceptions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What are runtime  exceptions?&lt;br /&gt;A:&lt;br /&gt;Runtime exceptions are those exceptions that are thrown at  runtime because of either wrong input data or because of wrong business logic  etc. These are not checked by the compiler at compile  time.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the difference between error and an  exception?&lt;br /&gt;A:&lt;br /&gt;An error is an irrecoverable condition occurring at runtime.  Such as OutOfMemory error. These JVM errors and you can not repair them at  runtime. While exceptions are conditions that occur because of bad input etc.  e.g. FileNotFoundException will be thrown if the specified file does not exist.  Or a NullPointerException will take place if you try using a null reference. In  most of the cases it is possible to recover from an exception (probably by  giving user a feedback for entering proper values  etc.).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;How to create custom exceptions?&lt;br /&gt;A:&lt;br /&gt;Your  class should extend class Exception, or some more specific type  thereof.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;If I want an object of my class to be thrown  as an exception object, what should I do?&lt;br /&gt;A:&lt;br /&gt;The class should extend from  Exception class. Or you can extend your class from some more precise exception  type also.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;If my class already extends from some other  class what should I do if I want an instance of my class to be thrown as an  exception object?&lt;br /&gt;A:&lt;br /&gt;One can not do anytihng in this scenarion. Because  Java does not allow multiple inheritance and does not provide any exception  interface as well.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;How does an exception permeate  through the code?&lt;br /&gt;A:&lt;br /&gt;An unhandled exception moves up the method stack in  search of a matching When an exception is thrown from a code which is wrapped in  a try block followed by one or more catch blocks, a search is made for matching  catch block. If a matching type is found then that block will be invoked. If a  matching type is not found then the exception moves up the method stack and  reaches the caller method. Same procedure is repeated if the caller method is  included in a try catch block. This process continues until a catch block  handling the appropriate type of exception is found. If it does not find such a  block then finally the program terminates.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What are the  different ways to handle exceptions?&lt;br /&gt;A:&lt;br /&gt;There are two ways to handle  exceptions, 1. By wrapping the desired code in a try block followed by a catch  block to catch the exceptions. and 2. List the desired exceptions in the throws  clause of the method and let the caller of the method hadle those  exceptions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the basic difference between the 2  approaches to exception handling.1&gt; try catch block and 2&gt; specifying the  candidate exceptions in the throws clause?When should you use which  approach?&lt;br /&gt;A:&lt;br /&gt;In the first approach as a programmer of the method, you  urself are dealing with the exception. This is fine if you are in a best  position to decide should be done in case of an exception. Whereas if it is not  the responsibility of the method to deal with it's own exceptions, then do not  use this approach. In this case use the second approach. In the second approach  we are forcing the caller of the method to catch the exceptions, that the method  is likely to throw. This is often the approach library creators use. They list  the exception in the throws clause and we must catch them. You will find the  same approach throughout the java libraries we use.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Is  it necessary that each try block must be followed by a catch block?&lt;br /&gt;A:&lt;br /&gt;It  is not necessary that each try block must be followed by a catch block. It  should be followed by either a catch block OR a finally block. And whatever  exceptions are likely to be thrown should be declared in the throws clause of  the method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;If I write return at the end of the try  block, will the finally block still execute?&lt;br /&gt;A:&lt;br /&gt;Yes even if you write  return as the last statement in the try block and no exception occurs, the  finally block will execute. The finally block will execute and then the control  return.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;If I write System.exit (0); at the end of the  try block, will the finally block still execute?&lt;br /&gt;A:&lt;br /&gt;No in this case the  finally block will not execute because when you say System.exit (0); the control  immediately goes out of the program, and thus finally never  executes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;How are Observer and Observable  used?&lt;br /&gt;A:&lt;br /&gt;Objects that subclass the Observable class maintain a list of  observers. When an Observable object is updated it invokes the update() method  of each of its observers to notify the observers that it has changed state. The  Observer interface is implemented by objects that observe Observable  objects.&lt;br /&gt;Q:&lt;br /&gt;What is synchronization and why is it important?&lt;br /&gt;A:&lt;br /&gt;With  respect to multithreading, synchronization is the capability to controlthe  access of multiple threads to shared resources. Without synchronization, it is  possible for one thread to modify a shared object while another thread is in the  process of using or updating that object's value. This often leads to  significant errors.&lt;br /&gt;Q:&lt;br /&gt;How does Java handle integer overflows and  underflows?&lt;br /&gt;A:&lt;br /&gt;It uses those low order bytes of the result that can fit  into the size of the type allowed by the operation.&lt;br /&gt;Q:&lt;br /&gt;Does garbage  collection guarantee that a program will not run out of memory?&lt;br /&gt;A:&lt;br /&gt;Garbage  collection does not guarantee that a program will not run out of memory. It is  possible for programs to use up memory resources faster than they are garbage  collected. It is also possible for programs to create objects that are not  subject to garbage collection.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the difference  between preemptive scheduling and time slicing?&lt;br /&gt;A:&lt;br /&gt;Under preemptive  scheduling, the highest priority task executes until it enters the waiting or  dead states or a higher priority task comes into existence. Under time slicing,  a task executes for a predefined slice of time and then reenters the pool of  ready tasks. The scheduler then determines which task should execute next, based  on priority and other factors.&lt;br /&gt;Q:&lt;br /&gt;When a thread is created and started,  what is its initial state?&lt;br /&gt;A:&lt;br /&gt;A thread is in the ready state after it has  been created and started.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the purpose of  finalization?&lt;br /&gt;A:&lt;br /&gt;The purpose of finalization is to give an unreachable  object the opportunity to perform any cleanup processing before the object is  garbage collected.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the Locale  class?&lt;br /&gt;A:&lt;br /&gt;The Locale class is used to tailor program output to the  conventions of a particular geographic, political, or cultural  region.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the difference between a while  statement and a do statement?&lt;br /&gt;A:&lt;br /&gt;A while statement checks at the beginning  of a loop to see whether the next loop iteration should occur. A do statement  checks at the end of a loop to see whether the next iteration of a loop should  occur. The do statement will always execute the body of a loop at least  once.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the difference between static and  non-static variables?&lt;br /&gt;A:&lt;br /&gt;A static variable is associated with the class as  a whole rather than with specific instances of a class. Non-static variables  take on unique values with each object instance.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;How  are this() and super() used with constructors?&lt;br /&gt;A:&lt;br /&gt;This() is used to invoke  a constructor of the same class. super() is used to invoke a superclass  constructor.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What are synchronized methods and  synchronized statements?&lt;br /&gt;A:&lt;br /&gt;Synchronized methods are methods that are used  to control access to an object. A thread only executes a synchronized method  after it has acquired the lock for the method's object or class. Synchronized  statements are similar to synchronized methods. A synchronized statement can  only be executed after a thread has acquired the lock for the object or class  referenced in the synchronized statement.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is  daemon thread and which method is used to create the daemon  thread?&lt;br /&gt;A:&lt;br /&gt;Daemon thread is a low priority thread which runs  intermittently in the back ground doing the garbage collection operation for the  java runtime system. setDaemon method is used to create a daemon  thread.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Can applets communicate with each  other?&lt;br /&gt;A:&lt;br /&gt;At this point in time applets may communicate with other applets  running in the same virtual machine. If the applets are of the same class, they  can communicate via shared static variables. If the applets are of different  classes, then each will need a reference to the same class with static  variables. In any case the basic idea is to pass the information back and forth  through a static variable. An applet can also get references to all other  applets on the same page using the getApplets() method of  java.applet.AppletContext. Once you get the reference to an applet, you can  communicate with it by using its public members. It is conceivable to have  applets in different virtual machines that talk to a server somewhere on the  Internet and store any data that needs to be serialized there. Then, when  another applet needs this data, it could connect to this same server.  Implementing this is non-trivial.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What are the steps in  the JDBC connection?&lt;br /&gt;A:&lt;br /&gt;While making a JDBC connection we go through the  following steps : Step 1 : Register the database driver by using  :&lt;br /&gt;Class.forName(\" driver classs for that specific database\" );&lt;br /&gt;Step 2 :  Now create a database connection using :&lt;br /&gt;Connection con =  DriverManager.getConnection(url,username,password);&lt;br /&gt;Step 3: Now Create a  query using :&lt;br /&gt;Statement stmt = Connection.Statement(\"select * from TABLE  NAME\");&lt;br /&gt;Step 4 : Exceute the query  :&lt;br /&gt;stmt.exceuteUpdate();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;How does a try statement  determine which catch clause should be used to handle an  exception?&lt;br /&gt;A:&lt;br /&gt;When an exception is thrown within the body of a try  statement, the catch clauses of the try statement are examined in the order in  which they appear. The first catch clause that is capable of handling the  exceptionis executed. The remaining catch clauses are ignored.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(204, 0, 0);"&gt;Q:Can an  unreachable object become reachable again?&lt;/span&gt;&lt;br /&gt;A:&lt;br /&gt;An unreachable object may  become reachable again. This can happen when the object's finalize() method is  invoked and the object performs an operation which causes it to become  accessible to reachable objects.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6627970515100200907-527045470947022400?l=java4interview.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java4interview.blogspot.com/feeds/527045470947022400/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6627970515100200907&amp;postID=527045470947022400' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/527045470947022400'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6627970515100200907/posts/default/527045470947022400'/><link rel='alternate' type='text/html' href='http://java4interview.blogspot.com/2007/11/core-java-qwhy-do-we-need-wrapper.html' title=''/><author><name>Real Time Questions</name><uri>http://www.blogger.com/profile/16931659279594942459</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6627970515100200907.post-4606916105760659522</id><published>2007-11-06T02:37:00.000-08:00</published><updated>2007-11-06T02:40:50.650-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Core JAVA1'/><title type='text'></title><content type='html'>&lt;span style="font-size:180%;"&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0); font-style: italic;"&gt;Core JAVA&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0); font-weight: bold;"&gt;Q:What is the difference between an Interface and an Abstract class? &lt;/span&gt;&lt;a name="q1"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;A:&lt;br /&gt;An abstract class can have instance methods that implement  a default behavior. An Interface can only declare constants and instance  methods, but cannot implement default behavior and all methods are implicitly  abstract. An interface has all public members and no implementation. An abstract  class is a class which may have the usual flavors of class members (private,  protected, etc.), but has some abstract methods..&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is  the purpose of garbage collection in Java, and when is it used?&lt;a name="q2"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;The purpose of garbage collection is to identify and  discard objects that are no longer needed by a program so that their resources  can be reclaimed and reused. A Java object is subject to garbage collection when  it becomes unreachable to the program in which it is used.&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Describe  synchronization in respect to multithreading.&lt;a name="q3"&gt;&lt;/a&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;A:&lt;br /&gt;With respect to multithreading,  synchronization is the capability to control the access of multiple threads to  shared resources. Without synchonization, it is possible for one thread to  modify a shared variable while another thread is in the process of using or  updating same shared variable. This usually leads to significant  errors.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Explain different way of using thread? &lt;a name="q4"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;The thread could be implemented by using runnable  interface or by inheriting from the Thread class. The former is more  advantageous, 'cause when you are going for multiple inheritance..the only  interface can help.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What are pass by reference and passby  value? &lt;a name="q5"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;Pass By Reference means the passing the address  itself rather than passing the value. Passby Value means passing a copy of the  value to be passed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is HashMap and Map?&lt;a name="q6"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;Map is Interface and Hashmap is class that implements  that.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Difference between HashMap and HashTable?&lt;a name="q7"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;The HashMap class is roughly equivalent to Hashtable,  except that it is unsynchronized and permits nulls. (HashMap allows null values  as key and value whereas Hashtable doesnt allow). HashMap does not guarantee  that the order of the map will remain constant over time. HashMap is  unsynchronized and Hashtable is synchronized.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Difference  between Vector and ArrayList?&lt;a name="q8"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;Vector is synchronized  whereas arraylist is not.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Difference between Swing and  Awt?&lt;a name="q9"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;AWT are heavy-weight componenets. Swings are  light-weight components. Hence swing works faster than  AWT.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the difference between a constructor and a  method? &lt;a name="q10"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;A constructor is a member function of a class  that is used to create objects of that class. It has the same name as the class  itself, has no return type, and is invoked using the new operator.A method is an  ordinary member function of a class. It has its own name, a return type (which  may be void), and is invoked using the dot operator.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What  is an Iterator?&lt;a name="q11"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;Some of the collection classes provide  traversal of their contents via a java.util.Iterator interface. This interface  allows you to walk through a collection of objects, operating on each object in  turn. Remember when using Iterators that they contain a snapshot of the  collection at the time the Iterator was obtained; generally it is not advisable  to modify the collection itself while traversing an  Iterator.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;State t&lt;a name="q12"&gt;&lt;/a&gt;he significance of public,  private, protected, default modifiers both singly and in combination and state  the effect of package relationships on declared items qualified by these  modifiers.&lt;br /&gt;A:&lt;br /&gt;public : Public class is visible in other packages, field is  visible everywhere (class must be public too)private : Private variables or  methods may be used only by an instance of the same class that declares the  variable or method, A private feature may only be accessed by the class that  owns the feature.protected : Is available to all classes in the same package and  also available to all subclasses of the class that owns the protected  feature.This access is provided even to subclasses that reside in a different  package from the class that owns the protected feature.default :What you get by  default ie, without any access modifier (ie, public private or protected).It  means that it is visible to all within a particular  package.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is an abstract class?&lt;a name="q13"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;Abstract class must be extended/subclassed (to be  useful). It serves as a template. A class that is abstract may not be  instantiated (ie, you may not call its constructor), abstract class may contain  static data. Any class with an abstract method is automatically abstract itself,  and must be declared as such.A class may be declared abstract even if it has no  abstract methods. This prevents it from being  instantiated.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is static in java?&lt;a name="q14"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;Static means one per class, not one for each object no  matter how many instance of a class might exist. This means that you can use  them without creating an instance of a class.Static methods are implicitly  final, because overriding is done based on the type of the object, and static  methods are attached to a class, not an object. A static method in a superclass  can be shadowed by another static method in a subclass, as long as the original  method was not declared final. However, you can't override a static method with  a nonstatic method. In other words, you can't change a static method into an  instance method in a subclass.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is final?&lt;a name="q15"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;A final class can't be extended ie., final class may not  be subclassed. A final method can't be overridden when its class is inherited.  You can't change value of a final variable (is a constant).&lt;br /&gt;Q:&lt;br /&gt;What if the  main method is declared as private?&lt;br /&gt;A:&lt;br /&gt;The program compiles properly but  at runtime it will give "Main method not public."  message.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What if the static modifier is removed from  the signature of the main method?&lt;br /&gt;A:&lt;br /&gt;Program compiles. But at runtime  throws an error "NoSuchMethodError".&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What if I write  static public void instead of public static void?&lt;br /&gt;A:&lt;br /&gt;Program compiles and  runs properly.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What if I do not provide the String  array as the argument to the method?&lt;br /&gt;A:&lt;br /&gt;Program compiles but throws a  runtime error "NoSuchMethodError".&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the first  argument of the String array in main method?&lt;br /&gt;A:&lt;br /&gt;The String array is empty.  It does not have any element. This is unlike C/C++ where the first element by  default is the program name.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;If I do not provide any  arguments on the command line, then the String array of Main method will be  empty or null?&lt;br /&gt;A:&lt;br /&gt;It is empty. But not null.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;How  can one prove that the array is not null but empty using one line of  code?&lt;br /&gt;A:&lt;br /&gt;Print args.length. It will print 0. That means it is empty. But  if it would have been null then it would have thrown a NullPointerException on  attempting to print args.length.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What environment  variables do I need to set on my machine in order to be able to run Java  programs?&lt;br /&gt;A:&lt;br /&gt;CLASSPATH and PATH are the two  variables.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Can an application have multiple classes  having main method?&lt;br /&gt;A:&lt;br /&gt;Yes it is possible. While starting the application  we mention the class name to be run. The JVM will look for the Main method only  in the class whose name you have mentioned. Hence there is not conflict amongst  the multiple classes having main method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Can I have  multiple main methods in the same class?&lt;br /&gt;A:&lt;br /&gt;No the program fails to  compile. The compiler says that the main method is already defined in the  class.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Do I need to import java.lang package any time?  Why ?&lt;br /&gt;A:&lt;br /&gt;No. It is by default loaded internally by the  JVM.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Can I import same package/class twice? Will the  JVM load the package twice at runtime?&lt;br /&gt;A:&lt;br /&gt;One can import the same package  or same class multiple times. Neither compiler nor JVM complains abt it. And the  JVM will internally load the class only once no matter how many times you import  the same class.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What are Checked and UnChecked  Exception?&lt;br /&gt;A:&lt;br /&gt;A checked exception is some subclass of Exception (or  Exception itself), excluding class RuntimeException and its subclasses.Making an  exception checked forces client programmers to deal with the possibility that  the exception will be thrown. eg, IOException thrown by  java.io.FileInputStream's read() method·Unchecked exceptions are  RuntimeException and any of its subclasses. Class Error and its subclasses also  are unchecked. With an unchecked exception, however, the compiler doesn't force  client programmers either to catch theexception or declare it in a throws  clause. In fact, client programmers may not even know that the exception could  be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt()  method· Checked exceptions must be caught at compile time. Runtime exceptions do  not need to be. Errors often cannot be.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is  Overriding?&lt;br /&gt;A:&lt;br /&gt;When a class defines a method using the same name, return  type, and arguments as a method in its superclass, the method in the class  overrides the method in the superclass.When the method is invoked for an object  of the class, it is the new definition of the method that is called, and not the  method definition from superclass. Methods may be overridden to be more public,  not more private.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What are different types of inner  classes?&lt;br /&gt;A:&lt;br /&gt;Nested top-level classes, Member classes, Local classes,  Anonymous classes&lt;br /&gt;Nested top-level classes- If you declare a class within a  class and specify the static modifier, the compiler treats the class just like  any other top-level class.Any class outside the declaring class accesses the  nested class with the declaring class name acting similarly to a package. eg,  outer.inner. Top-level inner classes implicitly have access only to static  variables.There can also be inner interfaces. All of these are of the nested  top-level variety.Member classes - Member inner classes are just like other  member methods and member variables and access to the member class is  restricted, just like methods and variables. This means a public member class  acts similarly to a nested top-level class. The primary difference between  member classes and nested top-level classes is that member classes have access  to the specific instance of the enclosing class.Local classes - Local classes  are like local variables, specific to a block of code. Their visibility is only  within the block of their declaration. In order for the class to be useful  beyond the declaration block, it would need to implement amore publicly  available interface.Because local classes are not members, the modifiers public,  protected, private, and static are not usable.Anonymous classes - Anonymous  inner classes extend local inner classes one level further. As anonymous classes  have no name, you cannot provide a constructor.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Are the  imports checked for validity at compile time? e.g. will the code containing an  import such as java.lang.ABCD compile?&lt;br /&gt;A:&lt;br /&gt;Yes the imports are checked for  the semantic validity at compile time. The code containing above line of import  will not compile. It will throw an error saying,can not resolve symbolsymbol :  class ABCDlocation: package ioimport java.io.ABCD;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Does  importing a package imports the subpackages as well? e.g. Does importing  com.MyTest.* also import com.MyTest.UnitTests.*?&lt;br /&gt;A:&lt;br /&gt;No you will have to  import the subpackages explicitly. Importing com.MyTest.* will import classes in  the package MyTest only. It will not import any class in any of it's  subpackage.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the difference between declaring a  variable and defining a variable?&lt;br /&gt;A:&lt;br /&gt;In declaration we just mention the  type of the variable and it's name. We do not initialize it. But defining means  declaration + initialization.e.g String s; is just a declaration while String s  = new String ("abcd"); Or String s = "abcd"; are both  definitions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is the default value of an object  reference declared as an instance variable?&lt;br /&gt;A:&lt;br /&gt;null unless we define it  explicitly.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Can a top level class be private or  protected?&lt;br /&gt;A:&lt;br /&gt;No. A top level class can not be private or protected. It  can have either "public" or no modifier. If it does not have a modifier it is  supposed to have a default access.If a top level class is declared as private  the compiler will complain that the "modifier private is not allowed here". This  means that a top level class can not be private. Same is the case with  protected.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What type of parameter passing does Java  support?&lt;br /&gt;A:&lt;br /&gt;In Java the arguments are always passed by value  .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Primitive data types are passed by reference or pass  by value?&lt;br /&gt;A:&lt;br /&gt;Primitive data types are passed by  value.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Objects are passed by value or by  reference?&lt;br /&gt;A:&lt;br /&gt;Java only supports pass by value. With objects, the object  reference itself is passed by value and so both the original reference and  parameter copy both refer to the same object .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is  serialization?&lt;br /&gt;A:&lt;br /&gt;Serialization is a mechanism by which you can save the  state of an object by converting it to a byte  stream.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;How do I serialize an object to a  file?&lt;br /&gt;A:&lt;br /&gt;The class whose instances are to be serialized should implement  an interface Serializable. Then you pass the instance to the ObjectOutputStream  which is connected to a fileoutputstream. This will save the object to a  file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;Which methods of Serializable interface should I  implement?&lt;br /&gt;A:&lt;br /&gt;The serializable interface is an empty interface, it does  not contain any methods. So we do not implement any  methods.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;How can I customize the seralization process?  i.e. how can one have a control over the serialization process?&lt;br /&gt;A:&lt;br /&gt;Yes it  is possible to have control over serialization process. The class should  implement Externalizable interface. This interface contains two methods namely  readExternal and writeExternal. You should implement these methods and write the  logic for customizing the serialization process.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What  is the common usage of serialization?&lt;br /&gt;A:&lt;br /&gt;Whenever an object is to be sent  over the network, objects need to be serialized. Moreover if the state of an  object is to be saved, objects need to be  serilazed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What is Externalizable  interface?&lt;br /&gt;A:&lt;br /&gt;Externalizable is an interface which contains two methods  readExternal and writeExternal. These methods give you a control over the  serialization mechanism. Thus if your class implements this interface, you can  customize the serialization process by implementing these  methods.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;When you serialize an object, what happens to  the object references included in the object?&lt;br /&gt;A:&lt;br /&gt;The serialization  mechanism generates an object graph for serialization. Thus it determines  whether the included object references are serializable or not. This is a  recursive process. Thus when an object is serialized, all the included objects  are also serialized alongwith the original obect.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What  one should take care of while serializing the object?&lt;a name="q16"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;One should make sure that all the included objects are  also serializable. If any of the objects is not serializable then it throws a  NotSerializableException.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q:&lt;br /&gt;What happens to the static  fields of a class during serialization? &lt;a name="q17"&gt;&lt;/a&gt;&lt;br /&gt;A:&lt;br /&gt;There are  three exceptions in which seri
