0% found this document useful (0 votes)
5 views2 pages

Java Transaction Management and SQL Basics

The document discusses various programming concepts including bean-managed transactions, SQL HAVING clause, stored procedures vs functions, JSP tags, and Java exceptions. It also covers Java collections, thread safety, immutability, cloning, and the nature of Java as a programming language. Additionally, it touches on the instantiation of abstract classes and the behavior of null pointers in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Java Transaction Management and SQL Basics

The document discusses various programming concepts including bean-managed transactions, SQL HAVING clause, stored procedures vs functions, JSP tags, and Java exceptions. It also covers Java collections, thread safety, immutability, cloning, and the nature of Java as a programming language. Additionally, it touches on the instantiation of abstract classes and the behavior of null pointers in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

In a bean-managed transaction, the code in the session or message-driven bean

explicitly marks the boundaries of the transaction

Inline thread: (new Thread() {


public void run() {
// do stuff
}
}).start()

The HAVING clause was added to SQL because the WHERE keyword could not be used with
aggregate functions

<sql-query name = "empdetails">


<return alias="emp" class="[Link]"/>
SELECT emp.EMP_ID AS {[Link]},
emp.EMP_ADDRESS AS {[Link]},
emp.EMP_NAME AS {[Link]}
FROM Employee EMP WHERE [Link] LIKE :name
</sql-query>
Invoke Named Query :
List people = [Link]("empdetails")
.setString("Deepak", name)
.setMaxResults(50)
.list();

storedproc functions
can return more than 1 value can return only 1 value
can have i/o params can have only input params
allows DML statement allows only select statement
proc cannot be called from functions functions can be called from proc

jsp tags
Core Tags
Formatting tags
SQL tags
XML tags
JSTL Functions

public class YourController extends SimpleFormController{


//...
public CustomerController(){
setCommandClass([Link]);
setCommandName("customerForm");
}
setCommandClass([Link]) � Form�s values will store into this Customer
object.
setCommandName(�customerForm�) � If HTML form action value with named
�customerForm� is submitted, Spring will forward request to this form controller.

null pointer exception is in category of unchecked exceptions because


instance are not available at compile time so how complier checks whether object is
null or instantiated, so it is
treated as unchecked exception.

The reason why java collections have both interfaces and classes is interface will
have common methods which will be needed by one or many classes

Why wait and notify method should be called in loop? (to prevent doing task, if
condition is not true and thread is awake due to false alarms, checking conditions
in loop ensures that processing is only done when business logic allows)

Singelton is a class level implementation that means two different class loaders
could load two different instances of singleton and at a time there could be more
then one instances in JVM

Making an object as Immutable, it becomes automatically thread safe

Null keys could be used for storing a default value. For example, where a systems
retrieves data depending on some input, but when the input is not provided (null),
some default value is returned.

The biggest advantage of clone() is that it creates a new object with state which
is exactly same as the original object

int[] arr = { 11, 5, 17, 19, 18 };


int n = 3;
int maxn = 20;

for (int i = 0; i < n; i++) {


int min = -20;
for (int j = 0; j < [Link]; j++) {
if (arr[j] > min && arr[j] < maxn) {
min = arr[j];
}
}
maxn = min;
}
[Link](n+"th maximum number "+maxn);

java is not pure programming language because it use primitive data types like int,
float..

When a subclass of Abstract class is instantiated then Constructor of Abstract


class is invoked. So Abstract class should have a constructor.

Common questions

Powered by AI

The singleton pattern in Java ensures that a class has only one instance and provides a global point of access to it. This is achieved by making its constructor private, and providing a static method that returns the single instance, often employing lazy initialization. However, this pattern presents pitfalls such as concurrent access issues, where multiple threads may simultaneously create multiple instances if not synchronized correctly. Additionally, singletons can create hidden dependencies and hinder unit testing due to global state alteration. Developers should use techniques such as double-checked locking or initialization-on-demand holder idiom to circumvent threading issues .

The HAVING clause is used in SQL to filter records that work on aggregated data. It is used in combination with the GROUP BY clause to restrict the groups of returned rows to those groups for which the specified condition is TRUE. The main difference between HAVING and WHERE clauses is that HAVING is used to check conditions after the aggregation takes place, whereas WHERE is used to filter records before any groupings and aggregation are performed. This means WHERE cannot be used with aggregate functions, which necessitates the use of HAVING in such situations .

Making an object immutable in Java plays a vital role in ensuring thread safety because immutable objects are inherently thread-safe since their state cannot change once they are constructed. This means multiple threads can access these objects concurrently without synchronization, which reduces complexity and potential for errors in concurrent applications. For instance, using immutable objects can prevent issues such as race conditions, which are common when mutable objects are modified by multiple threads simultaneously. Consequently, immutability is a fundamental aspect in designing safe and efficient concurrent applications .

Classes in Java are instantiated to create objects, and they can include fields, methods, and constructors, which is how they can instantiate objects. Interfaces, however, cannot be instantiated but must be implemented by a class to be utilized. The purpose of interfaces is to specify methods that a class must implement, providing a form of abstraction and multiple inheritance of methods, which allows for more flexible and decoupled design. A common design pattern is to use interfaces to define behavior expectations, while classes provide specific implementations, allowing polymorphic behavior without compromising encapsulation .

Core and formatting tags in JSTL (JavaServer Pages Standard Tag Library) simplify JSP development by providing easy-to-use functionalities that eliminate the need for scriptlets. Core tags are used for tasks like iteration and conditionals, while formatting tags help format numbers and dates for internationalization. These tags enhance code readability, maintainability, and separate the presentation from the business logic, which aligns with the MVC pattern. For example, the use of conditional tags for decision-making and looping tags for iterating over data collections can significantly reduce Java syntax, leading to cleaner and more maintainable code .

The wait and notify methods should be called within a loop in Java to handle potential spurious wakeups. A loop allows the code to continually check the condition associated with the wait. This prevents the thread from incorrectly proceeding if it is awakened due to a spurious wakeup or if the condition for proceeding is not actually met. Without this loop, the program could experience erroneous behavior or deadlocks by proceeding under false conditions, since the business logic might not permit the continuation .

Using the clone() method in Java allows for creating a new object that has the same state as an existing object without calling the constructor, hence it bypasses the usual initialization process. The clone method differs from regular object creation as it is primarily meant to duplicate existing objects' state, which makes it useful when deep copying complex objects. However, the drawbacks include the need to implement the Clonable interface and the potential for shallow copies (default behavior) that can lead to issues if mutable fields exist within the object. Therefore, developers must override the clone method properly to ensure deep copying if required .

Stored procedures in SQL can offer performance advantages by reducing network traffic and reusing execution plans, as they allow complex operations and can return multiple values. They also support input/output parameters and can include DML statements such as INSERT, UPDATE, and DELETE. Functions, on the other hand, are restricted to SELECT statements and often serve to encapsulate reusable logic or calculations. While functions can be called from stored procedures, the reverse is not possible. However, the choice between the two often depends on application requirements: procedures are better for extensive batch processing, whereas functions are best for computations and condition checks .

Bean-managed transactions in Java allow developers to explicitly manage the transaction boundaries within session or message-driven beans. This approach provides flexibility because it gives the developer precise control over transaction management, unlike container-managed transactions where the container automatically handles transaction demarcation. This means developers can tailor transaction behavior to the specific needs of an application by starting, committing, or rolling back transactions manually in the code .

A null pointer exception in Java is an error that occurs when a program attempts to use an object reference that has not been assigned any object. This could happen when trying to call a method on an object that is actually null. It is categorized as an unchecked exception because it can occur at runtime and is not checked by the compiler at compile time. This is due to the fact that the existence of a null value is only known during the execution of the program, not during its compilation .

You might also like