Escolar Documentos
Profissional Documentos
Cultura Documentos
IOC/Dependency Injection:
The basic concept of the Inversion of Control pattern (also known as dependency injection) is that
you do not create your objects but describe how they should be created. You don't directly
connect your components and services together in code but describe which services are needed
by which components in a configuration file. A container (in the case of the Spring framework, the
IOC container) is then responsible for hooking it all up.
Final Class:
A final class can not be extended. A final method can not be overridden. Main() method in java is
public, static and final, so that it can not be overridden and JVM can call it without creating any
instance of the class.
Since the final class can not be extended so there is always a compiler error if we define an
abstract method in it.
The code
int i = 0;
i = i++;
System.out.println(i);
produces the output "0" instead of "1". Why?
Let's take a close look at what the line "i = i++;" does:
1. "i++" is evaluated. The value of "i++" is the value of i before the increment
happens.
2. As part of the evaluation of "i++", i is incremented by one. Now i has the
value of 1;
3. The assignment is executed. i is assigned the value of "i++", which is the
value of i before the increment - that is, 0.
int oldValue = i;
i = i + 1;
i = oldValue;
Solution:
You don't need the assignment at all, just use
i++;
Hi nikki,
this is what is happening:
i=2; //you are assigning the variable i to the value of 2
i=i++; //you are assigning i to i, which is 2 so i = 2,
//increment here, but the incremented value did not get assigned to anything so i=2,
See also
• http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.
14.2
• http://www.coderanch.com/t/244938/java-programmer-
SCJP/certification/post-increment-confusion
• http://radio.javaranch.com/corey/2004/06/03/1086277171000.html
}
In this case the output is always: 2 2 2
If we open the a section then the result is : 3 4 5
Value of count is 6 here.
Connection Pooling:
A connection pooling is a pool of open connections.
The connection objects are used when required and released after they are done.
Thus the overhead of creating a connection object and establishing the connection
with the database is greatly reduced.
There is one problem with connection pooling. A web application has to explicitly
close ResultSet's, Statement's, and Connection's. Failure of a web application to
close these resources can result in them never being available again for reuse, a db
connection pool "leak". This can eventually result in your web application db
connections failing if there are no more available connections.
JDBC Net pure Java driver(Type IV) is the fastest driver because it converts the
jdbc calls into vendor specific protocol calls and it directly interacts with the
database.
Use of the JDBC Data Sources JNDI Resource Factory requires that you make an
appropriate JDBC driver available to both Tomcat internal classes and to your web
application. This is most easily accomplished by installing the driver's JAR file(s) into
the$CATALINA_HOME/common/lib directory, which makes the driver available both
to the resource factory and to your application.
Four additional methods let you verify whether the cursor is at a particular position. The position is stated in
the method names: isFirst, isLast, isBeforeFirst, isAfterLast. These methods all return
a boolean and can therefore be used in a conditional statement.
The method absolute will move the cursor to the row number indicated in the argument passed to it.
For example, suppose you have iterated through some rows in a result set and want to print two columns
from the current row. To be sure that the cursor has not gone beyond the last row, you could use code such
as the following, in which srs is a scrollable ResultSet object.
if (!srs.isAfterLast()) {
String name = srs.getString("COF_NAME");
float price = srs.getFloat("PRICE");
System.out.println(name + " " + price);
}
Before you can make updates to a ResultSet object, you need to create one that is updatable. In order to
do this, you supply the ResultSet constant CONCUR_UPDATABLE to thecreateStatement method.
The Statement object that is created will produce an updatable ResultSet object each time it
executes a query. The following code fragment illustrates creating the updatable ResultSet object uprs
uprs.last();
uprs.updateFloat("PRICE", 10.99f);
Update operations in the JDBC 2.0 API affect column values in the row where the cursor is positioned, so in
the first line, the ResultSet uprs calls the method last to move its cursor to the last row (the row
where the column COF_NAME has the value 'French_Roast_Decaf' ). Once the cursor is on the last
row, all of the update methods you call will operate on that row until you move the cursor to another row.
The second line changes the value in the PRICE column to 10.99 by calling the method updateFloat.
This method is used because the column value we want to update is a floatin the Java programming
language.
Any situation where a logical unit of work requires more than one update to the
database cannot be done safely in auto-commit mode. If something happens to the
application or the system after one update is made and before any other updates are
made, the first change cannot be undone when running in auto-commit mode.
You should not add a query (a SELECT statement) to a batch of SQL commands because the
method executeBatch, which returns an array of update counts, expects an update count from each
SQL command that executes successfully. This means that only commands that return an update count
(commands such as INSERT INTO, UPDATE, DELETE) or that return 0 (such as CREATE
TABLE, DROP TABLE, ALTER TABLE) can be successfully executed as a batch with
the executeBatch method.
BatchUpdateException is derived from SQLException. This means that you can use all of the
methods available to an SQLException object with it. The following code fragment prints all of
theSQLException information plus the update counts contained in
a BatchUpdateException object.
Because BatchUpdateException.getUpdateCounts returns an array of int, the code uses
afor loop to print each of the update counts.
try {
// make some updates
} catch(BatchUpdateException b) {
System.err.println("----BatchUpdateException----");
System.err.println("SQLState: " + b.getSQLState());
System.err.println("Message: " + b.getMessage());
System.err.println("Vendor: " + b.getErrorCode());
System.err.print("Update counts: ");
int [] updateCounts = b.getUpdateCounts();
for (int i = 0; i < updateCounts.length; i++) {
System.err.print(updateCounts[i] + " ");
}
System.err.println("");
}
If your program frequently provides random access to the data of the list, the
ArrayList class offers quick access to individual elements of the list. This quick access
comes at a cost of slower operations for adding and removing in the middle of the
list.
If this latter behavior is what you desire, than the LinkedList class offers a better
alternative. It provides quick sequential access, additions, and deletes, at a cost of
slower random access.
// Demonstrate iterators.
import java.util.*;
class IteratorDemo {
public static void main(String args[]) {
// create an array list
ArrayList al = new ArrayList();
// add elements to the array list
al.add("C");
al.add("A");
al.add("E");
al.add("B");
al.add("D");
al.add("F");
// use iterator to display contents of al
System.out.print("Original contents of al: ");
Iterator itr = al.iterator();
while(itr.hasNext()) {
}
System.out.println();
// modify objects being iterated
ListIterator litr = al.listIterator();
while(litr.hasNext()) {
}
System.out.print("Modified contents of al: ");
itr = al.iterator();
while(itr.hasNext()) {
}
System.out.println();
// now, display the list backwards
System.out.print("Modified list backwards: ");
while(litr.hasPrevious()) {
}
System.out.println();
}
}
The iterators returned by this class's iterator and listIterator methods are fail-fast: if
the list is structurally modified at any time after the iterator is created, in any way
except through the Iterator's ownremove or add methods, the iterator will throw
a ConcurrentModificationException. Thus, in the face of concurrent modification, the
iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic
behavior at an undetermined time in the future.
JSTL:
<c:if test=”{}”>
</c:if> does not contain a else tag.
So in such situation <c:choose> should be used.
<c:choose>
<c:when test=”{}”>
</c:when>
<c:otherwise>
</c:otherwise>
<c:choose>
Generics:
CopyOnWriteArrayList
When the iterator is first created it refers state of the arraylist which never changes
during the life time of the iterator.
Hence the iterator will not reflect any change like addition, deletion to the underlying
arraylist since the iteratore is created.
Class.forName() returns the Class object associated with the class or interface with
the given string name.
With expressions in JSP the results of evaluating the expression are converted to a string and
directly included within the output page. Typically expressions are used to display simple
values of variables or return values by invoking a bean's getter methods. JSP expressions begin
within < = ... > tags and do not include semicolons:
But scriptlet can contain any number of language statements variable or method declarations
or expressions that are valid in the page scripting language. Within scriptlet tags you can
declare variables or methods to use later in the file write expressions valid in the page
scripting language use any of the JSP implicit objects or any object declared with a .
Scopes of Attributes:
${pageScope.objectName.attributeName}.
${requestScope.objectName.attributeName}.
Expression Language:
We can declare error page for a specific exception type and error code in Deployment Descriptor.
<init-param>
<param-name>config</param-name>
<param-value>WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/mod1</param-name>
<param-value>WEB-INF/mod1-config.xml</param-value>
</init-param>
Switch Action:
A standard Action that switches to a new module and then forwards control to a URI
(specified in a number of possible ways) within the new module.
EJB:
Enterprise java beans are server side software components that can be deployed in a
distributed multitier environment.
EJB server provides the following services like concurrency, security, transaction
management, persistence etc.
When a client invokes a method to a bean the server steps into the middle of each
method call and provide these services.
Message Driven Beans are like session beans and they can be called by sending
messages to them.
An EJB object is a request interceptor between a client and the bean. It delegates all
client requests to the bean.
EJB Home instantiates EJB objects and client code gets the reference from the home
object.
Statefull session bean: retains client state and thus service multiple request of the
same client.
On calling create () method remote EJB Object will be created but when client will
invoke a business method then only bean will come out of pool and will server the
method. So a stateless bean instance can serve for several business methods call in
its life, without knowing for which client.
Initially a bean is in does not exist state. When container decides that a bean
instance is needed in the pool to service client request then container creates bean
instance by calling the following methods:
Now the bean instance is in method ready state to service client request. Container
calls the ejbRemove() method if it decides that pool does not require so many beans.
Lifecycle of Statefull session bean:
Initially a Statefull bean is in doesn’t exists state. When client calls create method on
the home interface a bean instance is created and is ready to service the client
request. Client calls business method on the bean. If the client is not active then the
bean goes to passivated state and is again activated on clients method call.
The bean is destroyed when client calls remove method on the bean instance.
Asynchronous means client sends a request to the remote server and continues
doing other work.
Two or more client can communicate with each other asynchronously by using JMS
API.
Entity Bean:
The existing entity bean can be find out by calling finder method that starts with
ejbFind().
You must have one finder method called ejbFindByPrimaryKey. This method finds
one unique entity bean instance in the database.
EJB transactions:
TRUNCATE is a DDL command and cannot be rolled back. All of the memory space is
released back to the server.
DELETE is a DML command and can be rolled back.
Java Reflection:
It helps to find what data fields and methods are used in the class.
ThreadLocal:
This class provides thread-local variables. These variables differ from their normal
counterparts in that each thread that accesses one (via its get or set method) has its
own, independently initialized copy of the variable. ThreadLocal instances are
typically private static fields in classes that wish to associate state with a thread
(e.g., a user ID or Transaction ID).
For example, in the class below, the private static ThreadLocal instance (serialNum)
maintains a "serial number" for each thread that invokes the class's
static SerialNum.get() method, which returns the current thread's serial number. (A
thread's serial number is assigned the first time it invokes SerialNum.get(), and
remains unchanged on subsequent calls.)
interface Ball {
void hit();
}
}
Garbage collection is an automatic memory management in Java. With the help of this
methodology JVM destroys all the objects which are no longer in used and allocate
memory space.
The finalize method is used to close all the non java resources before the object is
garbage collected.
Immutable Class:
Declare the class final; declare the variable private final, only getter method.
JVM is the java byte code interpreter and JRE does not include any development
environment. JRE includes JVM.
Wrapper Class:
HashCode:
If the String class did not implement its own version of the equals method
comparing two Strings would compare the memory address rather than the
character sequence. This is rarely what you would want, and for this reason the
String class implements it's own version of the equals method that makes a
character by character comparison.
Objects that are equal according to the equals method must return the same
hashCode value
If two objects are not equal according to equals, they are not required to
return different hashCode values.
The String class has its own implementation of the hashCode method. If it did not it
would have inherited the hashCode method from Object which simply returns the
memory address of the class instance.
Be careful of any quesiton that uses the word always. The default inmplementation
of hashCode for the Object class is to return the memory address of the object. A
little knowledge of how Java works will tell you that there is no guarantee that an
object will have the same memory address from one execution to another. A
hashCode method must return the same value during the same run of a program but
not necessarily from one program run to another. If you do a test on the hashCode
of an instance of object you may find it seems to return the same memory address
during multiple program runs, but there is no guarantee of this.
Singleton Class:
sintoninstce=new Singleton();
}
But this is not thread safe and we need to make the accessor method synchronized
for thread safe.
For early initialization always create the instance of the singleton class when it loads.
The accessor method will return the instance.
Hashing:
The answer is that the array will not hold the keys. From the key object, a number will be derived
that will index into the array. This number is the hash code, produced by the hashCode( ) method
(in computer science parlance, this is the hash function) defined in Object and presumably
overridden by your class. To solve the problem of the fixed-size array, more than one key may
produce the same index. That is, there may be collisions. Because of this, it doesn’t matter how
big the array is because each key object will land somewhere in that array. So the process of
looking up a value starts by computing the hash code and using it to index into the array. If you
could guarantee that there were no collisions (which could be possible if you have a fixed number
of values) then you’d have a perfect hashing function, but that’s a special case. In all other cases,
collisions are handled by external chaining: the array points not directly to a value, but instead to
a list of values. These values are searched in a linear fashion using the equals( ) method. Of
course, this aspect of the search is much slower, but if the hash function is good there will only be
a few values in each slot, at the most. So instead of searching through the entire list, you quickly
jump to a slot where you have to compare a few entries to find the value. This is much faster,
which is why the HashMap is so quick.
Runtime.getRuntime().gc();
when creating your own classes to add to a HashSet remember to override hashCode().
The TreeSet implementation is useful when you need to extract elements from a collection in
a sorted manner. In order to work property, elements added to a TreeSet must be sortable.
The Collections Framework adds support for Comparable elements and will be covered in
detail later. For now, just assume a tree knows how to keep elements of
the java.lang wrapper classes sorted. It is generally faster to add elements to a HashSet,
then convert the collection to a TreeSet for sorted traversal.
Use of TreeSet:
We can create a collection of duplicate objects. But if we put add them to a HashSet, there will
not be any duplicate object.
But if we create a TreeSet with the hashset then the objects will be automatically sorted by
natural order.
If the objects are of a class defined by us then we have to override the hashcode method and
then implement the comparable interface to sort them using hashset.
import java.util.*;
For retrieving an object by name hashmap is best solution. It is not synchronized like
hashtable and hence performace is better. For treemap the elements must be sortable.
For inserting, deleting, and locating elements in a Map, the HashMap offers the best alternative.
Data Manipulation Language (DML) statements are used for managing data within schema
objects.
iBATIS:
<sqlMapConfig>
<settings useStatementNamespaces="true"/>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL"
value="jdbc:mysql://192.168.10.112:3306/vin"/>
<property name="JDBC.Username" value="root"/>
<property name="JDBC.Password" value="root"/>
</dataSource>
</transactionManager>
<sqlMap resource="Contact.xml"/>
</sqlMapConfig>
<sqlMap namespace="Contact">
<!--- Inserting data in table -->
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import java.io.*;
import java.sql.SQLException;
import java.util.*;
<sqlMap namespace="Contact">
<!--- Delete data from Contact table -->
<delete id="deleteAll" parameterClass="Contact">
delete from Contact
</delete>
<!--- Showing all data of table -->
<select id="getAll" resultClass="Contact">
select * from contact
</select>
</sqlMap>
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import java.io.*;
import java.sql.SQLException;
import java.util.*;
<sqlMap namespace="Contact">
<!--- Showing all data of table -->
<select id="getAll" resultClass="Contact">
select * from contact
</select>
<!--- Update data of Contact table -->
<update id="updateById" parameterClass="long">
update Contact
set
lastName = 'Raghuwanshi'
where
id=#id#
</update>
</sqlMap>
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import java.io.*;
import java.sql.SQLException;
import java.util.*;
<sqlMap namespace="Contact">
<!--- Showing data by ID -->
<resultMap id="result" class="Contact">
<result property="id" column="id"/>
<result property="firstName" column="firstName"/>
<result property="lastName" column="lastName"/>
<result property="email" column="email"/>
</resultMap>
<select id="getById" resultMap="result">
select * from contact where id=#id#
</select>
</sqlMap>
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import java.io.*;
import java.sql.SQLException;
import java.util.*;
(Contact)sqlMap.queryForObject("Contact.getById",new
Integer(1));
System.out.println("|Id = " + contact.ge
tId());
System.out.println("|First Name = " + contact.ge
tFirstName());
System.out.println("|Last Name = " + contact.ge
tLastName());
System.out.println("|Email Id = " + contact.ge
tEmail());
System.out.println("=============================
=============");
}
}
If there is frequent update in the table rows then indexing is not a good choice to
optimize query performance.
What is an Index?
An index is a performance-tuning method of allowing faster retrieval of records. An index creates an entry
for each value that appears in the indexed columns. By default, Oracle creates B-tree indexes.
Timestamp includes fractional seconds also whether in DATE difference between fractional events is difficult
to calculate.
T0_Char function is used to format dates in Oracle.
Blob – used to store 4GB of binary data
Clob – used to store 4GB of character data.
A cursor is a mechanism by which you can assign a name to a "select statement" and manipulate the
information within that SQL statement.
For every SQL statement execution certain area in memory is allocated. PL/SQL
allow you to name this area. This private SQL area is called context area or cursor. A
cursor acts as a handle or pointer into the context area. A PL/SQL program controls
the context area using the cursor. Cursor represents a structure in memory and is
different from cursor variable.
When you declare a cursor, you get a pointer variable, which does not point any
thing. When the cursor is opened, memory is allocated and the cursor structure is
created. The cursor variable now points the cursor. When the cursor is closed the
memory allocated for the cursor is released.
CURSOR c1
IS
SELECT course_number
from courses_tbl
where course_name = name_in;
The result set of this cursor is all course_numbers whose course_name matches the variable called
name_in.
While dealing with cursors, you may need to determine the status of your cursor. The following is a list of the
cursor attributes that you can use.
Attribute Explanation
%ISOPEN - Returns TRUE if the cursor is open, FALSE if the cursor is closed.
%FOUND - Returns INVALID_CURSOR if cursor is declared, but not open; or if cursor has been closed.
- Returns NULL if cursor is open, but fetch has not been executed.
%NOTFOUND - Returns INVALID_CURSOR if cursor is declared, but not open; or if cursor has been closed.
- Return NULL if cursor is open, but fetch has not been executed.
%ROWCOUNT - Returns INVALID_CURSOR if cursor is declared, but not open; or if cursor has been closed.
- The ROWCOUNT attribute doesn't give the real row count until you have iterated through the entire
cursor. In other words, you shouldn't rely on this attribute to tell you how many rows are in a cursor after
it is opened.
http://www.exforsys.com/tutorials/oracle-9i/oracle-cursors.html
In general, indexes are used as described in the following discussion. Characteristics specific
to hash indexes (as used in MEMORY tables) are described at the end of this section.
Dependency Injection:
Scope
This article presents a high level overview of Dependency Injection (DI). It aims to present the
overall concept of Dependency Injection to the junior developer within the context of how it could
be used in a variety of DI containers.
A lot of current literature often refers to the same design pattern as either Dependency Injection
or Inversion of Control. I prefer Dependency Injection from my belief that it is a more specific
name. I can imagine many scenarios where one would find evidence of Inversion of Control,
though the resultant pattern is unlikely to be focusing on resolving dependencies (e.g. moving
from a console application to a Windows Event Loop) . However should you prefer IOC, you can
pretty much read the remainder of the article by replacing DI with IOC. Within IOC there are
various types (creatively called as type 1, type 2, type 3). The differences within these types are
not particularly relevant to the scope of this article and thus not entered into.
Also note that I have used the term Service extensively through this article. This should not be
confused with Service Oriented Architectures. It simply became a lot easier to clarify the roles by
identifying “Clients” and “Services” as opposed to “Client Component” and “Server Component or
Supplier Component”
Thus your typical travel planning routine might look like the following :
Now if your company suddenly changed the preferred agencies and their contact mechanisms,
you would be subject to the following relearning scenarios
• The new agencies, and their new contact mechanisms (say the new agencies offer
internet based services and the way to do the bookings is over the internet instead of over
the phone)
• The typical conversational sequence through which the necessary bookings get done
(Data instead of voice).
Its not just you, but probably many of your colleagues would need to adjust themselves to the
new scenario. This could lead to a substantial amount of time getting spent in the readjustment
process.
Scenario 2
Now lets say the protocol is a little bit different. You have an administration department.
Whenever you needed to travel an administration department interactive telephony system simply
calls you up (which in turn is hooked up to the agencies). Over the phone you simply state the
destination, desired arrival date and time by responding to a programmed set of questions. The
flight reservations are made for you, the cab gets scheduled for the appropriate time, and the
tickets get delivered to you.
Now if the preferred agencies were changed, the administration department would become aware
of a change, would perhaps readjust its workflow to be able to communicate with the agencies.
The interactive telephony system could be reprogrammed to communicate with the agencies over
the internet. However you and your colleagues would have no relearning required. You still
continue to follow exactly the same protocol as earlier (since the administration department did all
the necessary adaptation in a manner that you do not need to do anything differently).
Dependency Injection ?
In both the scenarios, you are the client and you are dependent upon the services provided by
the agencies. However Scenario 2 has a few differences.
• You don't need to know the contact numbers / contact points of the agencies – the
administration department calls you when necessary.
• You don't need to know the exact conversational sequence by which they conduct their
activities (Voice / Data etc.) (though you are aware of a particular standardized
conversational sequence with the administration department)
• The services you are dependent upon are provided to you in a manner that you do not
need to readjust should the service providers change.
Thats dependency injection in “real life”. This may not seem like a lot since you imagine a cost to
yourself as a single person – but if you imagine a large organization the savings are likely to be
substantial.
Software components (Clients), are often a part of a set of collaborating components which
depend upon other components (Services) to successfully complete their intended purpose. In
many scenarios, they need to know “which” components to communicate with, “where” to locate
them, and “how” to communicate with them. When the way such services can be accessed is
changed, such changes can potentially require the source of lot of clients to be changed.
One way of structuring the code is to let the clients embed the logic of locating and/or
instantiating the services as a part of their usual logic. Another way to structure the code is to
have the clients declare their dependency on services, and have some "external" piece of code
assume the responsibility of locating and/or instantiating the services and simply supplying the
relevant service references to the clients when needed. In the latter method, client code typically
is not required to be changed when the way to locate an external dependency changes. This type
of implementation is considered to be an implementation of Dependency Injection and the
"external" piece of code referred to earlier is likely to be either hand coded or implemented using
one of a variety of DI frameworks.
Those attempting to map the above scenario to design idioms will notice that the analogy could
be applied to three different design idioms – Dependency Injection, Factory and Program to an
Interface and not an Implementation. As in this analogy these three idioms are often but not
necessarily used together.
The conventional approach till a few years ago was to separate the interface from the
implementation. The factory pattern even allowed for hiding the complexity of instantiation.
However the mechanism to “locate” the services was often left to the clients. Moreover some
parts of the software also needed to be aware of the dependencies between the various services
themselves and thus implicitly had to work out the appropriate sequencing of such component
initialization, and had to track and manage their life cycles.
### Dependency injection is basically giving an object what it needs instead of letting this object
get it by itself.
By applying Dependency Injection in your projects, you’ll find that your code will become
significantly simpler, easier to understand, and easier to test.
When applying Dependency injection(DI), objects are given their dependencies at creation time
by some external entity that coordinates each object in the system. In other words, dependencies
are injected into objects. So, DI means an inversion of responsibility with regard to how an object
obtains references to collaborating objects.
http://www.vogella.de/articles/SpringDependencyInjection/article.html#usagexml
Abstraction:
Encapsulation:
Hiding the data within the class and make them available only through method.
Inheritance:
In inheritance the subclass inherit the fields and methods of the super class. Inheritance helps
us to reuse our code.
String is immutable:
Once a string is created it can not be changed. The reference variable can be made to point to
a different string object. But the original string remains same and if no reference is there then
goes to string constant pool.
Str1=str2;
Here str1 and str2 both are referencing the String “Dhruba” but “Hello” string will still be there
and goes to string constant pool.
It can have constructor but it can not be instantiated. The subclass calls the constructor of the
abstract class.
JDBC statements:
To execute a query, call an execute method from Statement such as the following:
execute: Returns true if the first object that the query returns is a ResultSet object. Use this
method if the query could return one or more ResultSet objects. Retrieve
the ResultSet objects returned from the query by repeatedly calling Statement.getResutSet.
Use this for DDL (create, drop, rename which are used to define database structure)
executeQuery: Returns one ResultSet object. Use when you expect a resultset object from
the query.
executeUpdate: Returns an integer representing the number of rows affected by the SQL
statement. Use this method if you are using INSERT,DELETE, or UPDATE SQL statements.
SQL JOINS:
Outer join:
Select Supplier.supplier_id, Supplier.supplier_name, Orders.order_date from Supplier, Orders
where Supplier.supplier_id(+)=Orders.supplier_id