Tuesday, April 27, 2010

Java Interviwe Questions.

1) What is interface and when to use the abstract class ?
When To Use Interfaces
An interface allows somebody to start from scratch to implement your interface or implement your interface in some other code whose original or primary purpose was quite different from your interface. To them, your interface is only incidental, something that have to add on to the their code to be able to use your package.
When To Use Abstract classes
An abstract class, in contrast, provides more structure. It usually defines some default implementations and provides some tools useful for a full implementation. The catch is, code using it must use your class as the base. That may be highly inconvenient if the other programmers wanting to use your package have already developed their own class hierarchy independently. In Java, a class can inherit from only one base class.

2) Explain System.out.println ?
System is a predefined final class,
out is a PrintStream object and
println is a built-in overloaded method in the out object.

3) What we will get if System.out.println(null) and why?
Compilation error

4) How to create the immutable class with the properties as name and date ? tell any 2 ways ???
5) How to find out ip address of the java address ?
6) How to read the last 100 lines in a 1GB file ?
7) How can we find the free memory in java ?
8) Will the immutable objects impact the Garbage collection ? Are the immutable objects are good or bad for GC?
9) Open a file à modify the file àclose the file à where can we close the file ?
10) For (1 to 100) { string str =”Hello” } how many string objects are created in the for loop ?
11) Basic structure of Hash table? Code to write our own hash table ? create a class , 2 properties like key and value.. use collection to do it ……. What makes the hash table as so fast ??
12) How to you write a singleton class… implements serializes …but can we make them deserialiable .. what method .. any type single ton method.. which method we need to override … clone()
13) How do you create a connection? load the driver manager ?
14) How to execute a sql statement using java
15) If the invoke a close() under a statements … will the resultSet object will be closed ?
16) How many resultsets can we have for a statement ?
17) Out of memory .. how can we resolve the error ??? which method we are supposed to use ????
18) What are cursors .. ??? what is purpose of cursors ….
19) How do insert data to DB using JDBC ? excuteUpdate() or excute() what are the other ways ????
20) Resultset .insertRow ()
21) Diff between Forward() and sendRedirect () ?
22) We have servlets .. how can measure execution time of a servlets ? suppose we have login logic ???
23) What is doPost() ? how do we get the doPost() execution time ???
24) How can find no. of requests comings to a web application ???
25) Every time any request comes to web application , we want to write some info into log file.. what methods we use ?
26) A jsp returns a message “Welcome “ … the jsp can’t be modified by us… how can change the “welcome” message to “Goodbye “ ?
27) How do we implements filter ?
28) What is design pattern used in Struts ? MVC
29) How many Action servlets object can be there in struts ?
30) In struts , how can I pass my objects to actionServlet … simultaneous 2 or more
31) Extend the actionServlet .. which method we are suppose to override ? excute () ?
32) Jsp page … form à button à send a button .. click multiple times.. multiple times the files has been sent ?? how can we slove this … that only one time the files has to sent instead of multiple times ….. in struts and normal ???
33) Anyone can access the page.. one can access the file.. other can’t access the page .. access controller API ???
34) What is outer join?
35) What is biff between outer join and inner join?
36) Syntax to create a SP…
37) Table , varchar filename, filesDesc .. data is case sensitive ???
38) File table … fileID ,filename , file table is very huge …. To run the query .. it is taking 10 min… how can we tune the query ?????
39) Is the data in Oracle is case sensitive ?
40) How to execute the SP in SQL+ ?
41) How do we parse XML in java ?
42) Diff between SAX and DOM ?
43) How to we modify the XML as a well-formed??
44) How can we know that some attribute has been set to the session?
45) How can we make sure that parent class method is going to modify by the child class ?
46) What is a thread dump?
47) How many sockets can w open in Java at a time ?
48) How do we create server socket ?
49) What are features of JDK 1.5 ?
50) What are Auto switch Jobs ?
51) Difference between CVS and SVN ?
52) What is object in JavaScript?
53) How do we solve the memory leaks in java ? when do the memory leaks occur ?
54) How do we debug a jsp in product env .?
55) How to select different targets in Ant?
56) What is the root element in Ant?
57) How do we know that some events are happening in Java ?
58) Difference between doPost() and doGet() ?
59) How do we make the singleton as 100% even in 2 JVMS ?
60) What is thread Local class?
61) How do we delete a file in Java?
62) Dif between string buffer and string builder and string?
63) We have 32 bit JVM, but we are going to read 3GB data,, due to this we are going to get out of memory.. how we are going to handle the situation suing JDBC ?
64) Other way to insert data using JDBC other than execute() ?
65) What is setrogated key in DB ?
66) How would we create a object which is similar to hash table ?
67) How can we create a single ton class which implements serializable ?
68) How many ways can we create instance in java ?
69) what is the difference b/w request.getAttribute & getPrameter

To clarify just a bit. Parameters in a request are set there by the HTML client when the request is created, typically from elements (input and file elements to be exact) within an HTML form. Therefore if the form that called your servlet/JSP page had an element with a name "fred", you would retrieve the value of that form element by using getParameter("fred"). An HTML form does not set attributes, only parameters.Attributes are set programatically. If you set an attribute, then you can get it. This is typically done by a servlet or java POJO that either does some pre-processing and sets some additional attribute values, or one that processes the request, finds errors and therefore sets attributes and returns the request back to the originator. The originator may look for these attributes (for example error messages) and display them. You don't programatically set parameters, only attributes. -
70) how to change the port number in tomcat -- RUNNING.txt

71) where does the Ajax lies – both in the server side & client side…

72) what is the default port number of oracle – 80

73) What are the different transaction mgt in spring?

74) 6) where exactly we deploy the war file in tomcat --- webapps

75) what is the configuration we need to make to configure the debug mode in the eclipse – just run in the debug mode..
76) what are steps to configure the Tomcat with eclipse ..

77) what are inner joins & outer joins -

In outer Join some extra rows will come but in the inner join we get only the common rows. There is no option for the outer join to add the left or right joins..

78) how the resultSet maps to the data fetched from the query?



79) How can we make the code as synchronized w/o using the synchronized key word.
Use the Lock concept in JDK1.5
12) How Log4J works internally? What are the severity levels in it?
13) what is diff/bt warning & bug in log4J?
14) what are the advantages of the inheritance & polymorphism?
15) How do we send the java objects to the stored procedures?
16) how do we the session object in the servlet?
Http Session session = request.getSession(true);
*) why do we need a protocol specific sessions.
17) can we call abstract method in the non abstract () – yes.
18) Inheritance advantages
19) why we need so many layers in our project?
20) how can make sure that the implementing class will call the non shape.. color..
21) with using normal joins .. how many rows will get? no of rows of first table * no of rows in 2nd table
22) Implementation of the Abstraction & exact meaning of Abstraction?
23) Implementation of the Encapsulation
24) what is the significant of the user- defined exception?
25) is synchronized is the access modifier?
26) multicasting? – During the java sockets we need to use the multicasting.
27) main() of one class can be called in other class? - yes
28) throw & throws & throwable?
29) can a static class be there? No
30) Different methods in Redirecting the servlets? – RequestDispatcher.farward() & response.sendRedirect()
31) Advantages of the datasources over JDBC?
32) Abstract Factory pattern?
33) Inner Joins, outer joins & normal joins?
34) What algorithm does the Garbage collector uses?
35) How many static blocks can a class can have?
36) How to sort the arraylist.. – sort().
37)JDBC steps….
38) DriverManager is a interface or a class? - class
39) What does Class.forName return? - returns the class instances that representing the class….
Mainly it loads the class & returns the instatnce of the given class.
40) What are the ways to create an instance of the class?
a. Using new operater
b. Using the class.forname(“fdgdf ”).newInstance()
c. Using the deserialization
d. Using clone
41) Examples of the checked exceptions – FileNotFound.
42) How a Stored Procedure returns more than one RS.
a. Rs.getMoreResultset(), it also has rs.hasMoreResult.
43) How to pass an object to the Stored Procedure?
44) What is a RequestDispatcher?
a. RequestDispatcher dispatcher = getServletConfig ( ) .getServletContext ( ) .getRequestDispatcher ( "/"file_name ) ; dispatcher.forward ( request, response ) ;
b. ServletContext sc = getServletContext ( ) ; RequestDispatcher rd = sc.getRequestDispatcher ( url ) ; rd.forward ( req, res ) ;
45) Can a abstacr class contains the full nonabstact class?
46) Is it illegal to have a abstact modifier infornt of a interface method?
47) How can you pass the error page in the jsp…
a. In web.xml :
i.

java.lang.NullPointerException

/NPEerror.html






404
/errorServlet
48) Implict objects in Java?
49) How can we store the objects of the e.printstactTrace into a string & store into a DB?
a. StringWritter sw = new StringWritter(e.printStactTrace());
b. PrintWritter pw = new printwritter(sw);
c. String str = sw.tostring();
d. Store the str in the DB.
50) How do you handle Nullpointer exception?

Tuesday, March 9, 2010

Dynamic table creation using JSON objects.

Hi,
Here is an example for creating dyanmic table using JSON objects.

script type="text/javascript"

// Adding the rows to tbody. From the html we will call the below function.
function displayRows(jsonString){
var tableBody = document.getElementById("QuestionBody");
// Clears the table row contents initally.
while (tableBody.firstChild) {
tableBody.removeChild(tableBody.firstChild);
}
// Fetches the size of the JSON object and creates that many rows.
for(i=0; ivar row = document.createElement('tr');
createTableData(row, jsonString[i]);
tableBody.appendChild(row);
}
document.getElementById("QuestionBody").appendChild(tableBody);
jQuery('#QuestionTable').show();
jQuery('table').Scrollable(100, 800);
}

function createTableData(rowObject, data){
createTableRowContent(rowObject, data, 'td');
}
// Adding the actuall data content to the td.
function createTableRowContent(rowObject, data, cellType){
var rowContent = document.createElement(cellType);
var cell = document.createTextNode(data);
rowContent.appendChild(cell);
rowObject.appendChild(rowContent);
}
/script

Friday, March 5, 2010

Ways to fetch values using Hibernate

There are 3 ways to fetch values using Hibernate.
1) Using the HQL : just write the query in hql and map the tables to Classes and also the columns to attributes in the Class.
Ex:
String queryString = "select columName from tableX where columName like '%"+name+"%'";
List str = getHibernateTemplate().find(queryString);
Note : here in hql we are supposed to use the table attributes as column name and class names as table name.

2) Fetch directly with out using the query statement at all.
Ex : this.getSession().createCriteria(XXX.class).list();

3) write the query in the hbm.xml file and call the query from java file.
Ex :
In the java file :
getHibernateTemplate().findByNamedQuery("selectAllLike", x.trim());
In the hbm file define the selectAllLike query statement like

sql-query name="selectAllLike"
return alias="component" class="com.bofa.osm.hibernate.Component"
SELECT * FROM COMPONENT c WHERE upper(c.NAME) LIKE upper(?)
sql-query

Note : sql-query ans return are the tags.
Cheers
DeepthiMahesh

Friday, February 5, 2010

Food for thought

If you want to make the right decisions in confusing times—Time to refinance? Explore a different career? Root for the singing spinster or the 12-year-old?—you need to pay special attention to what you eat. That’s right: Your grocery list can help with your to-do list. That’s because the right foods are a kind of clean-burning fuel for your body’s biggest energy hog: Your brain. A study in the Journal of Physiology makes the point that, though your brain represents only 2 percent of your body weight, it makes 20 percent of the energy demands on your resting metabolism. On our new Eat This, Not That! Web site, we rounded up the best foods to munch on when you need a mental boost—and found studies that show, in fact, that you can be up to 200 percent more productive if you make the right eating choices. Stock up on these items to halt mental decline, jog your memory, sharpen your senses, improve your performance, activate your feel-good hormones, and protect your quick-witted sharpness, whether you’re 15, 40—or not admitting to any age whatsoever! FOR SHORT-TERM MEMORYDrink This!: COFFEEFresh-brewed joe is the ultimate brain fuel. Caffeine has been shown to retard the aging process and enhance short-term memory performance. In one study, British researchers found that just one cup of coffee helps improve attention and problem-solving skills. Not That!: ENERGY DRINKS/TOO MUCH COFFEEEver heard of the concept “too much of a good thing”? If you OD on caffeine—too many cups, a jolt of caf from the late afternoon onward, a Red Bull cocktail—it can mess with your shuteye schedule. Sleep is reboot time for your mental computer, and you don’t want to mess with it.FOR LONG-TERM MEMORYEat This!: BLUEBERRIESAntioxidants in blueberries help protect the brain from free-radical damage and cut your risk of Alzheimer’s and Parkinson’s diseases. They can also improve cognitive processing (translation: thinking). Wild blueberries, if you can find them, have even more brain-boosting antioxidants than the cultivated variety, so book that vacation in Maine now. The berries will ripen in July. Not That!: THE UNRIPE AND UNREADYHere’s a cool tip: if your favorite berries are out of season, buy them frozen. The freezer locks in peak flavor and nutrients, so the berries’ antioxidant capacity is maxed out. Those pale, tough, and expensive off-season berries usually ripen on a truck, rather than on the bush, so they’re nutritional imposters compared to the real thing.For more smart shopping tips, point your grocery cart to THIS story and learn how to pick the most delicious and nutritious while controlling your waistline! TO THINK FASTEREat This!: SALMON OR MACKERELIf the Internal Revenue Service picks you for some up-close-and-personal auditing, you’ll want to be on your toes when they vet your deductions list. So put salmon or mackerel on the grocery list. The omega-3 fatty acids found in fatty fishes are a primary building block of brain tissue, so they’ll amp up your thinking power. Salmon is also rich in niacin, which can help ward off Alzheimer’s disease and slow the rate of cognitive decline. Not That!: FULL-FAT ICE CREAMNot all fats are created equal: Beware foods high in saturated fats, which can clog blood vessels and prevent the flow of nutrients and blood to the brain. Ice cream is not a brain-health food. TO ENERGIZE:Eat This!: HIGH-PROTEIN SALAD WITH VINAIGRETTEThe oil in the dressing will help slow down digestion of protein and carbs in the salad, stabilizing blood-sugar levels and keeping energy levels high. Build your salad on a bed of romaine and spinach for an added boost in riboflavin, and add chicken and a hard-boiled egg for more energizing protein. Not That!: PANCAKES OR BAGELSMIT researchers analyzed blood samples from a group of people who had eaten either a high-protein or a high-carbohydrate breakfast. Two hours after eating, the carb eaters had tryptophan levels four times higher than those of the people who had eaten protein. The tryptophan in turkey is one of the reasons you crawl off for an afternoon nap after Thanksgiving dinner. So watch what you gobble.TO CALM DOWNEat This!: LOW-FAT YOGURT OR MIXED NUTSScientists in Slovakia gave people 3 grams each of two amino acids—lysine and arginine—or a placebo, and asked them to deliver a speech. Blood measurements of stress hormones revealed that the amino acid-fortified guys were half as anxious during and after the speech as those who took the placebo. Yogurt is one of the best food sources of lysine; nuts pack loads of arginine. Not That!: SODAA study from the American Journal of Public Health found that people who drink 2½ cans of soda daily are three times more likely to be depressed and anxious, compared with those who drink fewer. So Mountain Dew is a Mental Don’t. TO CONCENTRATEEat This!: PEPPERMINT TEAThe scent of peppermint helps you focus and boosts performance, according to researchers. Need to reach Chicago before nightfall, and you’re stuck in traffic around Cleveland? One study found that peppermint makes drivers more alert and less anxious. Not That!: CANDYSugary foods incite sudden surges of glucose that, in the long term, cause sugar highs and lows, leading to a fuzzy state of mind. So you’ll need to avoid all the attention-busting sugar bombs on this list of the 20 most sugar-packed foods in America. FOR GOOD MOODS AND GRINSEat This! ARUGULA OR SPINACH SALADLeafy greens—arugula, chard, spinach—are rich sources of B vitamins, which are key components on the assembly line that manufactures feel-good hormones such as serotonin, dopamine, and norepinephrine. According to a study published in the Journal of Neuroscience Nursing, a lack of B6 can cause nervousness, irritability, and even depression. Not That!: WHITE CHOCOLATEWhite chocolate isn’t chocolate at all, since it contains no cocoa solids. So it won’t stimulate the euphoria-inducing mood boosters like serotonin, as real chocolate does. Grab the real thing, the darker the better. More cacao means more happy chemicals and less sugar, which will eventually pull you down. FOR SHARPER SENSESEat This!: 1 TBSP OF GROUND FLAXSEED DAILYFlax is the best source of alphalinoleic, or ALA—a healthy fat that improves the workings of the cerebral cortex, the area of the brain that processes sensory information, including that of pleasure. To meet your quota, sprinkle it on salads or mix it into a smoothie or shake. Not That!: ALCOHOLThis one’s obvious, but worth mentioning anyway. A drink or two can increase arousal signals, but more than that will actually depress your nervous system. This makes you sloppy, not sharp.


Work for a Cause, not applause. Live to express, not to impress...

Life is short make it sweet.
Satish

The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.