My strong belief is if you are starting new, you are cash flow negative atleast for some time until the product picks up. Does that belief translate into adding a major new feature to existing product? I think it does. You have a product with a steady revenue stream. Now you are adding a major feature which is completely re-inventing your self. I think during the time period when you are re-inventing yourself the revenue will take a dip and it should not be a surprise. I would take Netflix as an example. They had a steady revenue stream. They bet on online subscription and took a dip in their stock price. How long is such dip sustainable before the company goes down? I dont know. But companies do need to re-invent themselves to stay relevant in the evolving market place and take those risks immediately or eventually the market will render those products obsolete.
My blog sort of outlines my work life - the areas I worked in, the issues I faced, my knowledge and my opinions
Tuesday, May 20, 2014
Tuesday, May 13, 2014
Flow through Product Lifecycle
Does organization structure impact innovation? Do I hear a resounding yes !!!
A mid-sized company does not want to deviate too much from their path. They however are faced with obsoleteness and want to invest in emerging markets. So one product line is declining and another product line is emerging. However they believe market growth will automatically bring these emerging market technologies bear fruit. But company has to realize that any emerging, growing market product needs sufficient investment to be able to grow in the rapidly changing scenarios as the market is still emerging. Based on the product lifecycle for new products, a product can cross the chasm and still be in limbo if it stop innovating. I wish there was a lifecycle of failing products to prove what I am trying to say. The product lifecycle by Dr. Geoffrey Moore talks about chasm as the test for the product but even after crossing the chasm if the product loses funding, the product can go back to the chasm phase if it cannot keep up to the technology advances offered by competition. Maybe that is already documented in the technology lifecycle and I have missed but that is definitely an important point to highlight on how a product which obtained early majoring slipped back into the chasm because of lack of catching up to competition.
A mid-sized company does not want to deviate too much from their path. They however are faced with obsoleteness and want to invest in emerging markets. So one product line is declining and another product line is emerging. However they believe market growth will automatically bring these emerging market technologies bear fruit. But company has to realize that any emerging, growing market product needs sufficient investment to be able to grow in the rapidly changing scenarios as the market is still emerging. Based on the product lifecycle for new products, a product can cross the chasm and still be in limbo if it stop innovating. I wish there was a lifecycle of failing products to prove what I am trying to say. The product lifecycle by Dr. Geoffrey Moore talks about chasm as the test for the product but even after crossing the chasm if the product loses funding, the product can go back to the chasm phase if it cannot keep up to the technology advances offered by competition. Maybe that is already documented in the technology lifecycle and I have missed but that is definitely an important point to highlight on how a product which obtained early majoring slipped back into the chasm because of lack of catching up to competition.
Thursday, April 25, 2013
Big Data Product Leadership
I think there is lack of leadership in the big data space who can say "This is how you are going to analyze data in your system and this is what you are going to use". There is a lack of a company like Apple who can say that "This the way smart phones should be and here's my product iPhone".
I am seeing companies all around me which wants to enter the big data and big data analytics market because its a huge untapped market. No clear market leader exists and its a fast growing segment. Companies are recognizing the value of data and performing analytics to gain value from data to gain competitive advantage.
Why are the companies trying to sell analytics solution not able to choose a segment like fraud detection? I am unable to understand why fraud detection agencies have to use ten tools to have an application running? Why is there no single solution for complete analytical solution in market? The solution should do model generation (Run repeated regression analysis with various parameters automatically, run k-mean clustering, run APRIORI and such), model validation and real time data incorporation that can solve all the problems of a fraud detection system. As a fraud detection application architect, I just want to go to one tool which will allow me to automatically generate models (smart) and suck in data what will keep on validating the models on regular basis and define rules for making real time decisions per transaction to determine if it is fraud or genuine.
I am seeing companies all around me which wants to enter the big data and big data analytics market because its a huge untapped market. No clear market leader exists and its a fast growing segment. Companies are recognizing the value of data and performing analytics to gain value from data to gain competitive advantage.
Why are the companies trying to sell analytics solution not able to choose a segment like fraud detection? I am unable to understand why fraud detection agencies have to use ten tools to have an application running? Why is there no single solution for complete analytical solution in market? The solution should do model generation (Run repeated regression analysis with various parameters automatically, run k-mean clustering, run APRIORI and such), model validation and real time data incorporation that can solve all the problems of a fraud detection system. As a fraud detection application architect, I just want to go to one tool which will allow me to automatically generate models (smart) and suck in data what will keep on validating the models on regular basis and define rules for making real time decisions per transaction to determine if it is fraud or genuine.
Tuesday, July 10, 2012
Data Analysis Techniques
Linear Regression:
Here one dependent variable is described as a combination of a list of independent variables
Assumptions:
There is one dependent variable and a number of independent variables
Process:
Excel will let you run linear regression given a bunch of columns of independent variables
The distribution of independent variables should be normal?
Output:
An Equation. which describes which variables are significant in describing the variability in data of dependent variable
The result of the equation is a numeric value which can be used for forecasting or predicting
Sales = 0.8 * # of people entering the store
where sales is the dependent variable and
# of people entering the store is independent variable
Linear Discriminant Analysis
In order to discriminate or seperate out 2 ore more groups of data and characterizing the difference by a vector, we use Linear Discriminant Analysis.
Assumptions:
the independent variables need to be normally distributed
Process:
You can obtain LDA equation using R given a set of data
Output:
# of equations equal to the number of groups/classes -1
The result is used to find if a particular set of data belongs to group#1 or group#2 or group#3 or group#4 & so on
Eg. For 3 classes of flowers, there are 4 characteristics which classifies one flower from another
the 4 characterizing features are Sepal width, sepal length, petal width, petal length.
LD1 = 0.39 * sepal length + 2.067 * sepal width -2.27 * petal length -2.28 * petal width
LD2 = 0.56 * sepal length -2.45 * sepal width +0.41 * petal length -2.12 * petal width
LD1 line goes parallel through the means and LD2 line gives the distance between the means
If for a random flower we know the sepal length, sepal width , petal width and petal length, we can evaluate equation 2 to find which flower it is based on the sepal length, sepal width, petal length, petal width
Disadvantage:
It needs variance within each group to be same.
Logistic Regression
In order to run linear regression on a set of data but have an outcome which is dichotomous, we use logistic regression.We use logistic regression when we want to know which variables the dependent variable is dependent on.
Assumptions:
The inputs need not be normally distributed.
Output:
Output is an equation which is a natural log of the likelihood of the occurance of a state of the dependent variable.
eg.
1 = female
0 = male
ln(P(1)/(1-P(1)) = 0.2 + 0.4*height
Disadvantage:
It needs large sample size
ANOVA
tests whether the groups are different enough to be classified
the output of anova too is a true or false whether teh data columns are statistically different. There is a way they can be seperated
F value =SSE(between)/ SSE(Within)
Process:
You can run it in excel
Output
Output is an F value and probability of F-value. if p < 0.05, then the null hypothesis is rejected and the data is proven to be statistically different
Here one dependent variable is described as a combination of a list of independent variables
Assumptions:
There is one dependent variable and a number of independent variables
Process:
Excel will let you run linear regression given a bunch of columns of independent variables
The distribution of independent variables should be normal?
Output:
An Equation. which describes which variables are significant in describing the variability in data of dependent variable
The result of the equation is a numeric value which can be used for forecasting or predicting
Sales = 0.8 * # of people entering the store
where sales is the dependent variable and
# of people entering the store is independent variable
Linear Discriminant Analysis
In order to discriminate or seperate out 2 ore more groups of data and characterizing the difference by a vector, we use Linear Discriminant Analysis.
Assumptions:
the independent variables need to be normally distributed
Process:
You can obtain LDA equation using R given a set of data
Output:
# of equations equal to the number of groups/classes -1
The result is used to find if a particular set of data belongs to group#1 or group#2 or group#3 or group#4 & so on
Eg. For 3 classes of flowers, there are 4 characteristics which classifies one flower from another
the 4 characterizing features are Sepal width, sepal length, petal width, petal length.
LD1 = 0.39 * sepal length + 2.067 * sepal width -2.27 * petal length -2.28 * petal width
LD2 = 0.56 * sepal length -2.45 * sepal width +0.41 * petal length -2.12 * petal width
LD1 line goes parallel through the means and LD2 line gives the distance between the means
If for a random flower we know the sepal length, sepal width , petal width and petal length, we can evaluate equation 2 to find which flower it is based on the sepal length, sepal width, petal length, petal width
Disadvantage:
It needs variance within each group to be same.
Logistic Regression
In order to run linear regression on a set of data but have an outcome which is dichotomous, we use logistic regression.We use logistic regression when we want to know which variables the dependent variable is dependent on.
Assumptions:
The inputs need not be normally distributed.
Output:
Output is an equation which is a natural log of the likelihood of the occurance of a state of the dependent variable.
eg.
1 = female
0 = male
ln(P(1)/(1-P(1)) = 0.2 + 0.4*height
Disadvantage:
It needs large sample size
ANOVA
tests whether the groups are different enough to be classified
the output of anova too is a true or false whether teh data columns are statistically different. There is a way they can be seperated
F value =SSE(between)/ SSE(Within)
Process:
You can run it in excel
Output
Output is an F value and probability of F-value. if p < 0.05, then the null hypothesis is rejected and the data is proven to be statistically different
Tuesday, April 10, 2012
How do you define a good Product?
Whether a product is tangible or intangible, the criteria that defines a good product are quite the same.
The four Ps of Product Marketing are: Product, Price, Promotion, Place. It is just impossible to define a good product without considering the other 3 Ps. however, here is my attempt at what makes a good product.
The product has to
1) Provide value and enrich the customer in some form or another.(Product)
2) Provide ease of use (Product)
3) Be unique. There has to be differentiation (Product)
4) Have a well defined use of product (Product)
5) Be interesting and exciting (Product)
The four Ps of Product Marketing are: Product, Price, Promotion, Place. It is just impossible to define a good product without considering the other 3 Ps. however, here is my attempt at what makes a good product.
The product has to
1) Provide value and enrich the customer in some form or another.(Product)
2) Provide ease of use (Product)
3) Be unique. There has to be differentiation (Product)
4) Have a well defined use of product (Product)
5) Be interesting and exciting (Product)
Friday, February 17, 2012
Product Management in a Startup
I work for a start-up and as with any job in a start-up you end up taking a lot more responsibility than your title demands.
When I finished my MBA, I went to ask for a product management position. They said we are short of developers. So I ended up taking on Product Management as well as development role.
Now as I am performing product management responsibilities, I realized that its a not as glamorous a job as I thought.
There are multiple new products you are working on. At the same time you need to make sure you are not building your stepping stone for new customers on the grave of your existing customer. Bug fixes need to take priority as well.
There there are inputs from development team that we need to upgrade the platform and need new tools as technology advances.
But there are only so many resources available.
I devised a means to assign all Development team requests lower weight, all bug fixes highest weight and new product development moderate weight. However, this made the development team not so happy as well as the upper management not so happy. The professional services guys were happy though.
How can you make everyone happy? Is it even possible?
Should I use some other mechanism to intersperse the weights so that some new development and some development team requests can be accommodated with higher weights & priorities?
When I finished my MBA, I went to ask for a product management position. They said we are short of developers. So I ended up taking on Product Management as well as development role.
Now as I am performing product management responsibilities, I realized that its a not as glamorous a job as I thought.
There are multiple new products you are working on. At the same time you need to make sure you are not building your stepping stone for new customers on the grave of your existing customer. Bug fixes need to take priority as well.
There there are inputs from development team that we need to upgrade the platform and need new tools as technology advances.
But there are only so many resources available.
I devised a means to assign all Development team requests lower weight, all bug fixes highest weight and new product development moderate weight. However, this made the development team not so happy as well as the upper management not so happy. The professional services guys were happy though.
How can you make everyone happy? Is it even possible?
Should I use some other mechanism to intersperse the weights so that some new development and some development team requests can be accommodated with higher weights & priorities?
Friday, February 03, 2012
Business Valuation
What is free cash flow?
It is the cash that is free to be distributed to share holders of the company to keep investors happy.
Hence we calculate NOPAT (Net Operating Profit After Tax) and subtract Net CAPEX (Capital Expenditure) from the NOPAT. CAPEX is subtracted because it is the investment already made by the company to grow its revenue. hence it is not available to the share holders.Change in Net Working Capital is also subtracted from NOPAT since it seems that next year they might need that changed working capital in addition to the already deducted working capital from NOPAT.
FCF = NOPAT - Net CAPEX - Delta NWC
Calculate NOPAT
NOPAT is calculated easily (EBIT * (1 - Tax Rate)). However, it is the adjustments that need to be made on NOPAT that makes it complicated. Without adjustments, NOPAT value in itself is not sufficient to use in any kind of analysis.
It is the cash that is free to be distributed to share holders of the company to keep investors happy.
Hence we calculate NOPAT (Net Operating Profit After Tax) and subtract Net CAPEX (Capital Expenditure) from the NOPAT. CAPEX is subtracted because it is the investment already made by the company to grow its revenue. hence it is not available to the share holders.Change in Net Working Capital is also subtracted from NOPAT since it seems that next year they might need that changed working capital in addition to the already deducted working capital from NOPAT.
FCF = NOPAT - Net CAPEX - Delta NWC
Calculate NOPAT
NOPAT is calculated easily (EBIT * (1 - Tax Rate)). However, it is the adjustments that need to be made on NOPAT that makes it complicated. Without adjustments, NOPAT value in itself is not sufficient to use in any kind of analysis.
Adjustments that go on NOPAT are any expenses that are one time expenses like restructuring charges or interest portion of operating lease payments since interest expense should not be deducted from NOPAT. Interest expense is not related to operations of the company so it is wise to add it back to Net Income/EBIT.
Calculate Net CAPEX
Capital Expenditure is money invested back into the company for future growth. Hence this money is not available to share holders. Hence it is deducted from the NOPAT to arrive at Free Cash flow.
The Capital Expenditure is mentioned in the Cash Flow Statement of company's financials.
Adjustments are made to Net CAPEX for depreciation. Depreciation is subtracted from capital expenditure All the investing activities which bring in money like sale of assets are subtracted from the CAPEX. All investing activities that result in outflow of cash are added to CAPEX like acquisitions.
Calculate Change in Net Working Capital (NWC)
Net Working Capital can be calculated as
Accounts Receivables + Inventory - Accounts Payable
Free Cash Flow (FCF)
FCF = NOPAT - CAPEX - change in NWC
Equity Valuation
To come to the Equity value of the company, you have to estimate the revenue for the next 5 years, estimate NOPAT as a % of Revenue, estimate CAPEX as % of Revenue, estimate change in NWC and calculate FCF for next 5 years. For years thereafter, assume a growth rate generally assumed to be 3%, and calculate Terminal Value. Calculate present Value for all the FCF values and sum them up to get the Equity Value of the Enterprise.
Debt Value
Debt value can be calculated by calculating present value for all future debt obligations and summing them up.
Enterprise Value
Enterprise Value is the sum of Debt Value and Equity Value.
Tuesday, January 04, 2005
Ant in 15 Minutes
1) Create a build.xml file.
2) The parent tag is project. It has 3 attributes - name, default, basedir.
Default is the first target to be executed.
Basedir is the reference from which other path references will be made
3) Then there are multiple target tags. The target referred to by default is executed first.
3) Target has 3 imp attributes -name, depends, description.
4) Depends executes from left to right.Depends has target names seperated by commas.
5) Inside target there are tasks
6) Tasks are - built-in tasks, optional tasks, write your own tasks
7) Generally used examples of built in tasks are -
copy (file/fileset, to dir, failonerror),
delete (file/dir/fileset, verbose, failonerror),
echo(message, level) - can also write message between open echo tag & closing echo tag,
ear(destfile, appxml),
jar(destfile, basedir, includes),
javac(srcdir, destdir, classpath failonerror),
java(classname, jar),
mkdir(dir),
move(file, todir),
property(name value),
war(destfile, webmxl, basedir)
2) The parent tag is project. It has 3 attributes - name, default, basedir.
Default is the first target to be executed.
Basedir is the reference from which other path references will be made
3) Then there are multiple target tags. The target referred to by default is executed first.
3) Target has 3 imp attributes -name, depends, description.
4) Depends executes from left to right.Depends has target names seperated by commas.
5) Inside target there are tasks
6) Tasks are - built-in tasks, optional tasks, write your own tasks
7) Generally used examples of built in tasks are -
copy (file/fileset, to dir, failonerror),
delete (file/dir/fileset, verbose, failonerror),
echo(message, level) - can also write message between open echo tag & closing echo tag,
ear(destfile, appxml),
jar(destfile, basedir, includes),
javac(srcdir, destdir, classpath failonerror),
java(classname, jar),
mkdir(dir),
move(file, todir),
property(name value),
war(destfile, webmxl, basedir)
Thursday, September 02, 2004
General Java Interview Questions
Topics
JDBC
Inner Classes
Enterprise Java Beans
EJB Transactions
Design Patterns
Collections
Synchronization
Questions
Q) final ref or final primitive wat is the difference
Q) compile time polymorphism & run time polymorphism
Q) String & StringBuffer- when will u use wat?
Q)When will u use static variable or static method?
Q) Wat if there is an exception in ejbremove? Is the bean instance destroyed? Or it remains?
Q)Does instance of return true for the parent class of the class specified?
Q) How do u convert an int to a string?
Q)How will u implement composition?
Q)What r volatile variables? When r they used?
Q) When to use session bean & when to use entity bean?
Q) CMP vs BMP?
Q) Coarse-grained & fine-grained entity beans?
Q) When will u use interface & when an abstract class?
Q) Include Directive, Include Action
Q) Wat is difference between outer join & inner join?
Q) How do threads communicate with each other
Q) How do u convert a mutable class to immutable?
Q) why J2EE
Q) Y have interfaces with no methods eg - java.io.Serialisable, java.lang.Clonable, java.rmi.Remote ?
Q) how do u ensure garbage collector will pick up the object?
Q) how does indexing help?
Q) JSP Forward or redirect.
Q) what does clone do if not overridden?
Q) Difference between runtime exception & compile time exception.
Q) how do u manage state?
Q) What is a memory leak in java?
Q) What all can you synchronize?
Q) If you have String x="foo"; String y="foo"; String z="foo"; how many instances of "foo" do you get?
Q) What is typesafe enum?
1) JDBC
There are 3 classes associated with JDBC.
java.sql.Driver
java.sql.DriverManager
java.sql.Connection
Generally the procedure is to first register a jdbc driver with the drivermanager. This happens with the Class.forName(""). (when u load a class with forName(), the loading, linking & initialization occurs. The initialization of JDBC driver involves registering the driver with the driver manager)
Then connection is requested from the driver manager. The driver manager in turn search through all of the known java.sql.Driver implementations for the one that connects with the URL you provided.
There r 3 kinds of statements
CreateStatement or just Statement
Prepared statement
Callable Statement
Never use create statement. The results r unformatted
Prepared statements execute faster then statements
Callable statement is an extention of prepared statement
Use callable statement while calling SP
The main feature of a PreparedStatement object is that, unlike a Statement object, it is given an SQL statement when it is created. The advantage to this is that in most cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a result, the PreparedStatement object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement 's SQL statement without having to compile it first.
It is possible to update resultset using updateRow() - JDBC drivers are not required to provide this functionality. To specify whether the resultset is updatable, in preparedStatement, add parameter ResultSet.CONCUR_UPDATABLE
2) 5 uses of inner classes:
it allows you to group classes that logically belong together and to control the visibility of one within the other
Each inner class can independently inherit from an implementation. Thus, the inner class is not limited by whether the outer class is already inheriting from an implementation
The inner class can have multiple instances, each with its own state information that is independent of the information in the outer class object.
In a single outer class you can have several inner classes, each of which implement the same interface or inherit from the same class in a different way. An example of this will be shown shortly.
The point of creation of the inner class object is not tied to the creation of the outer class object.
There is no potentially confusing "is-a" relationship with the inner class; it's a separate entity
Disadvantage: the compiler/virtual machine, treats an inner class just like any other class. In order for the inner class to have access to the private variables of the outer class, the variables are made default access - accessible to the package.
3) Enterprise Java Beans
It automatically takes into account - security, resource pooling, persistence, concurrency & transactional integrity
Rmi & iiop provide error & exception handling, parameter passing & passing of transaction & security context
Several clients can be connected to one ejb object, but only one client thread can access the bean instance at a time. If, for example, one of the clients invokes a method on the ejb object, no other client can access that bean instance until the method invocation is complete. If the method is part of a large transaction, then the bean instance cannot be accessed at all, except within the same transactional context, until the entire transaction is complete.
Session bean can never be reentrant & they throw remote exception if a loopback is attempted. Same is true for non-reentrant entity beans. U can make entity bean reentrant by specifying it in the deployment descriptor.
Remove methods are defined in javax.ejb.EJBHome interface. So the home interface inherits them.
ejbCreate method alwayz returns primary key with bmp & null for cmp.
For session bean, return type is void
PortableRemoteObject.narrow is needed to support the requirements of rmi over iiop. Because CORBA supports many different languages, casting is not native to CORBA. Therefore, to get remote reference to home, we must explicitly narrow the object returned by lookup. This has the same effect as casting
All beans have a default jndi context java:comp/env/ejb
EJBHome interface methods
EJBMetaData getEJBMetaData
HomeHandle getHomeHandle
Void remove
EJBMetaData interface methods
EJBHome getEJBHome
Class getHomeInterfaceClass
Class getPrimaryKeyClass
Class getRemoteInterfaceClass
Boolean IsSession
EJBObject interface methods
EJBHome getEJBHome
Handle getHandle
Object getPrimaryKey
Boolean isIdentical
Void remove
when u make a call getByPk,
ejbload happens. the data is put in the entitybean frm db.
the return is the stub. on each invocation of a method on entity bean, a remote call is made. if caching is done, the dta is there in entity bean. ejb load does not happen. So db call is saved.
4) Transactions - EJB
Problems: Dirty reads: a dirty read occurs when the first transaction reads uncommited changes made by a second transaction. If the second transaction is rolled back, the data read by the first transaction becomes invalid.
10:00:00 client 1 chooses cabin 99 to be reserved
10:00:02 client 2 reads the list of reservation. So cabin 99 is not available
10:00:03 client 1 pays. But credit card invalid. So transaction rolled back & cabin 99 is now available
Repeatable reads: a repeatable read is when data read is guaranteed to look the same if read again during the same transaction. A non-repeatable read is when the data retrieved in a subsequent read within the same transaction can return different results.
10:00:00 client 1 reads list of available cabins with 2 beds. Cabin 99 is in the list
10:00:02 client 2 changes bed count from 2 to 3 for cabin 99.
10:00:03 client 1 reexecutes read of list of available cabins with 2 beds. Cabin 99 is still in the list
Phantom read: phantom read occurs when new records added to the db are detectable by the transactions that started prior to the insert.
10:00:00 client 1 reads list of available cabins with 2 beds. Cabin 99 is in the list
10:00:02 client 2 makes a reservation on cabin 99
10:00:03 client 1 reexecutes read of list of available cabins with 2 beds. Cabin 99 is no longer in the list
generally do not use client initiated transaction. B'coz after successfully performing an operation, when the bean returns, it might throw, remote exception. So the client would not know whether the operation happened or no.
if a ejb component sends & receives message in the same component, then it is possible that it will keep on waiting till it receives a message(in relation to jms & mdb). The solution to this problem is - after sending this message, call commit on the jms session, which is your jms transaction helper object. This causes the outgoing message buffer to be flushed.
Transaction attributes to be specified in deployment descriptor
Required - if already within a transaction, then the bean is part of the transaction. If not transaction already started, it starts a new
RequiresNew - if starts a new transaction. If a transaction already exists, then that is suspended & a new transaction is created. When this bean is done, the old transaction is resumed.
Supports - it runs only in a transaction if the client has one- it joins the transaction. If the client does not have a transaction, the bean runs with no transaction at all.
Mandatory - mandates tht a transaction be already running when the bean method is called. If transaction is not running, the javax.ejb.TransactionRequired exception is thrown.
Not Supported - that ur bean cannot be involved in a transaction at all. The transaction is suspended & resumed when the bean method is over.
Never - that ur bean cannot be involved in a transaction at all. If the client calls the bean in a transaction, then java.rmi.remote/javax.ejb.EJBExxception exception is thrown
Transaction isolation attributes
READ_UNCOMMITTED
READ_COMMITTED - transaction cannot read uncommitted data. Data that is being changed by another transaction cannot be read.
REPEATABLE_READ - transaction cannot change data that is being read by another transaction.
SERIALISABLE - transaction has exclusive read & update privileges to data. Other transaction can neither read nor update the same data.
U are allowed to specify isolation levels on per method basis but this flexibility comes with an imp restriction: all methods invoked in the same transaction must have the same isolation level.
In Entity EJB, a transaction spans ejb load, method & ejb store.
In bean managed transactions, u might write transaction begin in ejb load & transaction end in ejb store. But ejb load & ejb store are called by the container. So u can never be sure. The transaction may never end. So bean managed transactions are illegal in entity beans.
In MDB
Container managed transaction, the message is read off in the same transaction as the business logic is executed. If something goes wrong, the transaction will roll back & message acknowledgement will occur.
Bean managed transaction, the transaction begins & ends after the message is received. You can use the deployment descriptor acknowledgement modes to instruct the container about when to acknowledge the messages.
There is no way to specify isolation level in container-managed bean in a portable way.
5) Design Patterns
Singleton
home factory required a single instance of the factory class
when data is cached in a hashtable, a single instance of the hashtable is required
example of factory pattern
ejbhome factory
flyweight pattern
command pattern - struts
here there is an abstract base class called Action. All the other classes extend this action class. They have one command "perform". On button click, the control goes to a common servlet. This servlet (ActionServlet) reads the xml file for the next operation to call. The path info is given as input, stuts config is read & corresponding action class name is obtained. Then on this name, the perform method is invoked.
6) Collections
The collection interface is a group of objects with duplicates allowed
Set interface extends collection but forbids duplicates
List extends Collection also allows duplicates & introduces positional indexing
Map extends neither Set nor Collection & forbids duplicate key
Set
-HashSet
-TreeSet(use it to extract elements in a sorted manner)
it is generally faster to add elements to a hash set then convert the collection to a treeset.
Eg. hashset for sparce matrix
Treeset for JList
List
-ArrayList(random access, without inserting or removing) )(corresponding historical is vector)
-LinkList()(if frequent add & remove elements in the middle of the list and only access elements sequentially)
eg. Arraylist for JcomboBox
Map
-HashMap(inserting, deleting and locating)(corresponding historical is Hashtable & properties)
-TreeMap(traversing the keys in a sorted manner)
Historical List
-Vector (implements List interface)
-Stack (extends vector)
Historical Map
-Hashtable (implements map)
-Properties (implements map extends Hashtable)
Historical collection classes- operations are synchronized.
Iterator u can traverse a collection & safely remove elements from the underlying collection.
If iterator is traversing a collection while underlying collection is being modified by another thread, then the iterator fails by throwing ConcurrentModificationException.
If u need synchronized map, using hashtable is faster then using synchronized hashmap.
Fastest to search is hashtable
Then binary search on sorted collection & quick sort
Can u iterate thru hashmap. - no u have to use entryset in order to convert map to set
7) Synchronization
Synchronized method -Only one thread is executing that method at a time. The object containing the synchronized method is locked..in the sense that no one can call a synchronized method on the same object while the synchronized method is getting executed.
Synchronized block - where u specify the object which is locked . only one thread will execute the block at one time. Useful when shared resource exists in the block of code. Eg. Document series number - u read it, increment it & save the new number. All this should happen only once at a time.
When u have a object in a synchronized method & the same object is accessed by the unsynchronized object, then the unsynchronized object can access that object b?coz since it is unsynchronized, it does not check if the object is locked.
Whenever control enters a synchronized method, the thread that called the method locks the object whose method has been called. Other threads cannot call a synchronized method on the same object until the object is unlocked.
Q) final ref or final primitive wat is the difference
A) if final primitive is used, u cannot change it.
If final ref is used, then u can change the properties of the object but not the address
Q) compile time polymorphism & run time polymorphism
A) overloading is compile time polymorphism. overriding is dynamic or runtime polymorphism.
Q) String & StringBuffer- when will u use wat?
A) String is a constant & Stringbuffer is modifiable.
When there r a lot of string manipulations, u use StringBuffer b'coz otherwise a lot of new objects are created.
Q)When will u use static variable or static method?
A) U use static when u want the variable or method to be accessed at class level without creating an instance of the class.
Typical use of static
· - The proper place to define utility methods (methods that take input and provide output only through passed parameters and the return value) . Methods that don't manipulate or use the state of an object or class I call utility methods
· A way to control access to objects and data. Public class variables are a different story. If a public class variable isn't final, it is a global variable: that nasty construct that is the antithesis of data hiding. There is never any excuse for a public class variable, unless it is final.
Q) Wat if there is an exception in ejbremove? Is the bean instance destroyed? Or it remains? ? can someone answer this question
Q)Does instance of return true for the parent class of the class specified?
A) yes
Q) How do u convert an int to a string?
A)Integer.toString(i);
ToString is a static method of integer. This method takes an interger & returns a String Object. In general what happens when u convert an object to another type or when u convert a primitive to an object
-consider the binary representation of the int & string.i.e. '\u0030' for 0 '\u0031' for 1.
Q)How will u implement composition?
A)Put the code in finalise to delete child objects. As finalise will be called when the parent is getting deleted.
Q)What r volatile variables? When r they used?
A)Volatile variables r variables which are updated each time a change is made to them & checked each time the value is used.
Q) When to use session bean & when to use entity bean?
A)
1) In session bean u can call save operation anytime whenever u wish. So more control. In entity bean, the container decides when to call ejbload & ejbstore methods. So no control.
2) Parameter passing
When u do a query in session bean, u get result set - pass by value
When u call get method on entityhome, u get stubs to server side objects - pass by reference.
In order to display data in gui, the client has to traverse the network if pass by reference is done. Hence performance penalty. U can work around this problem by collocating session bean with the entity bean & serializing the entity bean object before sending it to the client.
3) Caching. Session bean do not represent data hence it cannot be cached. Entity beans can be cached by setting up certain flags in the deployment descriptor. If data is shared, caching offers benefits else it is of no use. Eg of non-shared data is personal account information on amazon.com. eg of shared data is a product catalog of 100 hottest books on amazon.com
4) If entity bean then schema independence. However if session bean crafted correctly gives schema independence. (schema independence is if some column in table is changed, the impact in ejb layer is minimal)
Q) CMP vs BMP?
A)
1) Cmp entity beans if tuned properly, is higher performing than bmp. With bmp, it takes 2 sql stmts to load an entity bean: the finder method(to load primary key) & then ejbload() method.
2) Cmp is harder to debug.
3) Cmp may not handle complex mapping.
4) In cmp no hardcoding of database api such as jdbc. But this feature is imp only to those who r selling their bean to diff ppl with diff db requirements.
5) In ejb2.0 relationships can be mapped. In bmp, lot of scaffolding code has to be written.
Q) Coarse-grained & fine-grained entity beans?
A) One choice u have is to make some of the entity beans as java classes. These r called dependent value classes.
Q) When will u use interface & when an abstract class?
A) U use an interface when u don?t have common code. U use abstract class when u have code that can be shared.
When u want to change implementation behind a common interface, use interface. Eg. In a media player, u might want to change the algorithm that runs to play the media. So when a new algorithm comes up, u just implement that interface & use the new algorithm.
Abstract classes let you define some behaviors; they force your subclasses to provide others. This class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a "random access" data store (such as an array)
Q) include directive <%@ include file="child.jsp" %>
include action
A) The include directive includes the content of the file during the translation phase where as include action includes the content of the file during execution/request processing phase.
For include directive, JSP Engine adds the content of the inserted page at translation phase, so it does not have an impact on performance.
For include action, JSP Engine adds the content of the inserted page at run time which imposes extra overhead.
Q) Wat is difference between outer join & inner join?
A) Outer join is when you want all rows frm one table & only those rows frm other table which match the value from the table which has all rows.
Inner join is a simple join.
Left outer join is same as left outer join except that in left outer join, the (+) is on right side & in right outer join (+) is on left side.
Full outer join is all rows frm both table.
Q) How do threads communicate with each other
A) Threads communicate with one another thr semaphores or message queues. Semaphore is a integer. One example showing the use of semaphores is when one thread needs to send data (e.g. through a buffer) to another thread. In multithreading environments there is no guarantee in which order two threads will come to the point where the first thread is filling the data buffer and the other thread is reading it. Therefore, these two threads need to synchronize execution at the exchange point. Semaphore's logic for this case is fairly simple: the reader thread calls wait() before reading the buffer and "hangs" if the semaphore is not yet signaled. The writer thread calls post() after filling the buffer with data and thus signals the reader thread that the data buffer is ready. This schema ensures that the data buffer will be read by the second thread only when the data is actually ready
Q) How do u convert a mutable class to immutable?
A)
1. Make the class definition final
2. Remove all setter methods
3. Let the constructor set the attributes of the class
4. Don?t use any method that will change the state of the object.
Q) why J2EE
A) scalability- b?coz the application can be distributed.
Modularity
Isolation of concerns
Extensible
Maintainability
Q) Y have interfaces with no methods eg ? java.io.Serialisable, java.lang.Clonable, java.rmi.Remote ? Can anyone write answer to this
Q) how do u ensure garbage collector will pick up the object?
A) make the reference to the object null. U can hint the jvm to collect garbage by calling system.gc()
Q) how does indexing help?
A) Indexing is basically a binary tree is generated. The nodes are the key values & physical addresses to the row.
Q) JSP Forward or redirect.
A) Redirect is slow b?coz a new request is created. Forward does not create a new request. RequestDispatcher x = req.getRequestDispather("url"); x.forward(req, res);
Q) what does clone do if not overridden?
A) there are 2 cases in this.
Case1 -If clone is called on object which has only primitive attributes.
Case 2 - If clone is called on onject; which has other object as attributes
Clone is a protected method of Object class. So to invoke on clone, u have to override this method.
For case 1 - u override the clone method & just call super.clone() in order to get ur object cloned.
For case 2 - u override the clone method & write implementation to create a duplicate object of the attribute object of the class. This is required b'coz when u call super.clone() the attributes of the container Object which are object references, the address gets copied to the cloned container object. Hence the cloned container object will point to the same attribute object since the addresses are the same.
Now it creates a new object but the constructor will not be called.
Q) Difference between runtime exception & compile time exception.
A)u have to handle compile time exceptions while u don't have to handle runtime exceptions.
Q) how do u manage state?
A) Session, cookies, database, url rewriting, caching
Q) What is a memory leak in java?
A) Memory leak in java is when a java object cannot be garbage collected.
Q) What all can you synchronize
A) You can synchronize a block, a method, an object, a class
Q) If you have String x="foo"; String y="foo"; String z="foo"; how many instances of "foo" do you get?
A) one since JVM automatically internalizes String. Internalizing means that when string class maintains a pool of Strings. When a new String is created, it checks if the same string is present in the pool. if it is present, it just returns the object from the pool and if not present, the value is added to the pool. I think that automatic internalizing happens only for Strings defined during compile time.
Q)What is typesafe enum
JDBC
Inner Classes
Enterprise Java Beans
EJB Transactions
Design Patterns
Collections
Synchronization
Questions
Q) final ref or final primitive wat is the difference
Q) compile time polymorphism & run time polymorphism
Q) String & StringBuffer- when will u use wat?
Q)When will u use static variable or static method?
Q) Wat if there is an exception in ejbremove? Is the bean instance destroyed? Or it remains?
Q)Does instance of return true for the parent class of the class specified?
Q) How do u convert an int to a string?
Q)How will u implement composition?
Q)What r volatile variables? When r they used?
Q) When to use session bean & when to use entity bean?
Q) CMP vs BMP?
Q) Coarse-grained & fine-grained entity beans?
Q) When will u use interface & when an abstract class?
Q) Include Directive, Include Action
Q) Wat is difference between outer join & inner join?
Q) How do threads communicate with each other
Q) How do u convert a mutable class to immutable?
Q) why J2EE
Q) Y have interfaces with no methods eg - java.io.Serialisable, java.lang.Clonable, java.rmi.Remote ?
Q) how do u ensure garbage collector will pick up the object?
Q) how does indexing help?
Q) JSP Forward or redirect.
Q) what does clone do if not overridden?
Q) Difference between runtime exception & compile time exception.
Q) how do u manage state?
Q) What is a memory leak in java?
Q) What all can you synchronize?
Q) If you have String x="foo"; String y="foo"; String z="foo"; how many instances of "foo" do you get?
Q) What is typesafe enum?
1) JDBC
There are 3 classes associated with JDBC.
java.sql.Driver
java.sql.DriverManager
java.sql.Connection
Generally the procedure is to first register a jdbc driver with the drivermanager. This happens with the Class.forName("
Then connection is requested from the driver manager. The driver manager in turn search through all of the known java.sql.Driver implementations for the one that connects with the URL you provided.
There r 3 kinds of statements
CreateStatement or just Statement
Prepared statement
Callable Statement
Never use create statement. The results r unformatted
Prepared statements execute faster then statements
Callable statement is an extention of prepared statement
Use callable statement while calling SP
The main feature of a PreparedStatement object is that, unlike a Statement object, it is given an SQL statement when it is created. The advantage to this is that in most cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a result, the PreparedStatement object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement 's SQL statement without having to compile it first.
It is possible to update resultset using updateRow() - JDBC drivers are not required to provide this functionality. To specify whether the resultset is updatable, in preparedStatement, add parameter ResultSet.CONCUR_UPDATABLE
2) 5 uses of inner classes:
it allows you to group classes that logically belong together and to control the visibility of one within the other
Each inner class can independently inherit from an implementation. Thus, the inner class is not limited by whether the outer class is already inheriting from an implementation
The inner class can have multiple instances, each with its own state information that is independent of the information in the outer class object.
In a single outer class you can have several inner classes, each of which implement the same interface or inherit from the same class in a different way. An example of this will be shown shortly.
The point of creation of the inner class object is not tied to the creation of the outer class object.
There is no potentially confusing "is-a" relationship with the inner class; it's a separate entity
Disadvantage: the compiler/virtual machine, treats an inner class just like any other class. In order for the inner class to have access to the private variables of the outer class, the variables are made default access - accessible to the package.
3) Enterprise Java Beans
It automatically takes into account - security, resource pooling, persistence, concurrency & transactional integrity
Rmi & iiop provide error & exception handling, parameter passing & passing of transaction & security context
Several clients can be connected to one ejb object, but only one client thread can access the bean instance at a time. If, for example, one of the clients invokes a method on the ejb object, no other client can access that bean instance until the method invocation is complete. If the method is part of a large transaction, then the bean instance cannot be accessed at all, except within the same transactional context, until the entire transaction is complete.
Session bean can never be reentrant & they throw remote exception if a loopback is attempted. Same is true for non-reentrant entity beans. U can make entity bean reentrant by specifying it in the deployment descriptor.
Remove methods are defined in javax.ejb.EJBHome interface. So the home interface inherits them.
ejbCreate method alwayz returns primary key with bmp & null for cmp.
For session bean, return type is void
PortableRemoteObject.narrow is needed to support the requirements of rmi over iiop. Because CORBA supports many different languages, casting is not native to CORBA. Therefore, to get remote reference to home, we must explicitly narrow the object returned by lookup. This has the same effect as casting
All beans have a default jndi context java:comp/env/ejb
EJBHome interface methods
EJBMetaData getEJBMetaData
HomeHandle getHomeHandle
Void remove
EJBMetaData interface methods
EJBHome getEJBHome
Class getHomeInterfaceClass
Class getPrimaryKeyClass
Class getRemoteInterfaceClass
Boolean IsSession
EJBObject interface methods
EJBHome getEJBHome
Handle getHandle
Object getPrimaryKey
Boolean isIdentical
Void remove
when u make a call getByPk,
ejbload happens. the data is put in the entitybean frm db.
the return is the stub. on each invocation of a method on entity bean, a remote call is made. if caching is done, the dta is there in entity bean. ejb load does not happen. So db call is saved.
4) Transactions - EJB
Problems: Dirty reads: a dirty read occurs when the first transaction reads uncommited changes made by a second transaction. If the second transaction is rolled back, the data read by the first transaction becomes invalid.
10:00:00 client 1 chooses cabin 99 to be reserved
10:00:02 client 2 reads the list of reservation. So cabin 99 is not available
10:00:03 client 1 pays. But credit card invalid. So transaction rolled back & cabin 99 is now available
Repeatable reads: a repeatable read is when data read is guaranteed to look the same if read again during the same transaction. A non-repeatable read is when the data retrieved in a subsequent read within the same transaction can return different results.
10:00:00 client 1 reads list of available cabins with 2 beds. Cabin 99 is in the list
10:00:02 client 2 changes bed count from 2 to 3 for cabin 99.
10:00:03 client 1 reexecutes read of list of available cabins with 2 beds. Cabin 99 is still in the list
Phantom read: phantom read occurs when new records added to the db are detectable by the transactions that started prior to the insert.
10:00:00 client 1 reads list of available cabins with 2 beds. Cabin 99 is in the list
10:00:02 client 2 makes a reservation on cabin 99
10:00:03 client 1 reexecutes read of list of available cabins with 2 beds. Cabin 99 is no longer in the list
generally do not use client initiated transaction. B'coz after successfully performing an operation, when the bean returns, it might throw, remote exception. So the client would not know whether the operation happened or no.
if a ejb component sends & receives message in the same component, then it is possible that it will keep on waiting till it receives a message(in relation to jms & mdb). The solution to this problem is - after sending this message, call commit on the jms session, which is your jms transaction helper object. This causes the outgoing message buffer to be flushed.
Transaction attributes to be specified in deployment descriptor
Required - if already within a transaction, then the bean is part of the transaction. If not transaction already started, it starts a new
RequiresNew - if starts a new transaction. If a transaction already exists, then that is suspended & a new transaction is created. When this bean is done, the old transaction is resumed.
Supports - it runs only in a transaction if the client has one- it joins the transaction. If the client does not have a transaction, the bean runs with no transaction at all.
Mandatory - mandates tht a transaction be already running when the bean method is called. If transaction is not running, the javax.ejb.TransactionRequired exception is thrown.
Not Supported - that ur bean cannot be involved in a transaction at all. The transaction is suspended & resumed when the bean method is over.
Never - that ur bean cannot be involved in a transaction at all. If the client calls the bean in a transaction, then java.rmi.remote/javax.ejb.EJBExxception exception is thrown
Transaction isolation attributes
READ_UNCOMMITTED
READ_COMMITTED - transaction cannot read uncommitted data. Data that is being changed by another transaction cannot be read.
REPEATABLE_READ - transaction cannot change data that is being read by another transaction.
SERIALISABLE - transaction has exclusive read & update privileges to data. Other transaction can neither read nor update the same data.
U are allowed to specify isolation levels on per method basis but this flexibility comes with an imp restriction: all methods invoked in the same transaction must have the same isolation level.
In Entity EJB, a transaction spans ejb load, method & ejb store.
In bean managed transactions, u might write transaction begin in ejb load & transaction end in ejb store. But ejb load & ejb store are called by the container. So u can never be sure. The transaction may never end. So bean managed transactions are illegal in entity beans.
In MDB
Container managed transaction, the message is read off in the same transaction as the business logic is executed. If something goes wrong, the transaction will roll back & message acknowledgement will occur.
Bean managed transaction, the transaction begins & ends after the message is received. You can use the deployment descriptor acknowledgement modes to instruct the container about when to acknowledge the messages.
There is no way to specify isolation level in container-managed bean in a portable way.
5) Design Patterns
Singleton
home factory required a single instance of the factory class
when data is cached in a hashtable, a single instance of the hashtable is required
example of factory pattern
ejbhome factory
flyweight pattern
command pattern - struts
here there is an abstract base class called Action. All the other classes extend this action class. They have one command "perform". On button click, the control goes to a common servlet. This servlet (ActionServlet) reads the xml file for the next operation to call. The path info is given as input, stuts config is read & corresponding action class name is obtained. Then on this name, the perform method is invoked.
6) Collections
The collection interface is a group of objects with duplicates allowed
Set interface extends collection but forbids duplicates
List extends Collection also allows duplicates & introduces positional indexing
Map extends neither Set nor Collection & forbids duplicate key
Set
-HashSet
-TreeSet(use it to extract elements in a sorted manner)
it is generally faster to add elements to a hash set then convert the collection to a treeset.
Eg. hashset for sparce matrix
Treeset for JList
List
-ArrayList(random access, without inserting or removing) )(corresponding historical is vector)
-LinkList()(if frequent add & remove elements in the middle of the list and only access elements sequentially)
eg. Arraylist for JcomboBox
Map
-HashMap(inserting, deleting and locating)(corresponding historical is Hashtable & properties)
-TreeMap(traversing the keys in a sorted manner)
Historical List
-Vector (implements List interface)
-Stack (extends vector)
Historical Map
-Hashtable (implements map)
-Properties (implements map extends Hashtable)
Historical collection classes- operations are synchronized.
Iterator u can traverse a collection & safely remove elements from the underlying collection.
If iterator is traversing a collection while underlying collection is being modified by another thread, then the iterator fails by throwing ConcurrentModificationException.
If u need synchronized map, using hashtable is faster then using synchronized hashmap.
Fastest to search is hashtable
Then binary search on sorted collection & quick sort
Can u iterate thru hashmap. - no u have to use entryset in order to convert map to set
7) Synchronization
Synchronized method -Only one thread is executing that method at a time. The object containing the synchronized method is locked..in the sense that no one can call a synchronized method on the same object while the synchronized method is getting executed.
Synchronized block - where u specify the object which is locked . only one thread will execute the block at one time. Useful when shared resource exists in the block of code. Eg. Document series number - u read it, increment it & save the new number. All this should happen only once at a time.
When u have a object in a synchronized method & the same object is accessed by the unsynchronized object, then the unsynchronized object can access that object b?coz since it is unsynchronized, it does not check if the object is locked.
Whenever control enters a synchronized method, the thread that called the method locks the object whose method has been called. Other threads cannot call a synchronized method on the same object until the object is unlocked.
Q) final ref or final primitive wat is the difference
A) if final primitive is used, u cannot change it.
If final ref is used, then u can change the properties of the object but not the address
Q) compile time polymorphism & run time polymorphism
A) overloading is compile time polymorphism. overriding is dynamic or runtime polymorphism.
Q) String & StringBuffer- when will u use wat?
A) String is a constant & Stringbuffer is modifiable.
When there r a lot of string manipulations, u use StringBuffer b'coz otherwise a lot of new objects are created.
Q)When will u use static variable or static method?
A) U use static when u want the variable or method to be accessed at class level without creating an instance of the class.
Typical use of static
· - The proper place to define utility methods (methods that take input and provide output only through passed parameters and the return value) . Methods that don't manipulate or use the state of an object or class I call utility methods
· A way to control access to objects and data. Public class variables are a different story. If a public class variable isn't final, it is a global variable: that nasty construct that is the antithesis of data hiding. There is never any excuse for a public class variable, unless it is final.
Q) Wat if there is an exception in ejbremove? Is the bean instance destroyed? Or it remains? ? can someone answer this question
Q)Does instance of return true for the parent class of the class specified?
A) yes
Q) How do u convert an int to a string?
A)Integer.toString(i);
ToString is a static method of integer. This method takes an interger & returns a String Object. In general what happens when u convert an object to another type or when u convert a primitive to an object
-consider the binary representation of the int & string.i.e. '\u0030' for 0 '\u0031' for 1.
Q)How will u implement composition?
A)Put the code in finalise to delete child objects. As finalise will be called when the parent is getting deleted.
Q)What r volatile variables? When r they used?
A)Volatile variables r variables which are updated each time a change is made to them & checked each time the value is used.
Q) When to use session bean & when to use entity bean?
A)
1) In session bean u can call save operation anytime whenever u wish. So more control. In entity bean, the container decides when to call ejbload & ejbstore methods. So no control.
2) Parameter passing
When u do a query in session bean, u get result set - pass by value
When u call get method on entityhome, u get stubs to server side objects - pass by reference.
In order to display data in gui, the client has to traverse the network if pass by reference is done. Hence performance penalty. U can work around this problem by collocating session bean with the entity bean & serializing the entity bean object before sending it to the client.
3) Caching. Session bean do not represent data hence it cannot be cached. Entity beans can be cached by setting up certain flags in the deployment descriptor. If data is shared, caching offers benefits else it is of no use. Eg of non-shared data is personal account information on amazon.com. eg of shared data is a product catalog of 100 hottest books on amazon.com
4) If entity bean then schema independence. However if session bean crafted correctly gives schema independence. (schema independence is if some column in table is changed, the impact in ejb layer is minimal)
Q) CMP vs BMP?
A)
1) Cmp entity beans if tuned properly, is higher performing than bmp. With bmp, it takes 2 sql stmts to load an entity bean: the finder method(to load primary key) & then ejbload() method.
2) Cmp is harder to debug.
3) Cmp may not handle complex mapping.
4) In cmp no hardcoding of database api such as jdbc. But this feature is imp only to those who r selling their bean to diff ppl with diff db requirements.
5) In ejb2.0 relationships can be mapped. In bmp, lot of scaffolding code has to be written.
Q) Coarse-grained & fine-grained entity beans?
A) One choice u have is to make some of the entity beans as java classes. These r called dependent value classes.
Q) When will u use interface & when an abstract class?
A) U use an interface when u don?t have common code. U use abstract class when u have code that can be shared.
When u want to change implementation behind a common interface, use interface. Eg. In a media player, u might want to change the algorithm that runs to play the media. So when a new algorithm comes up, u just implement that interface & use the new algorithm.
Abstract classes let you define some behaviors; they force your subclasses to provide others. This class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a "random access" data store (such as an array)
Q) include directive <%@ include file="child.jsp" %>
include action
For include directive, JSP Engine adds the content of the inserted page at translation phase, so it does not have an impact on performance.
For include action, JSP Engine adds the content of the inserted page at run time which imposes extra overhead.
Q) Wat is difference between outer join & inner join?
A) Outer join is when you want all rows frm one table & only those rows frm other table which match the value from the table which has all rows.
Inner join is a simple join.
Left outer join is same as left outer join except that in left outer join, the (+) is on right side & in right outer join (+) is on left side.
Full outer join is all rows frm both table.
Q) How do threads communicate with each other
A) Threads communicate with one another thr semaphores or message queues. Semaphore is a integer. One example showing the use of semaphores is when one thread needs to send data (e.g. through a buffer) to another thread. In multithreading environments there is no guarantee in which order two threads will come to the point where the first thread is filling the data buffer and the other thread is reading it. Therefore, these two threads need to synchronize execution at the exchange point. Semaphore's logic for this case is fairly simple: the reader thread calls wait() before reading the buffer and "hangs" if the semaphore is not yet signaled. The writer thread calls post() after filling the buffer with data and thus signals the reader thread that the data buffer is ready. This schema ensures that the data buffer will be read by the second thread only when the data is actually ready
Q) How do u convert a mutable class to immutable?
A)
1. Make the class definition final
2. Remove all setter methods
3. Let the constructor set the attributes of the class
4. Don?t use any method that will change the state of the object.
Q) why J2EE
A) scalability- b?coz the application can be distributed.
Modularity
Isolation of concerns
Extensible
Maintainability
Q) Y have interfaces with no methods eg ? java.io.Serialisable, java.lang.Clonable, java.rmi.Remote ? Can anyone write answer to this
Q) how do u ensure garbage collector will pick up the object?
A) make the reference to the object null. U can hint the jvm to collect garbage by calling system.gc()
Q) how does indexing help?
A) Indexing is basically a binary tree is generated. The nodes are the key values & physical addresses to the row.
Q) JSP Forward or redirect.
A) Redirect is slow b?coz a new request is created. Forward does not create a new request. RequestDispatcher x = req.getRequestDispather("url"); x.forward(req, res);
Q) what does clone do if not overridden?
A) there are 2 cases in this.
Case1 -If clone is called on object which has only primitive attributes.
Case 2 - If clone is called on onject; which has other object as attributes
Clone is a protected method of Object class. So to invoke on clone, u have to override this method.
For case 1 - u override the clone method & just call super.clone() in order to get ur object cloned.
For case 2 - u override the clone method & write implementation to create a duplicate object of the attribute object of the class. This is required b'coz when u call super.clone() the attributes of the container Object which are object references, the address gets copied to the cloned container object. Hence the cloned container object will point to the same attribute object since the addresses are the same.
Now it creates a new object but the constructor will not be called.
Q) Difference between runtime exception & compile time exception.
A)u have to handle compile time exceptions while u don't have to handle runtime exceptions.
Q) how do u manage state?
A) Session, cookies, database, url rewriting, caching
Q) What is a memory leak in java?
A) Memory leak in java is when a java object cannot be garbage collected.
A) You can synchronize a block, a method, an object, a class
Q) If you have String x="foo"; String y="foo"; String z="foo"; how many instances of "foo" do you get?
A) one since JVM automatically internalizes String. Internalizing means that when string class maintains a pool of Strings. When a new String is created, it checks if the same string is present in the pool. if it is present, it just returns the object from the pool and if not present, the value is added to the pool. I think that automatic internalizing happens only for Strings defined during compile time.
Q)What is typesafe enum
Subscribe to:
Posts (Atom)