Interview Prep Flashcards
What is Java platform independence?
Java platform independence means that this programming language can run on different platforms or OS without any changes, which becomes possible with bytecode. The original code of Java is converted into bytecode to adapt it for a specific machine. Bytecode is transmitted to Java Virtual Machine (or simply JYM) that is located in the RAM of any OS. JYM detects the bytecodes and transforms them into the native machine code.
What is an RDBMS?
RDBMS stands for Relational Data Base Management System, which is based on the relational model of the database system. It includes numerous tables that have their own primary key and are used to store the data using columns and rows. Typical examples of the RDBMS are systems like SQL, MS SQL Server, IBM DB2, ORACLE, My-SQL, Microsoft Access, and others.
What are the basic access specifiers for Java classes?
Access specifiers (also known as access modifiers) are the specific keywords used before a class name to determine the access scope. They’re mostly used for defining the visibility of classes, variables, interfaces, constructors, methods, etc. In Java, there are 4 types of access modifiers:
Private - variables that can be accessed only from the same class they belong to;
Public - methods and variables that can be accessed by any other classes in the project;
Protected - variables that can be accessed within the same set of classes and subclasses of any other packages;
Default - methods and variables that can be accessed only from the same package (not from the native one).
What are loops in Java and what are the 3 types of loops?
Java loop repeats a sequence of instructions until a particular condition is met. There are three types of loops in Java: for, while, and do-while.
What is the difference between fail-fast and fail-safe iterators?
Fail-fast iterators perform directly on the collection, which means they fail as soon as the definition of the collection has been changed during iteration.
Unlike the previous ones, fail-safe iterators function directly on a collection’s copy, thus they do not throw any exception if the collection has been changed during iteration.
What is the MVC design pattern?
MVC (also known as Model-View-Controller) is an app design tool that divides the application into 3 parts:
Model - stands for the app data
View - data representation on a screen
Controller - operates the list of processes and responds to the actions, that sometimes can change the model
What is Core Java?
Core Java is a general term used by Sun Microsystems to define a basic edition of Java (J2SE), used for the other editions created. Core Java is mainly used for building desktop and server-based apps, mostly because of its benefits as the fast and a highly-secure scripting language.
What are the 4 types of Java platforms?
Being a particular environment for the Java programming language, there are 4 different platform types for Java:
Java SE or Java Standard Edition
Java EE or Java Enterprise Edition
Java ME or Java Micro Edition
Java FX
What is the difference between transient and volatile variables in Java?
The main difference between transient vs volatile variables is that transient variables are utilized to prevent serialization while volatile variables are utilized to provide alternative synchronization in Java.
What’s the difference between a ClassNotFoundException and NoClassDefFoundError?
ClassNotFoundException is an exception that occurs when the class file for a requested class can’t be found on the classpath.
NoClassDefFoundError is an error that occurs when the class file existed at runtime but can’t be turned into a Class definition for some reason.
What’s the difference between ‘sleep ( )’ and ‘wait ( )’ methods in Java?
‘sleep ( )’ is a blocking operation that keeps either hold on the monitor or the lock on the shared object for a set amount of milliseconds and is commonly used for polling or certain results tracking at a set time.
‘wait ( )’ pauses the thread for the set amount of time or enables it after receiving approval from the other thread without locking the shared object or holding on to the monitor.
When ‘finally’ block is executed in Java?
The ‘finally’ block is mostly applied for putting the important codes like the clean-up code, for example when the file or connection needs closing. The ‘finally’ block is executed when an exception is thrown from a ‘try’ block that does not have a ‘catch’ block. It is executed even in cases when an exception is thrown or propagated to the calling code block.
What is the Java ClassLoader?
ClassLoader is the “deepest” mechanism in Java, which allows you to intervene practically into the core of the Java Virtual Machine (JVM) while remaining within the framework of Java programming. ClassLoader provides loading the classes from the local file system, remote file system, or web.
There are 3 types of ClassLoader in Java:
Bootstrap ClassLoader: Responsible for loading standard Java API files rt.jar from folder
Extensions ClassLoader: Manages loading jar files from the folder.
System Class Loader: Operates loading jar files from the specific path in the CLASSPATH environment
Can you use == on enum?
Yes, as the enums represent a set of constants like unchangeable variables or final variables, which ensure that you’ll have only one case of the constants used in the JVM. They have close instance controls which allow using == for the instances comparison. Furthermore, the ‘==’ operator provides compile-time and run-time safety.
What is composition in Java?
Composition in Java stands for code reusing. Basically, the composition is used as a part-of or ‘has-a’ relationship that helps to ensure the code reusability in the program. In other words, that’s a technique that assists in describing the reference between two or more classes. The composition between two entities is marked as done when an object contains a composed object, and the last one can exist within another entity.
What is a static import?
A static import is a method used in the Java development process, which allows various members (like fields and methods), scoped within their container classes as public static, to be employed in Java code without indicating the exact class in which the field has been defined. This method enhances the code readability and gets direct access to the static members.
What is method overloading in Java?
Method overloading in Java stands for a feature that enables a class to have more than one method with the same name if their argument lists are different. It has some similar points to the constructor overloading. There are 3 different ways in which you can overload a method:
by number of parameters
by the data type of parameters
by the sequence of the data type of parameters
What is method overriding in Java?
Method overriding in Java stands for a feature that allows a subclass or child class to complete a specific implementation of a method that has been done by one of its superclasses or parent classes. One of the benefits of this method is that it assists in defining a specific class type behavior so that a subclass can use a parent class method based on its type.
What does the Final Keyword in Java mean?
The final keyword defines the entity which can be assigned only once and can’t be modified in the future. Once it’s been set, it can’t change its value anymore, for instance in the functions. The entity defined by the final keyword can be a variable, a class, a method, etc.
What are OOPs concepts in Java?
The OOPs concepts stand for Object-Oriented Programming in Java and cover the following elements: class, object, encapsulation, inheritance, polymorphism, and abstraction. All these assist in ensuring the application’s reusability, security, and flexibility, and allows developers to create the working methods and variables, then reuse them all or part of them without compromising the system security.
Does Java have a static class?
1 Declare the class final to prevent the class extension and make it static
You can’t build the advanced class static but you can enhance its performance in the next steps:
#2 Set up the private constructor
#3 Configure the members and functions of the class static as well
What does the GetMethod of HashMap do in Java?
HashMap is constructed using the hash table data structure. Basically, it employs the ‘hashCode ( )’ method to compute hash code to find the bucket location on the underlying array and the ‘equals ( )’ method to detect the object in the same bucket in case of a collision.
What is the Difference between JDK and JRE?
Java Runtime Environment (also known as JRE) stands for a Java Virtual Machine (or JVM), the programming environment where the Java programs are being executed. It also covers the browser plugins for the advanced applet execution.
Java Development Kit (also known as JDK) is a much more complex, full-stack Software Development Kit for Java programming language which includes the JRE, various compilers, and a list of tools (for instance, JavaDoc or Java Debugger). JDK is targeted at developing, compiling, and executing different Java apps.
What is the meaning of Spring beans?
The Spring beans are the objects that form the keystone of your application and are controlled by the Spring IoC container. A so-called “bean” is an object that is instantiated, assembled, and managed in any possible option by a Spring IoC container. The Spring beans are formed with the configuration metadata that is supplied to the container.
For instance, you can always meet their definitions in the XML form:
What is the Application Context definition?
In general, the application context has a similar definition to the bean factory. It loads bean definitions, wires beans together, and dispenses them if required. Also, it provides a generic way to load file resources, specific events to the beans defined as listeners, as well as means for resolving text messages using various languages.
What is JDBC?
JDBC (also known as Java Database Connectivity) stands for the Java API, responsible for the connection to a database, queries, and commands issuing as well as receiving the result sets processed by the database. Basically, it enables developers to switch between the databases without having to underlie the specific features of a particular database.
What is Controller in the Spring framework?
The controllers of the Spring MVC framework enable access to the app behavior programmers typically define via the service interface. They analyze the user’s query and convert it into the specific model user can perceive by the view component. The controllers in Spring are implemented only in the abstract way, thus allowing developers to create a wide range of different controllers.
What is the function of the Continuous Integration (CI) server?
CI is a DevOps software development practice that is used to merge the code changes made by different developers in the central repository in order to run automated builds and tests. CI should build code multiple times a day in order to timely detect any issue and identify its cause.
How is Java different from C++?
Java and C++ are both object-oriented programming languages, but they have some key differences.
Platform independence: Java is a platform-independent language, while C++ is a platform-dependent language. This means that Java code can run on any platform that has a Java virtual machine (JVM), while C++ code can only run on the platform that it was compiled for.
Memory management: Java uses automatic memory management, while C++ requires manual memory management. This means that Java programmers do not need to worry about allocating and freeing memory, while C++ programmers need to be careful to manage memory correctly to avoid memory leaks.
Safety: Java is a safer language than C++. This is because Java has built-in security features that help to protect applications from malicious code. For example, Java does not allow direct access to the operating system, which makes it more difficult for attackers to exploit security vulnerabilities.
Performance: Java is typically not as fast as C++. This is because Java uses a virtual machine, which adds an extra layer of abstraction between the code and the hardware. However, Java applications are typically more portable and secure than C++ applications.
JDK
It stands for Java Development Kit.
It is the tool necessary to compile, document and package Java programs.
It contains JRE + development tools.
JRE
It stands for Java Runtime Environment.
JRE refers to a runtime environment in which Java bytecode can be executed.
It’s an implementation of the JVM which physically exists.
JVM
It stands for Java Virtual Machine.
It is an abstract machine. It is a specification that provides a run-time environment in which Java bytecode can be executed.
JVM follows three notations: Specification, Implementation, and Runtime Instance.
Explain public static void main(String args[]) in Java.
main() in Java is the entry point for any Java program. It is always written as public static void main(String[] args).
public: Public is an access modifier, which is used to specify who can access this method. Public means that this Method will be accessible by any Class.
static: It is a keyword in java which identifies it is class-based. main() is made static in Java so that it can be accessed without creating the instance of a Class. In case, main is not made static then the compiler will throw an error as main() is called by the JVM before any objects are made and only static methods can be directly invoked via the class.
void: It is the return type of the method. Void defines the method which will not return any value.
main: It is the name of the method which is searched by JVM as a starting point for an application with a particular signature only. It is the method where the main execution occurs.
String args[]: It is the parameter passed to the main method.
What is classLoader in Java?
The Java ClassLoader subset of JVM loads class files. The classloader loads Java programs first. Three classloaders are built into Java:
Bootstrap ClassLoader
Extension ClassLoader
System/Application ClassLoader
Why Java is not 100% Object-oriented?
Java is not 100% Object-oriented because it makes use of eight primitive data types such as boolean, byte, char, int, float, double, long, short which are not objects.
8 primitive data types
boolean, byte, char, double, int, float,
long, short
What are wrapper classes in Java?
Wrapper classes convert the Java primitives into the reference types (objects). Every primitive data type has a class dedicated to it. These are known as wrapper classes because they “wrap” the primitive data type into an object of that class. Refer to the below image which displays different primitive type, wrapper class and constructor argument.
What are constructors in Java?
In Java, constructor refers to a block of code which is used to initialize an object. It must have the same name as that of the class. Also, it has no return type and it is automatically called when an object is created.
There are two types of constructors:
Default Constructor: In Java, a default constructor is the one which does not take any inputs. In other words, default constructors are the no argument constructors which will be created by default in case you no other constructor is defined by the user. Its main purpose is to initialize the instance variables with the default values. Also, it is majorly used for object creation.
Parameterized Constructor: The parameterized constructor in Java, is the constructor which is capable of initializing the instance variables with the provided values. In other words, the constructors which take the arguments are called parameterized constructors.