life ideas

November 9, 2007

Java Interview Questions

Filed under: Uncategorized — manoftoday @ 1:50 am

1. Java says “write once, run anywhere”. What are some ways this isn’t quite true? Any time you use system calls specific to one operating system and do not create alternative calls for another operating system, your program will not function correctly. Solaris systems and Intel systems order the bits of an integer differently. (You may have heard of little endian vs. big endian) If your code uses bit shifting, or other binary operators, they will not work on systems that have opposide endianism.

2. What’s the difference between == and equals method? The typical “gotcha” for most people is in using == to compare two strings when they really should be using the String class’s equals() method. From above, you know that the operator will only return “true” when both of the references refer to the same actual object. But, with strings, most uses want to know whether or not the value of the two strings are the same — since two different String objects may both have the same (or different) values.

3. two types of stream

basically there are 2 types of streams.

byte streams that are used to handle stream of bytes and character streams for handling streams of characters.

in byte streams inputStream/outputStream are the abstract classes at the top of hierarchy,while writer/reader are abstract classes at the top of character streams hierarchy.

4.What class allows you to read objects directly from a stream? The ObjectInputStream class supports the reading of objects from input streams.

5. Can you write Java code for declaration of multiple inheritance in Java ? Class C extends A implements B { }

6. Given two tables Student(SID, Name, Course) and Level(SID, level) write the SQL statement to get the name and SID of the student who are taking course = 3 and at freshman level.


FROM Student, Level

WHERE Student.SID = Level.SID AND Level.Level = “freshman” AND Student.Course = 3;

7. advantagesof OOPL The features of OOPL as inheritance, polymorphism, encapsulation makes it powerful.

8. marker interfaces in java except Serializable.



An interface having no methods is called as a Marker Interface.

9. instanceof() vs isInstance()

Point pt = new Point(3, 4);


System.out.println(“Is pt a String? [using instanceof] ” +

((Object)pt instanceof String));



try {


“Is pt a String? [using isInstance()] ” +

(Class.forName(“java.lang.String”).isInstance(pt))); //you need a Class object.


catch(Throwable e) {



10. Are constructors inherited? Can a subclass call the parent’s class constructor? When? You cannot inherit a constructor. By giving the developer the ability to override a superclasses onstructor you would erode the encapsulation abilities of the language. but you can call the parent’s class constructor. 

11. synchronization

When you synchronize on an object your thread gains exclusive use of that object until synchronization ends or wait is called on the object.Language support for synchronization:

1. Use the synchronized block:

In a method you may: synchronized(object) { code here }

synchronized(SomeClass.class) { code here }

 In the first case access to the instance variables/methods of the class are synchronized.

In the second case access to the static methods/fields are synchronized.

2. Declare the method synchronized:

public synchronized foo() { code here }

public static synchronized foo() { code here }

These two act just like synchronized(this) or synchronized(MyClass.class) (depending if the method is static or not).

In addition the Object class defines the wait, notify, notifyAll, and sleep methods. To execute any of these methods the object must be in a synchronized block (this can be in a calling method). The compiler will not check this, a runtime error will be thrown if this is not the case. The wait method temporaly releases the lock on the object. The notify/notifyAll method allows a previously waiting thread to continue to execute.

Also when executing the static block of a class: public class Foo { static { code here } } A special lock is placed on the class, this lock is different from the synchronized lock, as no other thread may access the class until the static block is done.

12. access control

Public : Any other class from any package can instantiate and execute the classes and methods.

Protected : Only classes inside of the package and subclasses can access the classes and methods.

Private : The original class is the only class allowed to execute the methods.

Default : Only classes inside of the package can access the classes and methods.

13. JDBC steps

The standard steps to connecting the database as follows:


      1: Loading the drivers Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);

      2:Getting the connection Connection con=DriverManager.getConnection(“jdbc:odbc:datasourcename”,”scott”,”tiger”);

      3:Create the Statement Statement st=con.createStatement();

      4:Execute the Statement ResultSet rs=st.executeQuery(“select * from emp”);

      5:Accessing the data from the backend


                        System.out.println(rs.getString(1)); System.out.println(rs.getInt(2)); System.out.println(rs.getString(3));

      6:close the connection }catch(SQLException se) { se.printStackTrace(); } finally{ con.close(); rs.close(); st.close(); }

14. java different from c++;

         java : no goto; no destructor;has garbage collection;

         Java has method overloading, but no operator overloading.

        java package;     c++: namespace

15. String abc= “xyz”;

 Important to note that you are NOT calling a java.lang.String constuctor when you type String s = “abc”; For example String x = “abc”; String y = “abc”; refer to the same object. While String x1 = new String(“abc”); String x2 = new String(“abc”); refer to two different objects. 

16. Java Network Programming

 Java supports “low-level” and “high-level” classes.

“Low-level” classes provide support for socket programming: Socket, DatagramSocket, and ServerSocket classes.

“High-level” classes provide “Web programming”: URL, URLEncoder, and URLConnection classes. Networking programming classes ease the programming of network applications, but do not substitute your knowledge of networking. Java networking like anything else in Java is platform-independent.

17.  unreachable object becomes reachable. An unreachable object may become reachable again. This can happen when the object’s finalize() method is invoked and the object performs an operation which causes it to become accessible to reachable objects.

18. modifiers for top class   A top-level class may be public, abstract, or final.

19. default value of boolean The default value of the boolean type is false.

20. Expain the reason for each keyword of public static void main(String args[])?

public- main(..) is the first method called by java environment when a program is executed so it has to accessible from java environment. Hence the access specifier has to be public.

static: Java environment should be able to call this method without creating an instance of the class , so this method must be declared as static.

void: main does not return anything so the return type must be void

The argument String indicates the argument type which is given at the command line and arg is an array for string given during command line.

21. What is the difference between Abstract class and …

1. Abstract Class may contains constructor but interface does not contain constructor.
2.By default, all variables in interfaces are static and final,then we can’t declare method as final.
3.In Interface all methods shuld be public but mot in abstract class.
4.interface supportes multiple inheritance but abstract class does not support.
5.we should initialise variables in interface but not necessory in abstract class.

6.interface has no method implementation.




22. How to track “memory leak” and how to prevent it i…

To reduce possibility of memory leaks, following things should be kept in mind.

Try to avoid long recursive loops in the code. This leads to an OutOfMemoryError.

Avoid collections as static members of a class. If so, carefully manage removals and additions to the Collection. If the collection continues adding members without removing them, it might lead to a leak. Static members persist throughout the life of the program. A static collection will keep references to objects, whether you are using it or not. So the garbage collector might miss collecting the unused contents of the collection.

Avoid populating the HttpSession with too much data. Session persists in the system as long as the user is online, and it might get filled up fast. Additions and removals in the session should be checked.

If you are using AWT/Swing components, call dispose() to kill the windowing component completely.

Check your native code for memory leaks, if you are calling C/C++ code from Java using JNI.

There are other things too, to take care of, but these are the most important ones.

tool: JProbe Memory debugger


Filed under: Uncategorized — manoftoday @ 12:45 am

behavior questions.

1. So, tell me a little about yourself.
You don’t need to explain everything from birth to present day. Relevant facts about education, your career and your current life situation are fine.

2. Why are you looking (or why did you leave you last job)?
This should be a straightforward question to answer, but it can trip you up. Presumably you are looking for a new job (or any job) because you want to advance your career and get a position that allows you to grow as a person and an employee. It’s not a good idea to mention money here, it can make you sound mercenary. And if you are in the unfortunate situation of having been downsized, stay positive and be as brief as possible about it. If you were fired, you’ll need a good explanation. But once again, stay positive.

3. Tell me what you know about this company.
Do your homework before you go to any interview. Whether it’s being the VP of marketing or the mailroom clerk, you should know about the company or business you’re going to work for. Has this company been in the news lately? Who are the people in the company you should know about? Do the background work, it will make you stand out as someone who comes prepared, and is genuinely interested in the company and the job.

4. Why do you want to work at X Company?
This should be directly related to the last question. Any research you’ve done on the company should have led you to the conclusion that you’d want to work there. After all, you’re at the interview, right? Put some thought into this answer before you have your interview, mention your career goals and highlight forward-thinking goals and career plans.

5. What relevant experience do you have?
Hopefully if you’re applying for this position you have bags of related experience, and if that’s the case you should mention it all. But if you’re switching careers or trying something a little different, your experience may initially not look like it’s matching up. That’s when you need a little honest creativity to match the experiences required with the ones you have. People skills are people skills after all, you just need to show how customer service skills can apply to internal management positions, and so on.

6. If your previous co-workers were here, what would they say about you?
Ok, this is not the time for full disclosure. If some people from your past are going to say you’re a boring A-hole, you don’t need to bring that up. Stay positive, always, and maybe have a few specific quotes in mind. “They’d say I was a hard worker” or even better “John Doe has always said I was the most reliable, creative problem-solver he’d ever met.”

7. Have you done anything to further your experience?
This could include anything from night classes to hobbies and sports. If it’s related, it’s worth mentioning. Obviously anything to do with further education is great, but maybe you’re spending time on a home improvement project to work on skills such as self-sufficiency, time management and motivation.

8. Where else have you applied?
This is a good way to hint that you’re in demand, without sounding like you’re whoring yourself all over town. So, be honest and mention a few other companies but don’t go into detail. The fact that you’re seriously looking and keeping your options open is what the interviewer is driving at.

9. How are you when you’re working under pressure?
Once again, there are a few ways to answer this but they should all be positive. You may work well under pressure, you may thrive under pressure, and you may actually PREFER working under pressure. If you say you crumble like aged blue cheese, this is not going to help you get your foot in the door.

10. What motivates you to do a good job?
The answer to this one is not money, even if it is. You should be motivated by life’s noble pursuits. You want recognition for a job well done. You want to become better at your job. You want to help others or be a leader in your field.

11. What’s your greatest strength?
This is your chance to shine. You’re being asked to explain why you are a great employee, so don’t hold back and stay do stay positive. You could be someone who thrives under pressure, a great motivator, an amazing problem solver or someone with extraordinary attention to detail. If your greatest strength, however, is to drink anyone under the table or get a top score on Mario Kart, keep it to yourself. The interviewer is looking for work-related strengths.

12. What’s your biggest weakness?
If you’re completely honest, you may be kicking yourself in the butt. If you say you don’t have one, you’re obviously lying. This is a horrible question and one that politicians have become masters at answering. They say things like “I’m perhaps too committed to my work and don’t spend enough time with my family.” Oh, there’s a fireable offense. I’ve even heard “I think I’m too good at my job, it can often make people jealous.” Please, let’s keep our feet on the ground. If you’re asked this question, give a small, work-related flaw that you’re working hard to improve. Example: “I’ve been told I occasionally focus on details and miss the bigger picture, so I’ve been spending time laying out the complete project every day to see my overall progress.

13. Let’s talk about salary. What are you looking for?
Run for cover! This is one tricky game to play in an interview. Even if you know the salary range for the job, if you answer first you’re already showing all your cards. You want as much as possible, the employer wants you for as little as you’re willing to take. Before you apply, take a look at for a good idea of what someone with your specific experience should be paid. You may want to say, “well, that’s something I’ve thought long and hard about and I think someone with my experience should get between X & Y.” Or, you could be sly and say, “right now, I’m more interested in talking more about what the position can offer my career.” That could at least buy you a little time to scope out the situation. But if you do have a specific figure in mind and you are confident that you can get it, I’d say go for it. I have on many occasions, and every time I got very close to that figure (both below and sometimes above).

14. Are you good at working in a team?
Unless you have the I.Q. of a houseplant, you’ll always answer YES to this one. It’s the only answer. How can anyone function inside an organization if they are a loner? You may want to mention what part you like to play in a team though; it’s a great chance to explain that you’re a natural leader.

15. Tell me a suggestion you have made that was implemented.
It’s important here to focus on the word “implemented.” There’s nothing wrong with having a thousand great ideas, but if the only place they live is on your notepad what’s the point? Better still, you need a good ending. If your previous company took your advice and ended up going bankrupt, that’s not such a great example either. Be prepared with a story about an idea of yours that was taken from idea to implementation, and considered successful.

16. Has anything ever irritated you about people you’ve worked with?
Of course, you have a list as long as your arm. But you can’t say that, it shows you as being negative and difficult to work with. The best way to answer this one is to think for a while and then say something like “I’ve always got on just fine with my co-workers actually.

Use this question as a chance to show that you are a team player: “The only people I have trouble with are those who aren’t team players, who just don’t perform, who complain constantly, and who fail to respond to any efforts to motivate them.” The interviewer is expecting a response focused on personality and personal dislikes. Surprise her by delivering an answer that reflects company values

17. Is there anyone you just could not work with?
No. Well, unless you’re talking about murderers, racists, rapists, thieves or other dastardly characters, you can work with anyone. Otherwise you could be flagged as someone who’s picky and difficult if you say, “I can’t work with anyone who’s a Bronco’s fan. Sorry.”

18. Tell me about any issues you’ve had with a previous boss.
Arrgh! If you fall for this one you shouldn’t be hired anyway. The interviewer is testing you to see if you’ll speak badly about your previous supervisor. Simply answer this question with exteme tact, diplomacy and if necessary, a big fat loss of memory. In short, you’ve never had any issues.

The answer to 18 is completely wrong. I am a director at a major media company’s interactive division. Our company is expanding and I am almost in a constant state of hiring. I ask a variation of this question in every single interview and if a candidate has never had one issue or disagreement with anyone, (I stated a variation: I ask if it has happened with anyone in the workplace) I peg them as a liar and reject them immediately.

I went well with my previous boss. If there is an conflict, I will be open mind and talk about facts. once decision is made, I execute it well.

19. Would you rather work for money or job satisfaction?
It’s not a very fair question is it? We’d all love to get paid a Trump-like salary doing a job we love but that’s rare indeed. It’s fine to say money is important, but remember that NOTHING is more important to you than the job. Otherwise, you’re just someone looking for a bigger paycheck.

20. Would you rather be liked or feared?
I have been asked this a lot, in various incarnations. The first time I just drew a blank and said, “I don’t know.” That went over badly, but it was right at the start of my career when I had little to no experience. Since then I’ve realized that my genuine answer is “Neither, I’d rather be respected.” You don’t want to be feared because fear is no way to motivate a team. You may got the job done but at what cost? Similarly, if you’re everyone’s best friend you’ll find it difficult to make tough decisions or hit deadlines. But when you’re respected, you don’t have to be a complete bastard or a lame duck to get the job done.

21. Are you willing to put the interests of X Company ahead of your own?
Again, another nasty question. If you say yes, you’re a corporate whore who doesn’t care about family. If you say no, you’re disloyal to the company. I’m afraid that you’ll probably have to say yes to this one though, because you’re trying to be the perfect employee at this point, and perfect employees don’t cut out early for Jimmy’s baseball game.

it is situational. if you… ; if you …. Ethics and professionalism


22. So, explain why I should hire you.
As I’m sure you know, “because I’m great” or “I really need a job” are not good answers here. This is a time to give the employer a laundry list of your greatest talents that just so happen to match the job description. It’s also good to avoid taking potshots at other potential candidates here. Focus on yourself and your talents, not other people’s flaws.

23. Finally, do you have any questions to ask me?
I’ll finish the way I started, with one of the most common questions asked in interviews. This directly relates to the research you’ve done on the company and also gives you a chance to show how eager and prepared you are. You’ll probably want to ask about benefits if they haven’t been covered already. A good generic one is “how soon could I start, if I were offered the job of course.” You may also ask what you’d be working on. Specifically, in the role you’re applying for and how that affects the rest of the company. Always have questions ready, greeting this one with a blank stare is a rotten way to finish your interview. Good luck and happy job hunting.

ponder for a moment, and then ask your interviewer “what aspect of your job do you find most challenging”.

I would ask the interviewer, “Why do you like to work here?”

24. Where do you want to be in 5 to years?

They dont want to hear in the same job you are interviewing for. Ultimately, the HR people are searching for someone who can handle the job now, and has the potential to grow into a high level management job in the future. Do you have those goals too?

24. Would you rather work for a big company or a small one?

Favorite answer: I’d treat any company like it was my own regardless. Total ownership of the situation can get you a long way.

General , the worst answer was “I don’t know.” I’ve since learned that “it depends,” with a couple of examples, is perfectly appropriate.

Blog at