|Sunday, November 27th, 2011|
What's the difference between passive and script-based templates?
The idea of script-based templates is to take a single model node and transform it to the desired output. As much template code plus much logic leeds to a hard to maintain monster people are looking for ways to reduce the logic code within the template.
Solution strategies on script based templating solutions
- Reducing language abilities
Nowadays most template languages in java disallow arbitrary method calls. The idea is keep web developers from adding business logic to the template and thus reducing template size over all. However, there's some typical view or data binding logic, which in turn can't be realized within the template. As the model is the only way of communication with the template, this is typically solved by an additional model, where all the data has to be copied into.
- Provide a controlled way to embed (business) logic
Like JSP Tags. Complex configuration and API are intended to prevent from getting to much tags.
- Complex template handling with inheritance
- Additional frameworks like Tiles or SiteMesh
Solving with passive templates
Passive templates in turn provide this view model by default. Data is simply copied into the view. There are solutions like Snippetory
combining this with a strong abstraction layer. All logic is implemented in java. Editing, debugging, testing. All works fine with the tool one is used to.
|Sunday, August 3rd, 2008|
What are the steps in the JDBC connection?
Steps are :
1. Load or register the driver with Class.forName().
2. Establish Connection with the database with Connection Interface.
3. Create Statement objects for Queries.
4. Execute the statements which may or may not return ResultSet.
5. Manipulate the ResultSet.
6. Close the Statements and Connection objects.
What is JDBC?
What is JDBC?
JDBC is Java application programming interface that allows the Java programmers to access database management system from Java code.
Understanding JDBC Architecture
JDBC is a core part of the Java platform and is included in the standard JDK distribution.
JDBC Driver and Its Types
There are four types of JDBC drivers.
|Tuesday, July 29th, 2008|
difference between the Boolean & operator and the && operator
If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand.
When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.
difference between preemptive scheduling and time slicing
Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.
difference between checked and Unchecked Exceptions in Java
Unchecked exceptions are any class of exception that extends the RuntimeException class at some point in its inheritance hierarchy. This includes the most common exceptions. An ArithmeticException occurs when a program tries to divide by zero. A NullPointerException occurs when you try and access an instance data member or method of a reference variable that does not yet reference an object.
Unchecked exceptions can occur anywhere in a program and in a typical program can be very numerous. Therefore, the cost of checking these exceptions can be greater than the benefit of handling them. Thus, Java compilers do not require that you declare or catch unchecked exceptions in your program code. Unchecked exceptions may be handled as explained for checked exceptions in the following section.
All Exceptions that extend the RuntimeException class are unchecked exceptions.
Checked exceptions are exceptions that do not extend the RuntimeException class. Checked exceptions must be handled by the programmer to avoid a compile-time error. One example of a checked exception is the IOException that may occur when the readLine method is called on a BufferedReader object. Read more about the readLine method in the section on console input in the Java I/O page. All other exceptions you may have experienced were examples of unchecked exceptions.
There are two ways to handle checked exceptions. You may declare the exception using a throws clause or you may catch the exception. To declare an exception, you add the keyword throws followed by the class name of the exception to the method header. See example below. Any method that calls a method that throws a checked exception must also handle the checked exception in one of these two ways.
How are Observer and Observable used?
Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.
|Monday, July 28th, 2008|
What are different types of inner classes ?
Inner classes nest within other classes. A normal class is a direct member of a package. Inner classes, which became available with Java 1.1, are four types
Static member classes
What is synchronized keyword?
Synchronization is the act of serializing access to critical sections of code. We will use this keyword when we expect multiple threads to access/modify the same data. To understand synchronization we need to look into thread execution manner.
Threads may execute in a manner where their paths of execution are completely independent of each other. Neither thread depends upon the other for assistance. For example, one thread might execute a print job, while a second thread repaints a window. And then there are threads that require synchronization, the act of serializing access to critical sections of code, at various moments during their executions. For example, say that two threads need to send data packets over a single network connection. Each thread must be able to send its entire data packet before the other thread starts sending its data packet; otherwise, the data is scrambled. This scenario requires each thread to synchronize its access to the code that does the actual data-packet sending.
If you feel a method is very critical for business that needs to be executed by only one thread at a time (to prevent data loss or corruption), then we need to use synchronized keyword.
Synchronized block is faster than synchronized method.
How can I tell what state a thread is in ?
Prior to Java 5, isAlive() was commonly used to test a threads state. If isAlive() returned false the thread was either new or terminated but there was simply no way to differentiate between the two.
Starting with the release of Tiger (Java 5) you can now get what state a thread is in by using the getState() method which returns an Enum of Thread.States. A thread can only be in one of the following states at a given point in time.
A Fresh thread that has not yet started to execute.
A thread that is executing in the Java virtual machine.
A thread that is blocked waiting for a monitor lock.
A thread that is wating to be notified by another thread.
A thread that is wating to be notified by another thread for a specific amount of time
A thread whos run method has ended.
difference between the boolean & operator and the && operator?
What is the difference between the boolean & operator and the && operator?
If an expression involving the boolean & operator is evaluated, both operands are evaluated, whereas the && operator is a short cut operator. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. If the first operand evaluates to false, the evaluation of the second operand is skipped.
What is a static method?
A static variable is associated with the class as a whole rather than with specific instances of a class. Each object will share a common copy of the static variables i.e. there is only one copy per class, no matter how many objects are created from it. Class variables or static variables are declared with the static keyword in a class. These are declared outside a class and stored in static memory. Class variables are mostly used for constants. Static variables are always called by the class name. This variable is created when the program starts and gets destroyed when the programs stops. The scope of the class variable is same an instance variable. Its initial value is same as instance variable and gets a default value when its not initialized corresponding to the data type. Similarly, a static method is a method that belongs to the class rather than any object of the class and doesn't apply to an object or even require that any objects of the class have been instantiated.
Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can't override a static method with a non-static method. In other words, you can't change a static method into an instance method in a subclass.
Non-static variables take on unique values with each object instance.
What are different types of access modifiers?
Access specifiers are keywords that determine the type of access to the member of a class. These keywords are for allowing
privileges to parts of a program such as functions and variables. These are:
• Public : accessible to all classes
• Protected : accessible to the classes within the same package and any subclasses.
• Private : accessible only to the class to which they belong
• Default : accessible to the class to which they belong and to subclasses within the same package
Polymorphism in simple terms means one name many forms. Polymorphism enables one entity to be used as a general category for different types of actions. The specific action is determined by the exact nature of the situation.
Polymorphism exists in three distinct forms in Java:
• Method overloading
• Method overriding through inheritance
• Method overriding through the Java interface
What is the difference between a while statement and a do statement?
A while statement (pre test) checks at the beginning of a loop to see whether the next loop iteration should occur.
A do while statement (post test) checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the loop body at least once.
What is the difference between final, finally and finalize?
o final - declare constant
o finally - handles exception
o finalize - helps in garbage collection
Variables defined in an interface are implicitly final.
A final class can't be extended i.e., final class may not be subclassed. This is done for security reasons with basic classes like String and Integer. It also allows the compiler to make some optimizations, and makes thread safety a little easier to achieve.
A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant).
finalize() method is used just before an object is destroyed and garbage collected.
finally, a key word used in exception handling and will be executed whether or not an exception is thrown. For example, closing of open connections is done in the finally method.
What are the differences between == and .equals() ?
The == operator compares two objects to determine if they are the same object in memory i.e. present in the same memory location. It is possible for two String objects to have the same value, but located in different areas of memory.
== compares references while .equals compares contents.
difference between an Abstract class and Interface in Java
Question: What is the difference between an Abstract class and Interface in Java ? or can you explain when you use Abstract classes ?
Answer: Abstract classes let you define some behaviors; they force your subclasses to provide others. These abstract classes will provide the basic funcationality of your applicatoin, child class which inherited this class will provide the funtionality of the abstract methods in abstract class. When base class calls this method, Java calls the method defined by the child class.
An Interface can only declare constants and instance methods, but cannot implement default behavior.
Interfaces provide a form of multiple inheritance. A class can extend only one other class.
Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc.
A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class.
Interfaces are slow as it requires extra indirection to find corresponding method in the actual class. Abstract classes are fast.
computers, networks, Internet and software
Though my personal journal is mostly for my hystorical, literature and cultural interest, the modern world is about computers, networks, Internet and Java. So here would be a place for Java interview questons at first, then we will see...
You could use both English and Russian language here, no strict rules here.