Search This Blog

Sunday 18 December 2011

Difference between Statement and Prepared Statement

Statement:

When you use normal statements compilation of statement or
parsing of statement will happen every time. This is time
consuming when u have multiple queries to execute.

Statement s = conn.createStatement();
s.executeQuery();

Prepared Statement:
In prepared statement SQL query will be compiled or parsed
for the very first time and kept in some kind of pool. When
u execute one more time the same statement with different
values it saves the parsing time.

The PreparedStatement is a slightly more powerful version of a Statement, and should always be at least as quick and easy to handle as a Statement.

The PreparedStatement may be parametrized.
Prepared statement is precompiled statement it is used when
we want one query to be executed n no. of times.
Prepared Statement is Pre-compiled class , but Statement is not.
So in PreparedStatement the execution will be faster.

SQL select * from employee where employeeID=?,empName=?;
PreparedStatement ps = conn.PreparedStatement();
ps.execute(1,aru);
ps.execute(2,arya);

Callable Statement:

Callable statements are used to execute stored procedures
similar to java functions.

Tuesday 6 December 2011

Object Class functions in java

Object Class
Object Class is the Super class for all classes in JAVA.The Object class defines the basic state and behavior that all objects must have, such as the ability to compare oneself to another object, to convert to a string, to wait on a condition variable, to notify other objects that a condition variable has changed, and to return the object's class.
The Object Class Functions:
equals:
This function is used to compare two objects whether they have equivalent values are not.
It returns true if they are equal else returns false.
The getClass() Method:
The getClass method is a final method (cannot be overridden)
This method returns a Class object.With this class you can get the information of object like name, its super class, and the names of the interfaces that it implements.
use of the getClass method is to create a new instance of a class without knowing what the class is at compile time. This sample method creates a new instance of the same class as obj which can be any class that inherits from Object (which means that it could be any class):
Object createNewInstanceOf(Object obj) {
return obj.getClass().newInstance();
}
The toString Method
Object's toString method returns a String representation of the object. You can use toString to display an object.
The Object class also provides five methods that are critical when writing multithreaded Java programs:
• notify
• notifyAll
• wait (three versions)
hashCode()
Returns a hash code value for the object.
finalize()
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

Thursday 1 December 2011

System.out.println

Some people dont know what is System,out,println in System.out.println.
As per my Knowledge,

System is a class in java which is final class(Final will stop inheritance)

out is a static final PrintStream object that is in System Class
And println is a function in PrintStream class
Since out is a static object with out creating object we can access
directly
As
System.out.println();

Thursday 29 September 2011

Basics of Tables in MYSQL


A relational database system contains one or more objects called tables. The data or information for the database are stored in these tables. Tables are uniquely identified by their names and are comprised of columns and rows. Columns contain the column name, data type, and any other attributes for the column. Rows contain the records or data for the columns.

Example:Suppose you want to store the details of your company employees.
Generally Employees will have name, employee id,address.these properties we will represent them as columns.And the data of each employee will be as one Row.

Thursday 23 June 2011

Example on Java script

Most of the people are thinking about programming language java and java script are
same.But they are different.
Java script is mainly used for client side validations,not only this we can have so many uses from java script.

Thursday 5 May 2011

Overloading And Overriding Concepts

Method Overloading:
Method overloading in Java is nothing but two or more functions having same function name but with different parameters and signatures.

This can be implemented by compile time polymorphism


Method Overriding:


Method overriding in java is nothing but the function present in super class is overrides the function in sub class in other way add additional functionality to the function in super class
One thing to be noted down is
the function names in super class and sub class are same with signatures also..
Method overriding can be implemented by runtime polymorphism.

Tuesday 19 April 2011

Interface

Interface:
An interface in the java programing is an abstract type.
Interface can have variables and methods.
variables in interface are final,means the variables are constant,
and the methods dont have any definition.
An interface is declared as
interface interfacename
{
//variables
//method names with out any body definition
}
For an interface we cannot create any object for it.
If we want to create object we need to implement this interface through a class.
and the implemting class should all the methods in interface if not the class becomes abstract.
An interface can implement another interface also.


Thursday 14 April 2011

Types of Inheritance

1.Simple inheritance
Simple inhertance means one class extends the the class
Example
Class B extends A
B is the sub class and A is sub class
2.Multiple inheritance
Java implements multiple inheritance through interfaces but not through classes
multiple inheritance example
interface A
interface B
class C implements B,A
so multiple inheritance means one class can have one or more super classes.
3.Hybrid inheritance:
Suppose take an example
class A
class B extends A
class C extends B
means here class C has two super class B inturn B has a super class A
Advantages of inheritance
Main advantage of inheritance is code reusability
means the code in one class can be reused with out writing the code again.

Wednesday 13 April 2011

Inheritance

This is one of the important Oops. concept.
what is inheritance:
Aquiring the properties of one object class to another object class is called inheritance.
Means suppose take an example of  mother and child,some of the mother features will come to child.
Like this only in java suppose take class A it contains a variable test as int data type.
and a method function as display with return type void.
now take another class B it extends Class A means A is super class and now B is subclass
now B class will contain variable test and function display.
syntax of this is as follows......
Class A
{
//variables and functions
}

Class B extends A
{
//you can add your own functions also here
}
I will post the types of inheritance in my next post...

Class

A class is a blueprint or prototype from which objects are created.
In a class we can have class variables and methods.
Through these methods we can do operations on variables as per the requirement.
A class can be public private.
public class can access outside the package also but not the private class
A class can be abstract, final static.

Friday 8 April 2011

Hai

If any doubts pls post ur questions,
i will try to solve it....