This document contains a collection of Java study questions and answers covering topics like syntax, OOP concepts, exception handling, multithreading, and collections. Each question is followed by detailed answers with examples to help you prepare for exams or practice your Java skills. Perfect for...
Java Study Questions and Answers
1. What is Java?
Answer:
Java is a high-level, object-oriented programming language developed by James
Gosling at Sun Microsystems (now owned by Oracle). It follows the "Write Once,
Run Anywhere" philosophy, meaning code written in Java can run on any platform
that supports a Java Virtual Machine (JVM). Java is widely used for building web
applications, mobile applications (Android), and enterprise-level systems.
2. What are the different types of data types in Java?
Answer:
Java has two main types of data types:
Primitive Data Types:
o byte: 8-bit integer
o short: 16-bit integer
o int: 32-bit integer
o long: 64-bit integer
o float: 32-bit floating point
o double: 64-bit floating point
o char: 16-bit Unicode character
o boolean: true or false
Non-Primitive Data Types:
o String: A sequence of characters.
o Array: A collection of similar data types.
o Object: An instance of a class, which can hold multiple values and
methods.
, 3. What is the difference between == and equals() in Java?
Answer:
== is a reference comparison operator used to check if two references point
to the same object in memory (it checks for object identity).
equals() is a method defined in the Object class, which is used to compare
the actual content or state of two objects for equality.
Example:
String str1 = new String("Hello");
String str2 = new String("Hello");
4. What is inheritance in Java?
Answer:
Inheritance is an OOP concept in Java that allows one class to inherit fields and
methods from another class. The class that inherits is called the subclass or child
class, and the class it inherits from is called the superclass or parent class. It helps
to achieve code reusability and method overriding.
Example:
class Animal {
void sound() {
System.out.println("Animal makes a sound");
}
}
class Dog extends Animal {
void sound() {
System.out.println("Dog barks");
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller rileyclover179. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $6.89. You're not tied to anything after your purchase.