java - Basic Flashcards
What is Java and what are its main features?
Java is a high-level, general-purpose programming language that was developed by Sun Microsystems (now owned by Oracle Corporation).
Its main features include platform independence, object-oriented programming (OOP) support, automatic memory management (garbage collection), robustness, and a large standard library.
What is Java SE
Java SE (Standard Edition) is the core Java platform that provides the basic set of APIs and libraries for general-purpose development.
What is Java EE
Java EE (Enterprise Edition) is a set of APIs and libraries built on top of Java SE, specifically designed for developing enterprise applications, such as web applications and distributed systems.
What is Java ME
Java ME (Micro Edition) is a subset of Java SE, optimized for resource-constrained devices like mobile phones and embedded systems.
Explain the JVM (Java Virtual Machine) and its role in Java programming.
The JVM is a crucial component of the Java platform.
It is responsible for executing Java bytecode, which is the compiled form of Java source code.
The JVM acts as an abstraction layer between the Java program and the underlying hardware and operating system.
It provides platform independence by translating bytecode into machine-specific instructions at runtime.
The JVM also manages memory, handles garbage collection, and provides various runtime services to Java programs.
What are the different types of data types in Java?
primitive
reference
What are the primitive data types in Java?
byte
short
int
long
float
double
char
boolean
What are the reference types in Java?
classes
interfaces
arrays
enumerations
What is a class?
a class is a blueprint or template that defines the structure and behavior of objects.
It specifies the properties (fields) and actions (methods) that objects of that class can possess.
What is an object?
An object, on the other hand, is an instance of a class.
It represents a specific entity created from the class and can hold its own unique state and behavior.
Explain the concept of inheritance
Inheritance is a fundamental feature of object-oriented programming in Java.
It allows a class to inherit the properties and methods of another class, known as the superclass or base class.
The class that inherits from the superclass is called a subclass or derived class.
The subclass can reuse the code and extend the functionality of the superclass
Give an example of inheritance
consider a superclass called “Vehicle” and a subclass called “Car.”
The Car class can inherit attributes and methods from the Vehicle class, such as “numberOfWheels” and “startEngine()”.
What is the purpose of the “static” keyword in Java?
The “static” keyword in Java is used to declare members (fields or methods) that belong to the class itself rather than specific instances of the class.
Static members are shared among all objects of the class and can be accessed directly using the class name, without creating an instance of the class.
Static methods are commonly used for utility functions or operations that don’t require access to instance-specific data.
How do you create and use an array in Java?
In Java, an array is a fixed-size, ordered collection of elements of the same type.
To create an array, you specify the element type and the size of the array.
For Example:
int[] numbers = new int[5];
or
int[] numbers = {1, 2, 3, 4, 5};
What is method overloading?
Method overloading refers to the ability to have multiple methods in the same class with the same name but different parameters.
The methods are distinguished by their parameter types, number, or order.
What is method overriding?
Method overriding, on the other hand, occurs when a subclass provides a specific implementation of a method that is already defined in its superclass.
The overridden method in the subclass must have the same name, return type, and parameters as the method in the superclass.
How do you handle exceptions in Java?
The try-catch-finally block is used to handle exceptions.
The code that might throw an exception is placed in the try block, and the corresponding exception handlers are placed in catch blocks.
If an exception occurs in the try block, the catch block that matches the type of the thrown exception is executed.
The finally block, if present, is executed regardless of whether an exception occurred or not and is commonly used for cleanup tasks.
What is a checked exception?
Checked exceptions are exceptions that must be declared in the method signature using the “throws” keyword or caught using a try-catch block.
They represent expected error conditions that the calling code must handle explicitly.
checked exceptions are subclasses of Exception (excluding RuntimeException and it’s subclasses)