Saturday, January 3, 2009

JSF Interview Questions - 1

1)What is JavaServer Faces?
JavaServer Faces (JSF) is a user interface (UI) framework for Java web applications. It is designed to significantly ease the burden of writing and maintaining applications that run on a Java application server and render their UIs back to a target client. JSF provides ease-of-use in the following ways:
Makes it easy to construct a UI from a set of reusable UI components
Simplifies migration of application data to and from the UI
Helps manage UI state across server requests
Provides a simple model for wiring client-generated events to server-side application code
Allows custom UI components to be easily built and re-used

Most importantly, JSF establishes standards which are designed to be leveraged by tools to provide a developer experience which is accessible to a wide variety of developer types, ranging from corporate developers to systems programmers. A "corporate developer" is characterized as an individual who is proficient in writing procedural code and business logic, but is not necessarily skilled in object-oriented programming. A "systems programmer" understands object-oriented fundamentals, including abstraction and designing for re-use. A corporate developer typically relies on tools for development, while a system programmer may define his or her tool as a text editor for writing code. Therefore, JSF is designed to be tooled, but also exposes the framework and programming model as APIs so that it can be used outside of tools, as is sometimes required by systems programmers.
2)How to pass a parameter to the JSF application using the URL string?
if you have the following URL: http://your_server/your_app/product.jsf?id=777, you access the passing parameter id with the following lines of java code:
FacesContext fc = FacesContext.getCurrentInstance();
String id = (String) fc.getExternalContext().getRequestParameterMap().get("id");
From the page, you can access the same parameter using the predefined variable with name param. For example,

Note: You have to call the jsf page directly and using the servlet mapping.

3)How to add context path to URL for outputLink?
Current JSF implementation does not add the context path for outputLink if the defined path starts with '/'. To correct this problem use #{facesContext.externalContext.requestContextPath} prefix at the beginning of the outputLink value attribute. For example:

4)How to get current page URL from backing bean?
You can get a reference to the HTTP request object via FacesContext like this:
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest(); and then use the normal request methods to obtain path information. Alternatively,
context.getViewRoot().getViewId();
will return you the name of the current JSP (JSF view IDs are basically just JSP path names).

5)How to access web.xml init parameters from java code?
You can get it using externalContext getInitParameter method. For example, if you have: connectionString jdbc:oracle:thin:scott/tiger@cartman:1521:O901DB
You can access this connection string with:
FacesContext fc = FacesContext.getCurrentInstance();
String connection = fc.getExternalContext().getInitParameter("connectionString");

6)How to access web.xml init parameters from jsp page?
You can get it using initParam pre-defined JSF EL valiable.
For example, if you have: productId 2004Q4
You can access this parameter with #{initParam['productId']} . For example:
Product Id:



7)How to terminate the session?
In order to terminate the session you can use session invalidate method.
This is an example how to terminate the session from the action method of a backing bean:
Public String logout() {
FacesContext fc = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);
session.invalidate();
return "login_page";
}
The following code snippet allows to terminate the session from the jsp page:
<% session.invalidate(); %>

8)How to implement "Please, Wait..." page?
The client-side solution might be very simple. You can wrap the jsp page (or part of it you want to hide) into the DIV, then you can add one more DIV that appears when user clicks the submit button. This DIV can contain the animated gif you speak about or any other content.
Scenario: when user clicks the button, the JavaScript function is called. This function hides the page and shows the "Wait" DIV. You can customize the look-n-fill with CSS if you like.

10)How to download PDF file with JSF?
This is an code example how it can be done with action listener of the backing bean.
Add the following method to the backing bean:
public void viewPdf(ActionEvent event) {
String filename = "filename.pdf";
// use your own method that reads file to the byte array
byte[] pdf = getTheContentOfTheFile(filename);
FacesContext faces = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) faces.getExternalContext().getResponse();
response.setContentType("application/pdf");
response.setContentLength(pdf.length);
response.setHeader( "Content-disposition", "inline; filename=\""+fileName+"\"");
try {
ServletOutputStream out;
out = response.getOutputStream();
out.write(pdf);
} catch (IOException e) {
e.printStackTrace();
}
faces.responseComplete();
}
This is a jsp file snippet:


JNI Interview Questions & Answers

1)How to debug JNI code in CVM?
Porting Guide for the CDC and the Foundation Profile from SUN has a chapter on "C Debugging with GDB".

2)How can I check the status of a java Thread using JVMDI?
// ThreadTool.java class ThreadTool { public static final int THREAD_STATUS_UNKNOWN = -1; public static final int THREAD_STATUS_ZOMBIE = 0; ...

3)Is there a COM Bridge that lets Windows developers create native client applications that access Enterprise JavaBeansTM (EJBTM) components deployed on a J2EE App server?
Yes. Take a look at: JavaTM 2 Platform, Enterprise Edition Client Access Services (J2EETM CAS) COM Bridge 1.0 Early Access.

4)What is necessary to have an applet call a native method? DLL installation, code signing, specific security permissions needed.
After more tries I solved the problem. I used your posted response about such a thing for Netscape. But was difficult to use that answer because Netscape...

5)JDK 1.4 has introduced the concept of direct buffers. Where can I get more information and/or samples for manipulating direct buffers?
JNI has been enhanced in v 1.4 to reflect a new feature of the java.nio package: direct buffers. The contents of a direct buffer can, potentially, reside...

6)What are the basic techniques for debugging mixed java and C++ code?
Debugging integrated Java and C/C++ code illustrates the two basic approaches using JNI (call C/C++ code from java, embed jvm in C/C++ code) and ways to...
EJB-JNI-Legacy Integration (C++ API) we have existing System in C++.We want to use Existing in the intranet/internet. We are using JNI to use existing System. And then we are calling JNI Classes in...
EJBs are supposed to be portable between different app servers who comply with the Sun's specifications for compliant EJB containers. Because of this reason,

7)Anyone know of a way of marking a Java thread as being a demon if it was "created" through the JNI AttachCurrentThread call?
Through a new method called AttachCurrentThreadAsDaemon.

8)What is Signal Chaining mechanism that has been implemented in JDK 1.4?
Signal-chaining enables the Java Platform to better interoperate with native code that installs its own signal handlers. The facility works on both Solaris and Linux platforms.

The signal-chaining facility was introduced to remedy a problem with signal handling in previous versions of the Java Hotspot VM. Prior to version 1.4, the Java Hotspot VM would not allow application-installed signal handlers for certain signals including, for example, SIGBUS, SIGSEGV, SIGILL, etc, since those signal handlers could conflict with the signal handlers used internally by the Java Hotspot VM.
The signal-chaining facility offers:
A. Support for pre-installed signal handlers when the Hotspot VM is created.
B. Support for signal handler installation after the Hotspot VM is created, inside JNI code or from another native thread.

Pre-installed signal handlers (A) are supported by means of saving existing signal handlers, for signals that are used by the VM, when the VM is first created. Later, when any of these signals are raised and found not to be targeted at the Java Hotspot VM, the pre-installed handlers are invoked. In other words, pre-installed handlers are "chained" behind the VM handlers for these signals.

9)Is there a TCL-Java Bridge?
Yes, The Tcl/Java project currently has two packages, Jacl and Tcl Blend. Jacl, which stands for Java Command Language, is a Java implementation of Tcl..

PHP – Variables

If you have never had any programming, Algebra, or scripting experience, then the concept of variables might be a new concept to you. A detailed explanation of variables is beyond the scope of this tutorial, but we've included a refresher crash course to guide you.


A variable is a means of storing a value, such as text string "Hello World!" or the integer value 4. A variable can then be reused throughout your code, instead of having to type out the actual value over and over again. In PHP you define a variable with the following form:



$variable_name = Value;

If you forget that dollar sign at the beginning, it will not work. This is a common mistake for new PHP programmers!



Note: Also, variable names are case-sensitive, so use the exact same capitalization when using a variable. The variables $a_number and $A_number are different variables in PHP's eyes.




A Quick Variable Example




Say that we wanted to store the values that we talked about in the above paragraph. How would we go about doing this? We would first want to make a variable name and then set that equal to the value we want. See our example below for the correct way to do this.



PHP Code:









Note for programmers: PHP does not require variables to be declared before being initialized.


PHP Variable Naming Conventions



There are a few rules that you need to follow when choosing a name for your PHP variables.



PHP variables must start with a letter or underscore "_".

PHP variables may only be comprised of alpha-numeric characters and underscores. a-z, A-Z, 0-9, or _ .

Variables with more than one word should be separated with underscores. $my_variable

Variables with more than one word can also be distinguished with capitalization. $myVariable


PHP – Echo



As you saw in the previous lesson, the PHP command echo is a means of outputting text to the web browser. Throughout your PHP career you will be using the echo command more than any other. So let's give it a solid perusal!


Outputting a String



To output a string, like we have done in previous lessons, use PHP echo. You can place either a string variable or you can use quotes, like we do below, to create a string that the echo function will output.



PHP Code:

I love using PHP!";

?>



Display:



Hello!

I love using PHP!

In the above example we output "Hello!" without a hitch. The text we are outputting is being sent to the user in the form of a web page, so it is important that we use proper HTML syntax!



In our second echo statement we use echo to write a valid Header 5 HTML statement. To do this we simply put the
at the beginning of the string and closed it at the end of the string. Just because you're using PHP to make web pages does not mean you can forget about HTML syntax!


Careful When Echoing Quotes!



It is pretty cool that you can output HTML with PHP. However, you must be careful when using HTML code or any other string that includes quotes! Echo uses quotes to define the beginning and end of the string, so you must use one of the following tactics if your string contains quotations:


Don't use quotes inside your string

Escape your quotes that are within the string with a backslash. To escape a quote just place a backslash directly before the quotation mark, i.e. \"

Use single quotes (apostrophes) for quotes inside your string.

See our example below for the right and wrong use of echo:



PHP Code:

I love using PHP!
";



// OK because we escaped the quotes!

echo "
I love using PHP!
";



// OK because we used an apostrophe '

echo "
I love using PHP!
";

?>



If you want to output a string that includes quotations, either use an apostrophe ( ' ) or escape the quotations by placing a backslash in front of it ( \" ). The backslash will tell PHP that you want the quotation to be used within the string and NOT to be used to end echo's string.


Echoing Variables


Echoing variables is very easy. The PHP developers put in some extra work to make the common task of echoing all variables nearly foolproof! No quotations are required, even if the variable does not hold a string. Below is the correct format for echoing a variable.



PHP Code:





Display:

Hello Bob. My name is: 4a

Echoing Variables and Text Strings

You can also place variables inside of double-quoted strings (e.g. "string here and a $variable"). By putting a variable inside the quotes (" ") you are telling PHP that you want it to grab the string value of that variable and use it in the string. The example below shows an example of this cool feature.



PHP Code:

";

echo "Hi, I'm Bob. Who are you? $my_string
";

echo "Hi, I'm Bob. Who are you? $my_string Bobetta";

?>



Display:



Hello Bob. My name is: Bobetta

Hi, I'm Bob. Who are you? Hello Bob. My name is:

Hi, I'm Bob. Who are you? Hello Bob. My name is: Bobetta



By placing variables inside a string you can save yourself some time and make your code easier to read, though it does take some getting used to. Remember to use double-quotes, single-quotes will not grab the value of the string. Single-quotes will just output the variable name to the string, like )$my_string), rather than (Hello Bob. My name is: ).


PHP Echo - Not a Function




Echo is not a function, rather it is a language construct. When you use functions in PHP, they have a very particular form, which we will be going over later. For now, just know that echo is a special tool that you'll come to know and love!

Java Reporting Made Easy

Overview

ReportMill is the best Java application reporting tool available for dynamically generating reports and web pages from Java applications in formats such as PDF, HTML, Flash, Excel and more. ReportMill combines an easy-to-use page layout application and a powerful Java API in a single compact jar file, which is remarkably easy to integrate into your custom Java application.

Embedded Reporting

Running as Java code inside your application, ReportMill seamlessly harvests data directly from any Java dataset, whether EJBs, POJOs (Plain Old Java Objects), Java Collection classes, JDBC ResultSets or any combination of these. This is much more efficient than traditional reporting tools, which often require developers to repackage existing Java datasets as the original SQL query, then force a redundant refetch and some potentially risky inter-process communication.

This architecture also provides unique access to custom business logic found in the developer's object model, providing a significant savings by reusing this code instead of forcing a rewrite in proprietary template macro languages.

Powerful Design Application
ReportMill is the only reporting tool built on top of a comprehensive page layout application . This ensures that almost any page or report design can be accommodated and also makes template design more intuitive for anyone who has made a newsletter or "For Sale" sign in any of the popular page layout applications.

Downlaod The ReportMill

http://reportmill.com/product/


Simple API


Most developers need to call only three lines of ReportMill API. Since ReportMill harvests data from any Java dataset using reflection and common collections interfaces, there is no need to write any binding/feeder code, implement any interfaces or create any datasource objects.

Online Aptitude Tests

1) Which of the following countries has launched the solar observation satellite solar-B ?



1) Japan

2) China

3) Russia

4) USA



2) A Great way to fly is the media campaign of which of the following airlines?



1) Lufthansa

2) Fly Emirates

3) Jet Airways

4) Singapore Airlines



3) Who among the following is the author as the book mein kampf?



1) Rudyard Kipling

2) Adolf Hitler

3) Arnold Toynbee

4) Charles Dickens



4) Who among the following were the founders of the Vijayanagar empire?



1) Krishna Deva Raja

2) Saluva Narsimha

3) Deva Raja II

4) Harihara and Bukka



5) What is the correct expansion of the abbreviation NASA?




1) National Aeronautical Science Association

2) New Aeronautical and Science Agency

3) National Aeronautics and space Administration

4) None of these



6) At which of the following places on the globe has the highest temperature been recorded?




1) Al Azizyah

2) Jacobabad

3) Cairo

4) None of these



7) The Indio constitution is divided into how many parts?




1) Twenty-Two

2) Twenty

3) Eighteen

4) Sixteen



8) The first five year plan of India started in




1) 1952-53

2) 1951-52

3) 1956-57

4) 1948-49



9) The first Indian woman president of the Indian National Congress was



1) Sarojini Naidu

2) Nellie Sengupta

3) Annie Besant

4) Aruna Asaf Ali



10) The first bowler to take all the 10 wickets in a test innings was



1) Anil Kumble

2) Richard Hadlee

3) Jim Laker

4) Shane Warne



11) The first Indian tennis player to win a Grand Slam event



1) Ramanathan Krishanan

2) Mahesh Bhupati

3) Ramesh Krishanan

4) Leander paes



12) The first train in India from Bombay to Thane ran in




1) 1857

2) 1855

3) 1860

4) 1853



13) How many PIN code zone are there in India?




1) 7

2) 9

3) 8

4) 6



14) The film DON is a remake of an old film of the same name. Who is the director of the present DON?



1) Shahrukh Khan

2) Rakesh Mehra

3) Ram Gopal Verma

4) Farhan Akhtar



15) The new Chief Minister of the Jharkhand is



1) Arjun Munda

2) Madhu Koda

3) Shibu Soren

4) None of these





Ans:
1) 1 2) 4 3) 2 4) 4 5) 3
6) 1 7) 1 8) 2 9) 1 10) 3

11) 1 12) 4 13) 3 14) 4 15) 2

Hibernate Interview Questions

1.What is Hibernate?
Hibernate is a powerful, high performance object/relational persistence and query service. This lets the users to develop persistent classes following object-oriented principles such as association, inheritance, polymorphism, composition, and collections.

2.What is ORM?
ORM stands for Object/Relational mapping. It is the programmed and translucent perseverance of objects in a Java application in to the tables of a relational database using the metadata that describes the mapping between the objects and the database. It works by transforming the data from one representation to another.

3.What does an ORM solution comprises of?
It should have an API for performing basic CRUD (Create, Read, Update, Delete) operations on objects of persistent classes
Should have a language or an API for specifying queries that refer to the classes and the properties of classes
An ability for specifying mapping metadata
It should have a technique for ORM implementation to interact with transactional objects to perform dirty checking, lazy association fetching, and other optimization functions

4.What are the different levels of ORM quality?


There are four levels defined for ORM quality.

Pure relational

Light object mapping

Medium object mapping

Full object mapping

5.What is a pure relational ORM?

The entire application, including the user interface, is designed around the relational model and SQL-based relational operations.

6.What is a meant by light object mapping?

The entities are represented as classes that are mapped manually to the relational tables. The code is hidden from the business logic using specific design patterns. This approach is successful for applications with a less number of entities, or applications with common, metadata-driven data models. This approach is most known to all.

7.What is a meant by medium object mapping?

The application is designed around an object model. The SQL code is generated at build time. And the associations between objects are supported by the persistence mechanism, and queries are specified using an object-oriented expression language. This is best suited for medium-sized applications with some complex transactions. Used when the mapping exceeds 25 different database products at a time.

8.What is meant by full object mapping?
Full object mapping supports sophisticated object modeling: composition, inheritance, polymorphism and persistence. The persistence layer implements transparent persistence; persistent classes do not inherit any special base class or have to implement a special interface. Efficient fetching strategies and caching strategies are implemented transparently to the application.

9.What are the benefits of ORM and Hibernate?

There are many benefits from these. Out of which the following are the most important one.
Productivity – Hibernate reduces the burden of developer by providing much of the functionality and let the developer to concentrate on business logic.

Maintainability – As hibernate provides most of the functionality, the LOC for the application will be reduced and it is easy to maintain. By automated object/relational persistence it even reduces the LOC.

Performance – Hand-coded persistence provided greater performance than automated one. But this is not true all the times. But in hibernate, it provides more optimization that works all the time there by increasing the performance. If it is automated persistence then it still increases the performance.

Vendor independence – Irrespective of the different types of databases that are there, hibernate provides a much easier way to develop a cross platform application.

10.How does hibernate code looks like?

Session session = getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
MyPersistanceClass mpc = new MyPersistanceClass ("Sample App");
session.save(mpc);
tx.commit();
session.close();

The Session and Transaction are the interfaces provided by hibernate. There are many other interfaces besides this.

JMS Questions & Answers

1.What are the advantages of JMS?

JMS is asynchronous in nature. Thus not all the pieces need to be up all the time for the application to function as a whole. Even if the receiver is down the MOM will store the messages on it's behalf and will send them once it comes back up.



2.What is the difference between topic and queue?

A topic is typically used for one to many messaging i.e. it supports publish subscribe model of messaging. While queue is used for one-to-one messaging i.e. it supports Point-to-Point Messaging.



3.What is the use of Message object?

Message is a lightweight message having only header and properties and no payload.



4.What are the two different types of messaging models that are supported by JMS?

1. Point-to-Point
2. Publish and Subscribe.


5.What information is stored in the Header of a ‘Message’?

Message identification and routing information.



6.What are the types of acknowledgments?

1) Acknowledgment by commits. – Acknowledgement happens automatically when a transaction is committed.

2) Session.AUTO_ACKNOWLEDGE

3) Session.CLIENT_ACKNOWLEDGE – client must call the acknowledge( ) method

4) Session.DUPS_OK_ACKNOWLEDGE –Session acknowledges the message after it has been delivered. This may result in the delivery of some duplicate messages if the JMS provider fails.



7.What happens to messages if a transaction is rolled back?


All consumed messages are re-delivered.



8.What is text message?

Text messages contain String messages. It is useful for exchanging textual data and complex character data like XML.



9.What is the Role of the JMS Provider?


The JMS provider handles security of the messages, data conversion and the client triggering. The JMS provider specifies the level of encryption and the security level of the message, the best data type for the non-JMS client.



10.What are the advantages of JMS?


One of the principal advantages of JMS messaging is that it's asynchronous. Thus not all the pieces need to be up all the time for the application to function as a whole.