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
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
  1. DZone
  2. Coding
  3. Java
  4. Core Java Interview Questions List: Part I

Core Java Interview Questions List: Part I

You may not be a fan of these interview questions since some of them are not the things legitimate companies should be asking, but they're good to know.

Sam Atkinson user avatar by
Sam Atkinson
·
Dec. 15, 14 · Tutorial
Like (4)
Save
Tweet
Share
28.38K Views

Join the DZone community and get the full member experience.

Join For Free

As I’ve discussed several times on this site, I’m not a fan of learn by wrote Java questions. However, a lot of people continue to ask them during their interview process so it means you need to know how to answer them.

The name of the game is core java interview questions and I will be your quiz master. Each week I will publish 10 new quick fire questions and answers.

1. What is a static variable?

A static variable is a value that remains the same through all the instances and can be modified by all the instances. It is a shared value.

2. If I change the order of a methods modifiers will it still work? Is public static void main the same as public void static main? What about void static public main?

Modifiers can be moved around freely. The visibility modifier (if there is one)must be at the start.

3. Why would you pick an ArrayList or LinkedList?

ArrayList is great if you need fast access to objects but can cope with slower writes. Conversely, if you need fast writes (moving, removing or adding) but can cope with slower direct access then choose a LinkedList (read our in depth article on collections here).

4. What are the different access modifiers in Java and what do they mean?

public- accessible to everyone in the JVM

private- only accessible from inside the class.

protected- accessible from by any class in the same package or any subclass in any package

default-when no visibility modifier is present. accessible from any class in the same package only.

5. If you wanted to prevent your methods or classes from being overridden, how would you do this?

By declaring something as final you prevent it from being overridden. Nothing is perfect though, as crafty developers can always use Reflection to get around this, or alternatively just copy and paste your code into their own version of the class.  It is rarely a good idea to prevent your methods or classes being overridden, and you should code defensively to reflect this.

6. What is an immutable object?

The state of an immutable object cannot be changed after construction.  Immutable objects can play an important roll in threading. (read more on threading here).  A good example of an immutable objeect is String.  Any modification to an immutable object will result in  the creation of a new object.

7. What is the difference between overloading and overriding?

Method overloading is having multiple methods with the same name. They can be differentiated as they will have a different signature, e.g. take different method parameters.  Overriding is used when creating a subclass of a class and specifying your own functionality for the method by copying the method signature identically.

8. What does it mean when we say java does not support multiple inheritance? Is this a good thing?

Java cannot extend functionality from more than one concrete or abstract class.  If both parent classes had a jump() method, it would be unclear which functionality the caller would need to use.  We can implement multiple interfaces however as the the implementation occurs in our actual class so this problem does not occur.

9. What is an abstract class?

Similar to an interface, an abstract class cannot actually be instantiated. Unlike an interface, an abstract class can have method implementations.  Any method without implementation will have the modifier “abstract” to indicate to classes which extend it that they must provide the implementation.

10. What does “write once run anywhere” mean in relation to Java?

Java is a cross platform language; java compiles down to byte code which can be run on a Java Virtual Machine (JVM). JVMs are available on many platforms including the major operating systems. This means that any Java application can in theory run on any platform where a JVM is available, hence write once (for the JVM) and run anywhere (there is a JVM).

Java (programming language) Java virtual machine Interview (journalism)

Published at DZone with permission of Sam Atkinson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • AWS Cloud Migration: Best Practices and Pitfalls to Avoid
  • Beginners’ Guide to Run a Linux Server Securely
  • Easy Smart Contract Debugging With Truffle’s Console.log
  • Promises, Thenables, and Lazy-Evaluation: What, Why, How

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: