DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Culture and Methodologies
  3. Career Development
  4. 10 Tricky Java Interview Questions

10 Tricky Java Interview Questions

Sandeep Bhandari user avatar by
Sandeep Bhandari
·
May. 10, 11 · Interview
Like (1)
Save
Tweet
Share
99.44K Views

Join the DZone community and get the full member experience.

Join For Free
Here are some Java interview questions which are  un-common
 
  1. What is the performance effect of a large number of import statements which are not used?
    Answer: They are ignored if the corresponding class is not used.
  2. Give a scenario where hotspot will optimize your code?
    Answer: If we have defined a variable as static and then initialized this variable in a static block then the Hotspot will merge the variable and the initialization in a single statement and hence reduce the code.
  3. What will happen if an exception is thrown from the finally block?
    Answer: The program will exit if the exception is not catched in the finally block.
  4.  How does decorator design pattern works in I/O classes?
    Answer:  The various classes like BufferedReader , BufferedWriter workk on the underlying stream classes. Thus Buffered* class will provide a Buffer for Reader/Writer classes.
  5. If I give you an assignment to design Shopping cart web application, how will you define the architecture of this application. You are free to choose any framework, tool or server?
    Answer:  Usually I will choose a MVC framework which will make me use other design patterns like Front Controller, Business Delegate, Service Locater, DAO, DTO, Loose Coupling etc. Struts 2 is very easy to configure and comes with other plugins like Tiles, Velocity and Validator etc. The architecture of Struts becomes the architecture of my application with various actions and corresponding JSP pages in place.
  6. What is a deadlock in Java? How will you detect and get rid of deadlocks?
    Answer:  Deadlock exists when two threads try to get hold of a object which is already held by another object.
  7. Why is it better to use hibernate than JDBC for database interaction in various Java applications?
    Answer:  Hibernate provides an OO view of the database by mapping the various classes to the database tables. This helps in thinking in terms of the OO language then in RDBMS terms and hence increases productivity.
  8. How can one call one constructor from another constructor in a class?
    Answer:  Use the this() method to refer to constructors.
  9. What is the purpose of intern() method in the String class?
    Answer:  It helps in moving the normal string objects to move to the String literal pool
  10. How will you make your web application to use the https protocol?
    Answer:  This has more to do with the particular server being used  than the application itself. Here is how it can be done on tomcat:
    http://tomcat.apache.org/tomcat-4.1-doc/ssl-howto.html

From http://extreme-java.blogspot.com/2011/05/10-tricky-java-interview-questions.html

Java (programming language) Interview (journalism) application

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Keep Your Application Secrets Secret
  • A Beginner's Guide to Infrastructure as Code
  • Microservices Testing
  • A Gentle Introduction to Kubernetes

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: