YOUR FEEDBACK
iPhone Keyboard and How to Use It?
MIchael Daitzman wrote: Very important to make sure you know that the note...
Did you read today's front page stories & breaking news?

2007 East

  Diamond Sponsor:  
Laszlo
The Browser, the Portal, and the Desktop

  Platinum Sponsors:  

Adobe
'HDUX' - High Definition User Experience with Flex & Apollo
Cynergy
It Takes A Village: Building a World Class RIA Development Group
JackBe
The User is the Killer App. Empower Them!
Tibco
AJAX RIAs and the Service-Oriented Platform

      Gold Sponsors:     
Backbase
AJAX Best Practices
Helmi
Helmi Open Source RIA Platform
ICESoft
Secure Enterprise AJAX with ICEfaces
JetBrains
Is An IDE the Fifth Wheel or Sixth Sense?
Kapow
Serving Mashups from the Long Tail of the Web
Nexaweb
Enterprise Web 2.0 - Programming with Levers, Dials and maybe Switches
Click For 2006 Event Webcasts
SYS-CON.TV
TOP THREE LINKS YOU MUST CLICK ON


Secrets Of The Masters: Core Java Job Interview Questions
JDJ Enterprise Editor Yakov Fain Offers 30 Core Java Questions You Might Expect During Job Interviews

Digg This!

Page 1 of 2   next page »

JDJ's Enterprise Editor, Yakov Fain (pictured) writes: If you are planning to hit the job market,  you may need to refresh some of the Java basic terms and techniques to prepare yourself for a technical interview. Let me offer you some of the core Java questions that you might expect during the interviews. 

For  most questions  I’ve provided only  short  answers to encourage further research.  I have included only  questions for mid (*) and senior level (**) Java developers. These sample questions could also become handy for people who need to interview Java developers (see also the article "Interviewing Enterprise Java Developers").

30 Java Interview Questions

* Q1. How could Java classes direct program messages to the system console, but error messages, say to a file?

A. The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:

Stream st = new Stream(new FileOutputStream("output.txt")); System.setErr(st); System.setOut(st); 

* Q2. What's the difference between an interface and an abstract class?

A. An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.

* Q3. Why would you use a synchronized block vs. synchronized method?

A. Synchronized blocks place locks for shorter periods than synchronized methods.

* Q4. Explain the usage of the keyword transient?

A. This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).

* Q5. How can you force garbage collection?

A. You can't force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.

* Q6. How do you know if an explicit object casting is needed?

A. If you assign a superclass object to a variable of a subclass's data type, you need to do explicit casting. For example:

Object a; Customer b; b = (Customer) a;

When you assign a subclass to a variable having a supeclass type, the casting is performed automatically. 

* Q7. What's the difference between the methods sleep() and wait()

A. The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.

* Q8. Can you write a Java class that could be used both as an applet as well as an application?

A. Yes. Add a main() method to the applet.

* Q9. What's the difference between constructors and other methods?

A. Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.

* Q10. Can you call one constructor from another if a class has multiple constructors

A. Yes. Use this() syntax.

* Q11. Explain the usage of Java packages.

A. This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes.

* Q12. If a class is located in a package, what do you need to change in the OS environment to be able to use it?

A. You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let's say a class Employee belongs to a package com.xyz.hr; and is located in the file c:\dev\com\xyz\hr\Employee.java. In this case, you'd need to add c:\dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows:

c:\>java com.xyz.hr.Employee
 
* Q13. What's the difference between J2SDK 1.5 and J2SDK 5.0?

A.There's no difference, Sun Microsystems just re-branded this version.

* Q14. What would you use to compare two String variables - the operator == or the method equals()?

A. I'd use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object.

* Q15. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?

A. Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first.

* Q16. Can an inner class declared inside of a method access local variables of this method?

A. It's possible if these variables are final.

* Q17. What can go wrong if you replace && with & in the following code:

String a=null; if (a!=null && a.length()>10) {...}

A. A single ampersand here would lead to a NullPointerException.

* Q18. What's the main difference between a Vector and an ArrayList

A. Java Vector class is internally synchronized and ArrayList is not.

* Q19. When should the method invokeLater()be used?

A. This method is used to ensure that Swing components are updated through the event-dispatching thread.

* Q20. How can a subclass call a method or a constructor defined in a superclass?

A. Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass's constructor.


Page 1 of 2   next page »
About Yakov Fain
Yakov Fain is a managing principal of Farata Systems, consulting, training and product company. He's authored several Java books, dozens of technical articles. SYS-CON Books has released his latest book, "Rich Internet Applications with Adobe Flex and Java: Secrets of the Masters" in Spring of 2007. Sun Microsystems has nominated and awarded Yakov with the title Java Champion. He leads the Princeton Java Users Group. Yakov teaches Java and Flex 2 part time at New York University. He is an Adobe Certified Flex Instructor.

SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
In It? Reprint It! Contact advertising(at)sys-con.com for reprints!

Want to write? Send your article to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

LATEST JAVA STORIES & POSTS
SAP To Offer Individual Developer Licenses for SAP NetWeaver
SAP has announced that for the first time, individual developers can now purchase an annual developer license for the SAP NetWeaver platform, allowing them to create various types of customized user interfaces for SAP NetWeaver applications that can be based on either Java or ABA
How to Secure Tomcat Database Passwords for Java
Tomcat is a great reference implementation of the Java EE specification and is intended for desktop use by developers who are starting to learn about Java EE or those who work on enterprise applications and need an EE server for development. However because Tomcat is free it find
Interface21 Partners with Tasktop to Develop Spring Tool Suite
Interface21 has partnered with Tasktop Technologies, creators of the Eclipse Mylyn project, to develop the Spring Tool Suite. This new Spring-specific tool solution will build on Eclipse and Mylyn to dramatically reduce the complexity of enterprise Java application development an
Time for Introductions
In last month's column Onno Kluyt announced that he would be handing over the role of JCP chair to me. I'd like to take this opportunity to thank Onno for all of the effort he's put into the JCP over the past several years, to thank the hard-working staff of the Program Managemen
Sun Microsystems and Bank of America Pilot Solaris-based Payments Processing System
Sun Microsystems and Bank of America, a key provider of treasury services to Sun, are breaking new ground with a pilot of the ISO 20022 global financial messaging standard for end-to-end payment processing. Running on Sun's own Solaris 10 Operating System, the pilot will help Sun
Focusing on JEE Java Development: Mylyn and Spring
As developers, we're familiar with the endless pains that result from maintaining overly complex systems. Some complexity is accidental, so we continually strive to remove its overhead from our application. The latest crop of frameworks and dynamic languages has demonstrated just
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
Receive Breaking i-Technology News as it Happens...
AJAX Newsletter
Java Newsletter
Open Source/Linux Newsletter
Microsoft .NET Newsletter
Flex Newsletter
Internet TV Newsletter
IT Solution's Guide Newsletter
 
SOA/Web Services Newsletter
Virtualization Newsletter
Web 2.0 Newsletter
ColdFusion Newsletter
PowerBuilder Newsletter
XML Newsletter
Eclipse Newsletter
Your E-Mail: 
State: 
Zip Code: 



TODAY'S TOP LINKS YOU MUST CLICK ON !
ADS BY GOOGLE


BREAKING JAVA NEWS
New Evans Data Survey Says Unit Testing Automation is a Growing Priority for Global Development Teams
Agitar Software, the leader in unit testing solutions, today announced results from a new Ev