Friday, February 26, 2010

What is the difference between JDK and JRE?

A lot of times, we have seen that people ( obviously novices in the field of java) dont know the exact difference between JDK and JRE. Just to make Java get a lil more closer to our readers, we thought of putting up the difference between the two in this writeup.
“JDK” is the Java Development Kit. I.e., JDK is a bundle of software that you can use to develop Java based software. The “JRE” is the Java Runtime Environment. I.e., the JRE is an implementation of the Java Virtual Machine which actually executes the Java Programs.Typically, each JDK contains one (or more) JRE’s along with the various development tools like the Java source compilers, bundling and deployment tools, debuggers, development libraries, etc.

What are JDBC Drivers?

JDBC Drivers are set of classes that enables the Java application to communicate with databases. Java.sql that ships with JDK contains various classes for using relational databases. But these classes do not provide any implementation, only the behaviours are defined. The actual implementaions are done in third-party drivers. Third party vendors implements the java.sql.Driver interface in their database driver.

An Overview of Java Database Connectivity

Suppose you have a set of records in an Access database that you have to view through a front-end tool. You can design a user interface by using various programming languages such as Visual Basic, Visual C++, etc. Java, however, provides a more consistent approach in developing these interfaces through the javax.swing package. Moreover, Java provides the Java Database Connectivity (JDBC) API, with which you can connect your app to any database designed either using Microsoft Access or SQL Server. In this article, we will examine the basic steps required to handle JDBC using javax.swing for creating user interfaces.

Before proceeding further, let us take a quick look at Microsoft's Object Database Connectivity (ODBC) and the preference of JDBC over ODBC. The ODBC API offers connectivity to almost all databases on almost all platforms and is the most widely used programming interface for accessing relational databases. But ODBC cannot be used directly with Java programs due to various reasons.

1. ODBC uses a C interface. This has drawbacks in security, implementation, robustness, etc.
2. ODBC makes use of pointers (which have been removed from Java).

Hence JDBC came into existence. If you've done database programming using Visual Basic, then you will be familiar with ODBC. You can connect a VB application to an Access database or an Oracle table directly via ODBC. Since Java is a product of Sun Microsystems, you have to make use of JDBC along with ODBC in order to develop Java database applications. JDBC is a set of Java APIs for executing SQL statements. This API consists of a set of classes and interfaces to enable programmers to write pure database applications.

Let us now examine the basic steps required in all Java programs to handle JDBC.
Step 1: Loading Drivers

First, you have to load the appropriate driver. You can use one driver from the available four. However, the JDBC-ODBC driver is the most preferred among developers. In order to load the driver, you have to give the following syntax:

Class.ForName("sun.jdbc.odbc.JdbcOdbcDriver");

Step 2: Making a Connection

The getConnection() method of the Driver Manager class is called to obtain the Connection object. The syntax looks like this:

Connection conn = DriverManager.getConnection("jdbc:odbc:");

Here, note that getConnection() is a static method, meaning it should be accessed along with the class associated with the method. You have to give the Data Source Name as a parameter to this method. (See section below for setting up the Data Source Name in your computer.)
Step 3: Creating JDBC Statements

A Statement object is what sends your SQL Query to the Database Management System. You simply create a statement object and then execute it. It takes an instance of active connection to create a statement object. We have to use our Connection object "conn" here to create the Statement object "stmt". The code looks like this:

Statement stmt = conn.createStatement();

Step 4: Executing the Statement

In order to execute the query, you have to obtain the Result Set object (similar to Record Set in Visual Basic) and a call to the executeQuery() method of the Statement interface. You have to pass a SQL query like select * from students as a parameter to the executeQuery() method. If your table name is different, you have to substitute that name in place of students. Actually, the RecordSet object contains both the data returned by the query and the methods for data retrieval.

The code for the above step looks like this:

ResultSet rs = stmt.executeQuery("select * from students");

If you want to select only the name field, you have to issue a SQL command like Select Name from Student. The executeUpdate() method is called whenever there is a delete or an update operation.
Step 5: Looping Through the ResultSet

The ResultSet object contains rows of data that is parsed using the next() method, such as rs.next(). We use the getXXX() method of the appropriate type to retrieve the value in each field. For example, if your first field name is ID, which accepts Number values, then the getInt() method should be used. In the same way, if the second field Name accepts integer String values, then the getString() method should be used, like the code given below:


System.out.println(rs.getInt("ID"));

Step 6: Closing the Connection and Statement Objects

After performing all the above steps, you have to close the Connection and RecordSet objects appropriately by calling the close() method. For example, in our code above, we will close the object as conn.close() and statement object as stmt.close().

The code for the sample program is shown below for your reference:

import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Datas extends JFrame implements ActionListener {

JTextField id;
JTextField name;
JButton next;
JButton addnew;
JPanel p;
static ResultSet res;
static Connection conn;
static Statement stat;

public Datas() {
super("Our Application");
Container c = getContentPane();
c.setLayout(new GridLayout(5,1));
id = new JTextField(20);
name = new JTextField(20);
next = new JButton("Next");
p = new JPanel();
c.add(new JLabel("Customer ID",JLabel.CENTER));
c.add(id);
c.add(new JLabel("Customer Name",JLabel.CENTER));
c.add(name);
c.add(p);
p.add(next);
next.addActionListener(this);
pack();
setVisible(true);
addWindowListener(new WIN());

}

public static void main(String args[]) {
Datas d = new Datas();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:cust"); // cust is the DSN
Name
stat = conn.createStatement();
res = stat.executeQuery("Select * from Cutomers"); // Customers is
the table name
res.next();

}
catch(Exception e) {
System.out.println("Error" +e);
}
d.showRecord(res);
}

public void actionPerformed(ActionEvent e) {
if(e.getSource() == next) {
try {
res.next();
}
catch(Exception ee) {}
showRecord(res);
}
}

public void showRecord(ResultSet res) {
try {
id.setText(res.getString(1));
name.setText(res.getString(2));
}
catch(Exception e) {}

}//end of the main

//Inner class WIN implemented
class WIN extends WindowAdapter {
public void windowClosing(WindowEvent w) {
JOptionPane jop = new JOptionPane();
jop.showMessageDialog(
null,"Database","Thanks",JOptionPane.QUESTION_MESSAGE);

}

}

//end of the class

Wednesday, February 24, 2010

स्वभाव की झलक

एक बार गुरु नानक देव किसी शहर में पहुंचे। वहां उनका प्रवचन सुनने के लिए भीड़ उमड़ पड़ी। हर वर्ग, जाति और धर्म के लोगों ने उनके उपदेश का
लाभ उठाया।

एक स्त्री ने गुरु नानक से प्रार्थना की, 'महाराज, आप हमारे घर पधारकर हमें सेवा का अवसर दें।' उसके बार-बार प्रार्थना करने पर नानक देव उसके घर गए। उस स्त्री ने उनका स्नेहपूर्वक स्वागत किया। उनके पास बैठकर उनके लिए एक कटोरे में हंडिया से दूध डालने लगी। दूध की सारी मलाई कटोरे में गिर गई। यह देख उसके मुंह से निकला, 'अरे-अरे।' फिर दूध में चीनी डालकर उसने कटोरा नानक देव के सामने रख दिया। गुरु नानक यह सब बडे़ ध्यान से देख रहे थे। लेकिन उन्होंने यह जताया कि उन्हें कुछ भी पता नहीं है। वह पास में रखे दूध से अनजान होकर उस स्त्री को उपदेश देने लगे। उन्होंने उसकी जिज्ञासाओं का समाधान किया। उन्हें सुनते हुए भी वह स्त्री देख रही थी कि गुरु नानक दूध पीते हैं या नहीं।

उसने सोचा कि शायद दूध गरम होगा, इसलिए वह पी नहीं रहे हैं, किंतु उपदेश समाप्त होने पर भी जब उन्होंने दूध की ओर ध्यान नहीं दिया, तो वह बोली, 'महाराज दूध पी लीजिए।' तब नानक देव बोले, 'इसमें क्या-क्या मिलाया है?' स्त्री ने सहजता से उत्तर दिया, 'केवल चीनी।' गुरु नानक बोले, 'नहीं इसमें एक चीज और है, इसलिए इसे मैं नहीं पी सकता।' स्त्री ने कहा, 'मैंने तो इसमें और कोई चीज नहीं मिलाई है।' गुरु नानक बोले, 'नहीं, इसमें एक चीज और मिलाई है और वह है अरे-अरे! इसी कारण मैं इसे नहीं पी सकता।' यह सुन स्त्री को बहुत पश्चाताप हुआ। उसने अपने मन में उठे क्षणिक लोभ के लिए उनसे क्षमा मांगी। नानक देव ने स्त्री को क्षमा करते हुए समझाया, 'हमारा हर छोटा-बड़ा आचरण हमारे मन की स्थितियों का बयान करता है। हमारा व्यवहार ही हमारे व्यक्तित्व का आईना होता है।'

JDBC


What is the JDBC?
Java Database Connectivity (JDBC) is a standard Java API to interact with relational databases form Java. JDBC has set of classes and interfaces which can use from Java application and talk to database without learning RDBMS details and using Database Specific JDBC Drivers.
Features of JDBC 4.0
The major features added in JDBC 4.0 include :
·         Auto-loading of JDBC driver class
·         Connection management enhancements
·         Support for RowId SQL type
·         DataSet implementation of SQL using Annotations
·         SQL exception handling enhancements
·         SQL XML support
Basic Steps in writing a Java program using JDBC
JDBC makes the interaction with RDBMS simple and intuitive. When a Java application needs to access database :
·         Load the RDBMS specific JDBC driver because this driver actually communicates with the database (Incase of JDBC 4.0 this is automatically loaded).
·         Open the connection to database which is then used to send SQL statements and get results back.
·         Create JDBC Statement object. This object contains SQL query.
·         Execute statement which returns resultset(s). ResultSet contains the tuples of database table as a result of SQL query.
·         Process the result set.
·         Close the connection.
JDBC Architecture.
The JDBC Architecture consists of two layers:
·         The JDBC API, which provides the application-to-JDBC Manager connection.
·         The JDBC Driver API, which supports the JDBC Manager-to-Driver Connection.
The JDBC API uses a driver manager and database-specific drivers to provide transparent connectivity to heterogeneous databases. The JDBC driver manager ensures that the correct driver is used to access each data source. The driver manager is capable of supporting multiple concurrent drivers connected to multiple heterogeneous databases. The location of the driver manager with respect to the JDBC drivers and the Java application is shown in Figure 1.

Figure 1: JDBC Architecture

Main components of JDBC
The life cycle of a servlet consists of the following phases:
  • DriverManager: Manages a list of database drivers. Matches connection requests from the java application with the proper database driver using communication subprotocol. The first driver that recognizes a certain subprotocol under JDBC will be used to establish a database Connection.

  • Driver: The database communications link, handling all communication with the database. Normally, once the driver is loaded, the developer need not call it explicitly.

  • Connection : Interface with all methods for contacting a database.The connection object represents communication context, i.e., all communication with database is through connection object only.

  • Statement : Encapsulates an SQL statement which is passed to the database to be parsed, compiled, planned and executed.

  • ResultSet: The ResultSet represents set of rows retrieved due to query execution.


JDBC application works
A JDBC application can be logically divided into two layers:
1. Driver layer
2. Application layer
  • Driver layer consists of DriverManager class and the available JDBC drivers.
  • The application begins with requesting the DriverManager for the connection.
  • An appropriate driver is choosen and is used for establishing the connection. This connection is given to the application which falls under the application layer.
  • The application uses this connection to create Statement kind of objects, through which SQL commands are sent to backend and obtain the results.

Figure 2: JDBC Application

Sunday, February 21, 2010

Get fit with this easy rule: Walking

Man exercising
The deceptively simple path to a fit bod begins with the easiest activity in the world: walking.

Every get-fit plan should start with a basic 30-minute daily walk for 30 days. It will prime your body for the muscle-toning and stamina-building exercises you need in order to go from couch potato to hot property. Cheat or skip this simple step and you run the risk of injuring yourself and falling off the fitness wagon.

First things first
According to experts, an out-of-shape muscle is deficient in two things: tiny power house factories (called mitochondria) that generate juice for your workouts, and contractile proteins that give the muscle strength. And walking for 30 minutes a day – or for 10 minutes three times a day – for a month replenishes mitochondria and contractile proteins, so your body will be ready and able to build on your fitness routine. Find out how an "easy" walk can still help you lose weight.

Take the next step
When you're ready to expand your exercise program, follow these guidelines for sculpting a lean, healthy body:

- After 30 days of walking, add 10 minutes of resistance training, focusing on the large muscle groups of your body (back, abs, quads, glutes, shoulders, and hamstrings) every other day.

- The next month, add another 10 minutes of resistance training, hitting your remaining muscle groups (chest, shoulders, and arms) every other day.

Congratulations! After 90 days, you'll be ready to pull out your cutest workout gear and showoff your fit body. Add 21 minutes of stamina-building exercise to your routine three times a week.
Sexual act
Seven point guide for the Big O (Getty Images)
Unhappy with your sex life? Don't feel dejected. It's time to add some zing to your sex romps, courtesy our seven point guide to the Big O.

1. Be comfortable : While experimentation is all important, do not try positions that you are physically uncomfortable in. What works for you, might not work for someone else, so remember the key to good sex is finding a hot spot that works for you and your partner. Experiment with positions that give you more leverage to hit the right spots. And feel maximum pleasure. Communicate what position you feel best in to your better half as that will give you better access to their moan zones.

2. Feel the vibrations : A lot of us may not believe this, but using a vibrator during sex can lend immense pleasure to both partners and if time is of the essence, there's nothing more efficient than this sex machine. Just ensure you're giving your man extra TLC, so that he doesn't feel left out or that he's not needed in the act.

3. Fantasy unlimited : Using your imagination during the act goes a long way if you're not really feeling all that excited. Fantasies are very powerful and act as a potent sexual stimulus, so use it to enhance the physical sensations that are happening and soon you'll be in seventh heaven.

4. Curb distractions : While having sex, cut out all distractions - be it keeping your eye on an ongoing football match or on the clock or checking your phone or laptop for mails and messages. Be committed to the act of sex like it's a job you are on because getting distracted will only deter your performance.

5. Don't think of the end result : Sometimes, the harder you try, the harder it becomes to feel pleasure. If all you are focussed on is getting an orgasm, chances are that it will be more difficult to attain. Don't make your climax the sole objective. Enjoy the sensations, the smell, the foreplay, the caressing and the words. As someone said - 'it's a journey, not a destination.'

6. Indulge in porn : Magazines, DVDs, internet porn; there's no harm using external stimulation to get a sexual high. Watching other people having sex is an incredible turn on and can speed your sex session well. Just remove the porn DVD from your disc drive before that an important presentation at work or if you have kids at home to avoid embarrassment.

7. Talk the talk : Gone are the days when sex was supposed to be a silent process. Talk freely to your beau about what turns you on, your hot spots and the ways in which you feel pleasured the most and it's likely that you will discover a new meaning to a routine sex ritual. Also, during sex don't be afraid to moan aloud or call aloud your lover's name. It may just act as an added turn on!

Life is beautiful inside and outside

Girl
Should you live? With joy and exuberance. Joy should come not only from serving society but also from enjoying the best things in life. Just live with them, enjoy them. You do not have to possess something to enjoy it.

Look at the butterfly. Its lifespan is so short, yet it enjoys itself thoroughly. It goes from flower to flower, the most beautiful creation of nature. It sucks nectar the sweetest thing in nature. Give it anything else to eat or drink, but it chooses only the best, honey. Similarly, we should speak only sweetly, think and live beautifully and enjoy life. Sweetness is the secret of a beautiful life. Once we speak sweetly the whole world will speak sweetly to us. This should become our nature. Only bhakti can ensure this, because bhakti means love.

What do we do in temples? We put a stone there and offer archana , which means we lavish praise on the stone for all the qualities we value. We say you are our father, our mother. We invoke agni and offer praise, not one or two but one crore prayers each time. By doing this, we invest power in that stone.

One day a priest, adept as he was in offering worship, came home and heaped praise on his wife. You can imagine what a happy home she made for him. We have to develop the ability to appreciate the good in everyone. If we are happy and so are others, our speech will become sweet. Life then becomes easy, weightless. Otherwise the mind is full of problems and we are always ready to fight. If we develop sattvik qualities, wherever we go we will be happy.

We are also quick to point out different things that have disturbed our equanimity. If you think deeply you will find the fault always lies with others, never do you find yourself at fault! Actually it is the other way round.

One day a man felt he needed to see and talk to God. He went to a forest where he saw a sage sitting in meditation. He placed his request. The sage told him to collect rainwater in a pot and look into it till the mud settled. ''When you see your face in the water, you will know you have got gyana .''

The man did as instructed. Just as the water was becoming clear and he was beginning to see his face, the sage disturbed the pot. He did this repeatedly. Finally the seeker got upset. ''Oh! I am not disturbing it. I just shook it,'' said the sage. It is in the nature of worldly things that people keep ''disturbing'' or interfering with your life and time.

So if you find that someone has put you in a bad mood and so you cannot say nice words, or that when you see a person you remember his bad qualities and find nothing to praise, you know that the external world has disturbed the pot in your mind. Do not let it do so. God and everything divine is within you and in everyone around you. If there is happiness within you, you would not quarrel. And to find that happiness you have to find the divine in everyone.

As told to Sudhamahi Regunathan. Balgangadharnath Swami is the 71st pontiff of the Adichunchanagiri Mutt, Karnataka.

Friday, February 19, 2010

java-awt

How would you set the color of a graphics context called g to cyan?
g.setColor(Color.cyan);
g.setCurrentColor(cyan);
g.setColor(“Color.cyan”);
g.setColor(“cyan’);
g.setColor(new Color(cyan));
Ans : a.

The code below draws a line. What color is the line?
g.setColor(Color.red.green.yellow.red.cyan);
g.drawLine(0, 0, 100,100);
Red
Green
Yellow
Cyan
Black
Ans : d.

What does the following code draw?
g.setColor(Color.black);
g.drawLine(10, 10, 10, 50);
g.setColor(Color.RED);
g.drawRect(100, 100, 150, 150);
A red vertical line that is 40 pixels long and a red square with sides of 150 pixels
A black vertical line that is 40 pixels long and a red square with sides of 150 pixels
A black vertical line that is 50 pixels long and a red square with sides of 150 pixels
A red vertical line that is 50 pixels long and a red square with sides of 150 pixels
A black vertical line that is 40 pixels long and a red square with sides of 100 pixel
Ans : b.

Which of the statements below are true?
A polyline is always filled.
b) A polyline can not be filled.
c) A polygon is always filled.
d) A polygon is always closed
e) A polygon may be filled or not filled
Ans : b, d and e.

What code would you use to construct a 24-point bold serif font?
new Font(Font.SERIF, 24,Font.BOLD);
new Font(“SERIF”, 24, BOLD”);
new Font(“BOLD “, 24,Font.SERIF);
new Font(“SERIF”, Font.BOLD,24);
new Font(Font.SERIF, “BOLD”, 24);
Ans : d.

What does the following paint( ) method draw?
Public void paint(Graphics g) {
g.drawString("question #6",10,0);
}
 
The string “question #6″, with its top-left corner at 10,0
A little squiggle coming down from the top of the component, a little way in from the left edge
Ans : b.

What does the following paint( ) method draw?
Public void paint(Graphics g) {
g.drawString(“question #6″,10,0);
}
A circle at (100, 100) with radius of 44
A circle at (100, 44) with radius of 100
A circle at (100, 44) with radius of 44
The code does not compile
Ans : d.

8)What is relationship between the Canvas class and the Graphics class?
Ans : A Canvas object provides access to a Graphics object via its paint( ) method.

What are the Component subclasses that support painting.
Ans : The Canvas, Frame, Panel and Applet classes support painting.

What is the difference between the paint( ) and repaint( ) method?
Ans : The paint( ) method supports painting via a Graphics object. The repaint( ) method is used to cause paint( ) to be invoked by the AWT painting method.

What is the difference between the Font and FontMetrics classes?
Ans : The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.

Which of the following are passed as an argument to the paint( ) method?
A Canvas object
A Graphics object
An Image object
A paint object
Ans : b.

Which of the following methods are invoked by the AWT to support paint and repaint operations?
paint( )
repaint( )
draw( )
redraw( )
Ans : a.

Which of the following classes have a paint( ) method?
Canvas
Image
Frame
Graphics
Ans : a and c.

Which of the following are methods of the Graphics class?
drawRect( )
drawImage( )
drawPoint( )
drawString( )
Ans : a, b and d.

Which Font attributes are available through the FontMetrics class?
ascent
leading
case
height
Ans : a, b and d.

Which of the following are true?
The AWT automatically causes a window to be repainted when a portion of a window has been minimized and then maximized.
The AWT automatically causes a window to be repainted when a portion of a window has been covered and then uncovered.
The AWT automatically causes a window to be repainted when application data is changed.
The AWT does not support repainting operations.
Ans : a and b.

Which method is used to size a graphics object to fit the current size of the window?
Ans : getSize( ) method.

What are the methods to be used to set foreground and background colors?
Ans : setForeground( ) and setBackground( ) methods.

19) You have created a simple Frame and overridden the paint method as follows
public void paint(Graphics g){
 
 g.drawString("Dolly",50,10);
}
 
What will be the result when you attempt to compile and run the program?
The string “Dolly” will be displayed at the centre of the frame
b) An error at compilation complaining at the signature of the paint method
c) The lower part of the word Dolly will be seen at the top of the form, with the top hidden.
d) The string “Dolly” will be shown at the bottom of the form
Ans : c.

20) Where g is a graphics instancewhat will the following code draw on the screen.
g.fillArc(45,90,50,50,90,180);
a) An arc bounded by a box of height 45, width 90 with a centre point of 50,50, starting
at an angle of 90 degrees traversing through 180 degrees counter clockwise.
b) An arc bounded by a box of height 50, width 50, with a centre point of 45,90 starting
at an angle of 90 degrees traversing through 180 degrees clockwise.
c) An arc bounded by a box of height 50, width 50, with a top left at coordinates of 45,
90, starting at 90 degrees and traversing through 180 degrees counter clockwise.
d) An arc starting at 45 degrees, traversing through 90 degrees clockwise bounded by a
box of height 50, width 50 with a centre point of 90, 180.
Ans : c.

21) Given the following code
import java.awt.*;
public class SetF extends Frame{
public static void main(String argv[]){
SetF s = new SetF();
s.setSize(300,200);
s.setVisible(true);
}
}
 
How could you set the frame surface color to pink?
a)s.setBackground(Color.pink);
b)s.setColor(PINK);
c)s.Background(pink);
d)s.color=Color.pink
Ans : a.

java-question

1)What is OOPs?
Ans: Object oriented programming organizes a program around its data,i.e.,objects and a set of well defined interfaces to that data.An object-oriented program can be characterized as data controlling access to code.

2)what is the difference between Procedural and OOPs?
Ans: a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOPs program, unit of program is object, which is nothing but combination of data and code.
b) In procedural program,data is exposed to the whole program whereas in OOPs program,it is accessible with in the object and which in turn assures the security of the code.

3)What are Encapsulation, Inheritance and Polymorphism?
Ans: Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse.
Inheritance is the process by which one object acquires the properties of another object.
Polymorphism is the feature that allows one interface to be used for general class actions.

4)What is the difference between Assignment and Initialization?
Ans: Assignment can be done as many times as desired whereas initialization can be done only once.

5)What are Class, Constructor and Primitive data types?
Ans: Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created.
Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char

6)What is an Object and how do you allocate memory to it?
Ans: Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.

7)What is the difference between constructor and method?
Ans: Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.

8)What are methods and how are they defined?
Ans: Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes.Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above.

9)What is the use of bin and lib in JDK?
Ans: Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.

10)What is casting?
Ans: Casting is used to convert the value of one type to another.

11)How many ways can an argument be passed to a subroutine and explain them?
Ans: An argument can be passed in two ways. They are passing by value and passing by reference.Passing by value: This method copies the value of an argument into the formal parameter of the subroutine.Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.

12)What is the difference between an argument and a parameter?
Ans: While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.

13)What are different types of access modifiers?
Ans: public: Any thing declared as public can be accessed from anywhere.
private: Any thing declared as private can’t be seen outside of its class.
protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages.
default modifier : Can be accessed only to classes in the same package.

14)What is final, finalize() and finally?
Ans: final : final keyword can be used for class, method and variables.A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods.A final method can’ t be overriddenA final variable can’t change from its initialized value.finalize( ) : finalize( ) method is used just before an object is destroyed and can be called just prior to garbage collecollection finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.

15)What is UNICODE?
Ans: Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.

16)What is Garbage Collection and how to call it explicitly?
Ans: When an object is no longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection.System.gc() method may be used to call it explicitly.

17)What is finalize() method ?
Ans: finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.

18)What are Transient and Volatile Modifiers?
Ans: Transient: The transient modifier applies to variables only and it is not stored as part of its object’s Persistent state. Transient variables are not serialized.Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.

19)What is method overloading and method overriding?
Ans: Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading.
Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.

20)What is difference between overloading and overriding?
Ans: a) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method.
b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass.
c) In overloading, separate methods share the same name whereas in overriding,subclass method replaces the superclass.
d) Overloading must have different method signatures whereas overriding must have same signature.

21) What is meant by Inheritance and what are its advantages?
Ans: Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.

22)What is the difference between this() and super()?
Ans: this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.

23)What is the difference between superclass and subclass?
Ans: A super class is a class that is inherited whereas sub class is a classthat does the inheriting.

24) What modifiers may be used with top-level class?
Ans: public, abstract and final can be used for top-level class.

25)What are inner class and anonymous class?
Ans: Inner class : classes defined in other classes, including those defined in methods are called inner classes. An inner class can have any accessibility including private.Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.

sql-question


1.  Which is the subset of SQL commands used to manipulate Oracle Database structures, including tables?
Data Definition Language (DDL)

2.      What operator performs pattern matching?
LIKE operator

3.      What operator tests column for the absence of data?
IS NULL operator

4.      Which command executes the contents of a specified file?
             START or @

5.      What is the parameter substitution symbol used with INSERT INTO command?
             &

6.      Which command displays the SQL command in the SQL buffer, and then executes it?
             RUN

7.      What are the wildcards used for pattern matching?
             _ for single character substitution and % for multi-character substitution

8.      State true or false. EXISTS, SOME, ANY are operators in SQL.
             True

9.      State true or false. !=, <>, ^= all denote the same operation.
             True

10.  What are the privileges that can be granted on a table by a user to others?
            Insert, update, delete, select, references, index, execute, alter, all

11.  What command is used to get back the privileges offered by the GRANT command?
             REVOKE

12.  Which system tables contain information on privileges granted and privileges obtained?
             USER_TAB_PRIVS_MADE, USER_TAB_PRIVS_RECD

13.  Which system table contains information on constraints on all the tables created?
             USER_CONSTRAINTS

14.        TRUNCATE TABLE EMP;
DELETE FROM EMP;
Will the outputs of the above two commands differ?
             Both will result in deleting all the rows in the table EMP.

15.  What is the difference between TRUNCATE and DELETE commands?
             TRUNCATE is a DDL command whereas DELETE is a DML command. Hence DELETE operation can be rolled back, but TRUNCATE operation cannot be rolled back. WHERE clause can be used with DELETE and not with TRUNCATE.

16.  What command is used to create a table by copying the structure of another table?
Answer :
             CREATE TABLE .. AS SELECT command
Explanation :
To copy only the structure, the WHERE clause of the SELECT command should contain a FALSE statement as in the following.
CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE WHERE 1=2;
If the WHERE condition is true, then all the rows or rows satisfying the condition will be copied to the new table.

17.  What will be the output of the following query?
SELECT REPLACE(TRANSLATE(LTRIM(RTRIM('!! ATHEN !!','!'), '!'), 'AN', '**'),'*','TROUBLE') FROM DUAL;
             TROUBLETHETROUBLE

18.  What will be the output of the following query?
SELECT  DECODE(TRANSLATE('A','1234567890','1111111111'), '1','YES', 'NO' );
Answer :
             NO
Explanation :
The query checks whether a given string is a numerical digit.

19.  What does the following query do?
SELECT SAL + NVL(COMM,0) FROM EMP;
             This displays the total salary of all employees. The null values in the commission column will be replaced by 0 and added to salary.


20.  Which date function is used to find the difference between two dates?
             MONTHS_BETWEEN

21.  Why does the following command give a compilation error?
DROP TABLE &TABLE_NAME;
             Variable names should start with an alphabet. Here the table name starts with an '&' symbol.

22.  What is the advantage of specifying WITH GRANT OPTION in the GRANT command?
             The privilege receiver can further grant the privileges he/she has obtained from the owner to any other user.

23.  What is the use of the DROP option in the ALTER TABLE command?
             It is used to drop constraints specified on the table.

24.  What is the value of ‘comm’ and ‘sal’ after executing the following query if the initial value of ‘sal’ is 10000?
UPDATE EMP SET SAL = SAL + 1000, COMM = SAL*0.1;
             sal = 11000, comm = 1000

25.  What is the use of DESC in SQL?
Answer :
             DESC has two purposes. It is used to describe a schema as well as to retrieve rows from table in descending order.
Explanation :
The query SELECT * FROM EMP ORDER BY ENAME DESC will display the output sorted on ENAME in descending order.

26.  What is the use of CASCADE CONSTRAINTS?
             When this clause is used with the DROP command, a parent table can be dropped even when a child table exists.

27.  Which function is used to find the largest integer less than or equal to a specific value?
             FLOOR

28.  What is the output of the following query?
SELECT TRUNC(1234.5678,-2) FROM DUAL;
             1200

Wednesday, February 17, 2010

Here are ten ways to kick-start your love life:

Take time with each other. Separate it from kids and work, where kids and work are not discussed.
Plan a weekly date – whether it's going out to dinner or talking a walk. Don't go out to the movies or someplace where you're not going to talk or look at each other the entire night. If you can't afford a babysitter, go out on the porch and have a glass of wine together after the kids go to sleep, or go out by yourself.

Do interesting and exciting things together. In a study of three couple groups, those who engaged in activities like bungee jumping and white-water rafting had the greatest improvement in intimacy, connection and sexual interest. No one else in their day-to-day-life was really a part of the activity, so it sort of bonded them together more.

Take time for yourself every day. While this can be tough with hectic schedules, jobs and kids, even 10 to 15 minutes a day can help reduce your stress and give you more energy for your partner. What's more, it's really hard to go out and go bungee jumping if you've neglected your own life. It's important to keep your own energy going. The more connected to who you are, the less you get lost in the daily grind, which pulls you away from your partner. And the more sensual and the more connected to yourself you are, the more available you are for your partner. It's really tough when one partner stays really connected with themselves and the other is still lost. Both partners really need to make a commitment to do that.

Turn by turn. Ask your partner to take the kids a couple of afternoons a week while you read, take a bath, meditate or exercise.

Dress to the T. Doll up yourself and hand your partner the keys to a hotel room.

Touch technique. Be physical with one another without expecting sex to be the outcome – cuddle, hold hands, touch one another.

Try out. Experiment with different sexual positions. It’s a great way of exploring each other’s bodies.

Do as you wish. Do something you've always wanted to do like take a yoga class and learn to play the piano. It’s never too late to lean something new and enjoy it.

Monday, February 15, 2010

Your body language and actions speak louder than words, at least for a healthy sexual relationship. There are several signals and gestures from

your partner which normally you may miss on a routine day. But often it's these expressions of love that indicate that your partner is all set for a night of passion.

From planning a lavish dinner, getting clad in sexy outfits to exchanging naughty messages throughout the day or showering your lover with surprise gifts... these are indications that your partner wants to get cosy. Now it is entirely up to the other partner as how quickly they catch these clues and get ready for some bedroom action.

We list some of the lesser known ‘signs’ from your mate, which would help you decode their sex language easily. Experts too lend some handy tips to make this ‘read between the lines’ experience more exciting...

Dressed to kill : How often would you see your partner clad in a sexy revealing attire without any occasion? Not each day, of course! But if their sensuous style of dressing grabs your attention, it’s very likely that they are angling towards an intimate session. Flaunting see-through lingerie in sensuous shades of red often points out that a woman expects to be loved.

Hot tip : Body language expert Rita Gangwani suggests, “Make it a point to indulge in a sensual play with a provocative undressing to ignite sexual passion. The best way is to go slow because the charm gets lost if you undress all at once, so instead play a game and ask you mate to shed clothes one by one.”

Kids are fast asleep : Some partners have a tendency to baby-sit their kids or remain indulged with teenage kids despite the other mate waiting to make love. In such cases with the kids around, the passion gets spoilt. So what if your mate has got the kids to go to bed early on a particular night? Well, there are chances that he/she is charged for a steamy romp.

Hot tip : Relationship counsellor Dr. Chitra Bakshi says, “When one partner has made sure that the kids do not come in way of their private moments, they need to be extra discreet about their love-making acts. The couple shouldn’t make much noise, as couples tend to get hyper during these acts, so the best would be to do it on the floor. Also, make sure that locks are working properly and curtains are drawn."

Magic with aphrodisiacs : Cooking delectable dishes is the best way to tempt your partner. And if the ingredients happen to be aphrodisiacs, there is no reason that your partner would not understand the sexual signs. Aphrodisiacs like grapes and strawberry are ultimate wonder fruits. You can dip them in whipped cream and invite you partner to taste it.

Hot tip : Psychologist Dr. Ratan Kumar states, “Once it has been conveyed through a romantic dinner that you’re on for a sexual session, make sure that you relish the food by serving each other in a loving manner. Best would be to treat each other sensually, which would help keep the mood alive for passionate moments in bed.”

Break time from office : It's not very often that your partner heads back home early or takes a leave from office without any reason just to be at home (with you). But if they do and more so, if they put their mobile on the silent mode, it’s apparent that their romantic senses are highly stimulated.

Hot tip : Rita asserts, “When your mate has shown a clear interest for some wild action, all you need is to make sure that you too arrange for a break from your workplace and enjoy the pleasure. Once that’s in place, utilise the time to build an exotic environment in your bedroom and let your partner know that you’re equally geared up.”

Surprises to woo : One of the most predictable ways of reading your partner’s mind is the love surprises that they give in the form of gifts. Though it’s not always that giving a gift implies their intension to get intimate, but on certain occasions when the gift comes unexpected or reminds you of some intimate moments cherished earlier, it might be that your beau wants some hot passion.

Hot tip : “Whenever gifts are of a sexual nature like a red flower, a card with some intimate images, lingerie or s heady perfume with an arousing smell, it’s a clear hint that it’s time for a lovemaking night. You just need to ensure that you express it to the other partner that you loved their gifts and it has actually aroused your sexual senses,” recommends Dr. Chitra.

Naughty texts do the talk : Not many couples prefer exchanging romantic messages with their better half during his/her office hours. But if either of the partners is sounding keen and sending naughty messages repeatedly, it might clearly point out that they want some hot sex.

Hot tip : “A text message is possibly the best medium to express what’s on your mind at a given time. Here, the partner on the receiving end must try to respond in a similar way so that the sexual passion is at its peak by the time they reach home. But do not give in easily and let the other partner keep guessing about your mood,” advices Rita.