Potential Gold Mines found in South India
Marry a malayali girl and see how much gold you can get...
For those who are already married.... Sorry folks....
What is the difference between HttpSession mySession=request.getSession(true) and HttpSession mySession=request.getSession()
What is the difference between HttpSession mySession=request.getSession(true) and HttpSession mySession=request.getSession().?
Answer:
request.getSession() will return the current session and if one does not exist, a new session will be cretaed.
request.getSession(true) will return the current session if one exists, if one doesn't exits a new one will be created.
So there is actually no difference between the two methods HOWEVER, if you use request.getSession(false), it will return the current session if one exists and if one DOES NOT exist a new one will NOT be cretaed.
Types of Joins in Oracle with Examples
9i Joins:
Supports ANSI/ISO standard Sql 1999 syntax
Made easy for Appln s/w tools to understand Sql Queries
1. Natural Join
2. Join with Using
3. Join with ON
4. Inner Join
5. Left outer join
6. Right outer join
*7. Full outer join
8. Cross join
1. > select empno,ename,sal,job,deptno,dname,loc
from emp natural join dept;
2. > select empno,ename,sal,job,deptno,dname,loc
from emp join dept using(deptno);
3. > select e.empno, e.ename, e.sal, e.job, e.deptno, d.dname, d.loc from emp e Join dept d
on(e.deptno = d.deptno) ;
4. > select e.empno, e.ename, e.sal, e.job, e.deptno,d.dname, d.loc from emp e Inner Join dept d
on(e.deptno = d.deptno) ;
5. > select e.empno, e.ename, e.sal, e.job, e.deptno,d.dname, d.loc from emp e left outer join dept d on(e.deptno = d.deptno) ;
6. > select e.empno, e.ename, e.sal, e.job, e.deptno,d.dname, d.loc from emp e right outer join dept d on(e.deptno = d.deptno) ;
* 7. > select e.empno, e.ename, e.sal, e.job, e.deptno,d.dname, d.loc from emp e full outer join dept d on(e.deptno = d.deptno) ;
** left outer join union right outer join = full outer join
8. > select empno,ename,sal,job,deptno,dname,loc from emp cross join dept;
Oracle 8.0 Features
Used to return the values thru " DML" stmts.
Used with update and delete stmts.
Ex:
>var a varchar2(20)
>var b number
>update emp set sal = sal + 3000 where empno = 7900
returning ename,sal into :a,:b;
>print a b
>delete from emp where empno = 7902
returning ename,sal into :a,:b;
>print a b
----------------------------------------------------------------------------
* Bulk Collect:
Used to return bulk data into pl/sql variables.
Variables must be of pl/sql table type only.
Improves performance while retrieving data.
Used with select, update, delete, Fetch stmts.
select ename,sal into a,b from emp where empno = &ecode;
ecode : 101
>declare
type names is table of emp.ename%type index by binary_integer;
type pays is table of emp.sal%type index by binary_integer;
n names; p pays;
begin
-- retrieving all employees in 1 transaction
select ename,sal bulk collect into n,p from emp;
-- printing table contents
dbms_output.put_line('EMPLOY DETAILS ARE :');
for i in 1 .. n.count loop
dbms_output.put_line(n(i)||' '||p(i));
end loop;
end;
* update emp set sal = sal + 3000 where deptno = 30
returning ename,sal bulk collect into n,p;
* delete from emp where job = 'CLERK'
returning ename,sal bulk collect into n,p;
----------------------------------------------------------------------------
Using in Fetch stmt :
declare
type names is table of emp.ename%type index by binary_integer;
type pays is table of emp.sal%type index by binary_integer;
n names; p pays;
cursor c1 is select ename,sal from emp;
begin
open c1;
fetch c1 bulk collect into n,p;
-- printing table contents
for i in 1 .. n.count loop
dbms_output.put_line(n(i)||' '||p(i));
end loop;
end;
----------------------------------------------------------------------------
Dynamic SQL:
Supports to execute " DDL" stmts in Pl/sql block.
syntax: execute immediate(' DDL stmt ');
>begin
execute immediate(' create table employ1
(ecode number(4), ename varchar2(20),sal number(10))');
end;
Note: Table cannot be manipulated in same pl/sql block
begin
execute immediate('drop table employ1');
end;
----------------------------------------------------------------------------
Introduce yourself in interviews
1)Tell me about yourself?
A)Well,As you know Iam Hemanath Chowdary from Damlacheruvu which is little near to Chittoor in the part of Andhra Pradesh. I born and brought up in Andhrapradesh itself.
My Education Qualifiacation are I did my schooling in Games high school at tirupathi. After my schooling, I finished my graduation of Bsc Chemistry from S.V.arts college in 2006 that is affiliated to S.V. University at Tirupathi. After finishing my graduation, I have done my MCA from J N T University in2009.
Then I got selected in Solidus Multitech pvt ltd in bangalore and having around 2 yrs exp in Microsoft .NET technologies such as C#.net,Asp.net,Ado.net and other tool such as Ms sql server,Flat Text file,photoshop and dreamweaver.
Note:
• Here you should specify your experience on your projects...
• My career objective is Looking forward for a better carrer in Organization
• My strengths are dedications....willingness to walk an extra mile to achieve my career.
• Iam very eager to learn new technologies
• My weakness are.....
About my family background:
• My father is a retired headmaster and mother is a homemaker and i have 4 sisters and don't have brothers.
About my hoppies:
• singing song,playing cricket and watching TV
2)If we hire you, and then another company will offer you more money - what will you do?
A) Sir,money is not the matter.I prefer a company which gives me a oppurtunity to expose my ideas in a clear manner.
3)Why you are looking for change ?
A)i am looking for technical and economical growth, and wantto work in such environment where i can use my skill,innovative ideas and also improve my knowledge and skill.
4) how much salary you expected?
A)IT DEPENDS ON NOT ONLY COMPANY STANDARDS BUT ALSO ASPERINDIVIDUAL'S EXPERIENCE,PERFORMANCE AND CAPABILITY IN THE
PREVIOUS JOB AND MARKET CONDITION.
5) What does success mean to you?
A)For me success is not a destination of a achievement.It is a continous journey.
6) what are your strengths ?
A) My strengths are optimistic,self learner,team worker.i m altruist also
7) Tell me about your dream job.
A)The job that doesn't appear in my dream while i sleep.
8) What do you expect of others in a team environment?
A)Sharing knowledge & valuing the others opinion.
Clash of the Animal Titans
The explosive battle was caught on camera by British amateur photographer Mike Bailey as he holidayed in the remote Kwando River area of northern Botswana, Africa.
The spectacular dual between the huge spotted cat and the stouter tusked pig amazingly lasted over 10 minutes as the leopard tried to get the better of its prey.
Heart Attacks And Drinking Warm Water
A very good article which takes two minutes to read. I'm sending this to persons I care about.......I hope you do too!!! Heart Attacks And Drinking Warm Water This is a very good article. Not only about the warm water after your meal, but about Heart Attacks . The Chinese and Japanese drink hot tea with their meals, not cold water, maybe it is time we adopt their drinking habit while eating. |
A coke after that gives more power to this demon.
Avoid them for your Heart's Health
You may never have the first chest pain during the course of a heart attack.
A cardiologist says if everyone who reads this message sends it to 10 people, you can be sure that we'll save at least one life. Read this & Send to a friend. It could save a life... So, please be a true friend and send this article to all your friends you care about.
I JUST DID
How to do JUnit Testing Example
JUnit is a simple Java testing framework to write tests for you Java application. This tutorial gives
you an overview of the features of JUnit and shows a little example how you can write tests for
your Java application.
General
Author:
Sascha Wolski
Sebastian Hennebrueder
http://www.laliluna.de/tutorials.html – Tutorials for Struts, EJB, xdoclet and eclipse.
Date:
April, 12 2005
Software:
Eclipse 3.x
Junit 2.x
Source code:
http://www.laliluna.de/assets/tutorials/junit-testing-source.zip
PDF Version
http://www.laliluna.de/assets/tutorials/junit-testing-en.pdf
What is JUnit
JUnit is a simple open source Java testing framework used to write and run repeatable automated
tests. It is an instance of the xUnit architecture for unit testing framework. Eclipse supports
creating test cases and running test suites, so it is easy to use for your Java applications.
JUnit features include:
• Assertions for testing expected results
• Test fixtures for sharing common test data
• Test suites for easily organizing and running tests
• Graphical and textual test runners
What is a test case
A test case is a class which holds a number of test methods. For example if you want to test some
methods of a class Book you create a class BookTest which extends the JUnit TestCase class and
place your test methods in there.
How you write and run a simple test
1. Create a subclass of TestCase:
public class BookTest extends TestCase{
//..
}
2. Write a test method to assert expected results on the object under test:
Note: The naming convention for a test method is testXXX()
public void testCollection() {
Collection collection = new ArrayList();
assertTrue(collection.isEmpty());
}
3. Write a suite() method that uses reflection to dynamically create a test suite containing all the
testXXX() methods:
public static Test suite(){
return new TestSuite(BookTest.class);
}
4. Activate the JUnit view in Eclipse (Window > Show View > Other.. > Java > JUnit).
You find the JUnit tab near the Package Explorer tab. You can change the position of the tab by
drag and drop it.
5. Right click on the subclass of TestCase and choose Run > JUnit Test to run the test.
Using a test fixture
A test fixture is useful if you have two or more tests for a common set of objects. Using a test
fixture avoids duplicating the test code necessary to initialize and cleanup those common objects
for each test.
To create a test fixture, define a setUp() method that initializes common object and a tearDown()
method to cleanup those objects. The JUnit framework automatically invokes the setUp() method
before a each test is run and the tearDown() method after each test is run.
The following test uses a test fixture:
public class BookTest2 extends TestCase {
private Collection collection;
protected void setUp() {
collection = new ArrayList();
}
protected void tearDown() {
collection.clear();
}
public void testEmptyCollection(){
assertTrue(collection.isEmpty());
}
}
Dynamic and static way of running single tests
JUnit supports two ways (static and dynamic) of running single tests.
In static way you override the runTest() method inherited form TestCase class and call the desired
test case. A convenient way to do this is with an anonymous inner class.
Note: Each test must be given a name, so you can identify it if it fails.
TestCase test = new BookTest("equals test") {
public void runTest() {
testEquals();
}
};
The dynamic way to create a test case to be run uses reflection to implement runTest. It assumes
the name of the test is the name of the test case method to invoke. It dynamically finds and
invokes the test method. The dynamic way is more compact to write but it is less static type safe.
An error in the name of the test case goes unnoticed until you run it and get a
NoSuchMethodException. We leave the choice of which to use up to you.
TestCast test = new BookTest("testEquals");
What is a TestSuite
If you have two tests and you'll run them together you could run the tests one at a time yourself,
but you would quickly grow tired of that. Instead, JUnit provides an object TestSuite which runs
any number of test cases together. The suite method is like a main method that is specialized to
run tests.
Create a suite and add each test case you want to execute:
public static void suite(){
TestSuite suite = new TestSuite();
suite.addTest(new BookTest("testEquals"));
suite.addTest(new BookTest("testBookAdd"));
return suite;
}
Since JUnit 2.0 there is an even simpler way to create a test suite, which holds all testXXX()
methods. You only pass the class with the tests to a TestSuite and it extracts the test methods
automatically.
Note: If you use this way to create a TestSuite all test methods will be added. If you do not want all
test methods in the TestSuite use the normal way to create it.
Example:
public static void suite(){
return new TestSuite(BookTest.class);
}
A little example
Create a new Java project named JUnitExample.
Add a package de.laliluna.tutorial.junitexample where you place the example classes and a
package test.laliluna.tutorial.junitexample where you place your test classes.
The class Book
Create a new class Book in the package de.laliluna.tutorial.junitexample.
Add two properties title of type String and price of type double.
Add a constructor to set the two properties.
Provide a getter- and setter-method for each of them.
Add a method trunk for a method equals(Object object) which checks if the object is an instance of
the class Book and the values of the object are equal. The method return a boolean value.
Note: Do not write the logic of the equals(..) method, we do it after finish creating the test method.
The following source code shows the class Book.
public class Book {
private String title;
private double price;
/**
* Constructor
*
* @param title
* @param price
*/
public Book(String title,
double price) {
this.title = title;
this.price = price;
}
/**
* Check if an object is an instance of book
* and the values of title and price are equal
* then return true, otherwise return false
*/
public boolean equals(Object object) {
return false;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
The test case BookTest
Create a new test case BookTest in the package test.laliluna.tutorial.junitexample Right click on
the package and choose New > JUnit Test Case.
In the wizard choose the methods stubs setUp(), tearDown() and constructor().
The following source code shows the class BookTest
public class BookTest extends TestCase {
/**
* setUp() method that initializes common objects
*/
protected void setUp() throws Exception {
super.setUp();
}
/**
* tearDown() method that cleanup the common objects
*/
protected void tearDown() throws Exception {
super.tearDown();
}
/**
* Constructor for BookTest.
* @param name
*/
public BookTest(String name) {
super(name);
}
}
Now we want to write a test for the equals(..) method of the class Book. We provide three private
properties, book1, book2 and book3 of type Book.
private Book book1;
private Book book2;
private Book book3;
Within the setUp() method we initializes the three properties with some values. Property book1
and book3 are the same.
protected void setUp() throws Exception {
super.setUp();
book1 = new Book("ES", 12.99);
book2 = new Book("The Gate", 11.99);
book3 = new Book("ES", 12.99);
}
Within the tearDown() method we cleanup the properties:
protected void tearDown() throws Exception {
super.tearDown();
book1 = null;
book2 = null;
book3 = null;
}
Now, add a test method testEquals() to the test case. Within the method we use the assertFalse()
method of the JUnit framework to test if the return-value of the equals(..) method is false, because
book1 and book2 are not the same. If the return-value is false the logic of the equals() method is
correct, otherwise there is a logical problem while comparing the objects. We want to test if the
method compares the objects correctly by using the assertTrue() method. Book1 and Book3 are
the same, because both are an instance of the class Book and have the same values.
The following source code shows the testEquals() method:
public void testEquals(){
assertFalse(book2.equals(book1));
assertTrue(book1.equals(book1));
}
Writing the logic of the equals() method
We have finished the test and now we can add the logic to the equals() method stub. Open the
class Book and add the logic to the equals() method. First we check if the object given by the
method is an instance of Book. Then compare the properties title and price, if they are equal
return true.
public boolean equals(Object object) {
if (object instanceof Book) {
Book book = (Book) object;
return getTitle().equals(book.getTitle())
&& getPrice() == book.getPrice();
}
return false;
}
Create the suite() method
In order to run the test method testEquals() add a method suite() to the class BookTest.
Note: You can also create a separate class where you add the suite() method.
Within the method create a new instance of TestSuite and use the method addTest(..) to add a
test. Here we use the dynamically way to add a test to a TestSuite.
The method looks like the follows:
public static Test suite(){
TestSuite suite = new TestSuite();
suite.addTest(new BookTest("testEquals"));
return suite;
}
Run the test
After finishing all test methods we want to run the JUnit test case. Right mouse button on the class
BookTest and choose Run As > JUnit Test.
On the JUnit view (Menu Windows -> show view) of Eclipse you can see how many runs, errors
and failures occurred.
Types of JDBC Drivers
JDBC drivers are divided into four types or levels. The different types of jdbc drivers are:
Type 1: JDBC-ODBC Bridge driver (Bridge)
Type 2: Native-API/partly Java driver (Native)
Type 3: AllJava/Net-protocol driver (Middleware)
Type 4: All Java/Native-protocol driver (Pure)
4 types of jdbc drivers are elaborated in detail as shown below:
Type 1 JDBC Driver
JDBC-ODBC Bridge driver
The Type 1 driver translates all JDBC calls into ODBC calls and sends them to the ODBC driver. ODBC is a generic API. The JDBC-ODBC Bridge driver is recommended only for experimental use or when no other alternative is available.
Type 1: JDBC-ODBC Bridge
Advantage
The JDBC-ODBC Bridge allows access to almost any database, since the database’s ODBC drivers are already available.
Disadvantages
1. Since the Bridge driver is not written fully in Java, Type 1 drivers are not portable.
2. A performance issue is seen as a JDBC call goes through the bridge to the ODBC driver, then to the database, and this applies even in the reverse process. They are the slowest of all driver types.
3. The client system requires the ODBC Installation to use the driver.
4. Not good for the Web.
Type 2 JDBC Driver
Native-API/partly Java driver
The distinctive characteristic of type 2 jdbc drivers are that Type 2 drivers convert JDBC calls into database-specific calls i.e. this driver is specific to a particular database. Some distinctive characteristic of type 2 jdbc drivers are shown below. Example: Oracle will have oracle native api.
Type 2: Native api/ Partly Java Driver
Advantage
The distinctive characteristic of type 2 jdbc drivers are that they are typically offer better performance than the JDBC-ODBC Bridge as the layers of communication (tiers) are less than that of Type
1 and also it uses Native api which is Database specific.
Disadvantage
1. Native API must be installed in the Client System and hence type 2 drivers cannot be used for the Internet.
2. Like Type 1 drivers, it’s not written in Java Language which forms a portability issue.
3. If we change the Database we have to change the native api as it is specific to a database
4. Mostly obsolete now
5. Usually not thread safe.
Type 3 JDBC Driver
All Java/Net-protocol driver
Type 3 database requests are passed through the network to the middle-tier server. The middle-tier then translates the request to the database. If the middle-tier server can in turn use Type1, Type 2 or Type 4 drivers.
Type 3: All Java/ Net-Protocol Driver
Advantage
1. This driver is server-based, so there is no need for any vendor database library to be present on client machines.
2. This driver is fully written in Java and hence Portable. It is suitable for the web.
3. There are many opportunities to optimize portability, performance, and scalability.
4. The net protocol can be designed to make the client JDBC driver very small and fast to load.
5. The type 3 driver typically provides support for features such as caching (connections, query results, and so on), load balancing, and advanced
system administration such as logging and auditing.
6. This driver is very flexible allows access to multiple databases using one driver.
7. They are the most efficient amongst all driver types.
Disadvantage
It requires another server application to install and maintain. Traversing the recordset may take longer, since the data comes through the backend server.
Type 4 JDBC Driver
Native-protocol/all-Java driver
The Type 4 uses java networking libraries to communicate directly with the database server.
Type 4: Native-protocol/all-Java driver
Advantage
1. The major benefit of using a type 4 jdbc drivers are that they are completely written in Java to achieve platform independence and eliminate deployment administration issues. It is most suitable for the web.
2. Number of translation layers is very less i.e. type 4 JDBC drivers don’t have to translate database requests to ODBC or a native connectivity interface or to pass the request on to another server, performance is typically quite good.
3. You don’t need to install special software on the client or server. Further, these drivers can be downloaded dynamically.
Disadvantage
With type 4 drivers, the user needs a different driver for each database.