Solvd

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is inheritance?

It is the mechanism in java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, inheritance means creating new classes based on existing ones. A class that inherits from another class can reuse the methods and fields of that class. In addition, you can add new fields and methods to your current class as well. Inheritance in Java: Why do we need it? Code Reusability: The code written in the Superclass is common to all subclasses. Child classes can directly use the parent class's code.

How we can throw an exception in Java?

Java exception handling is managed via five keywords: try, catch, throw, throws, and finally. Briefly, here is how they work. Program statements that you think can raise exceptions are contained within a try block. If an exception occurs within the try block, it is thrown. Your code can catch this exception (using catch block) and handle it in some rational manner. System-generated exceptions are automatically thrown by the Java run-time system. To manually throw an exception, use the keyword throw. Any exception that is thrown out of a method must be specified as such by a throws clause. Any code that absolutely must be executed after a try block completes is put in a finally block.

How we can handle exceptions in java(2 ways)?

either try catch block from which exception is thrown if detected OR manually thrown with keyword throw

What is functional programming?

functional programming which is focused on actions

How to create a custom exception?

public class IncorrectFileNameException extends Exception { public IncorrectFileNameException(String errorMessage) { super(errorMessage); } } ____ Runner main function try (Scanner file = new Scanner(new File(fileName))) { if (file.hasNextLine()) return file.nextLine(); } catch (FileNotFoundException e) { if (!isCorrectFileName(fileName)) { throw new IncorrectFileNameException("Incorrect filename : " + fileName ); } }

What is lambda?

A lambda expression is a concise way to represent a function in Java. It consists of a set of parameters, an arrow, and a body. For example, the following lambda expression represents a function that takes two integers and returns their sum: Copy code (int x, int y) -> x + y Lambda expressions can be used to pass functions as arguments to methods, or to assign them to variables. They are a powerful tool for functional programming in Java and can be used to simplify code and improve readability.

Know 3 checks for equals overriding - object references

1 - Check if object references are the same 2. compare classes of the objects and see if they are the same 3. compare state of variable fields within the two objects to see if theyre the same

naming convention for classes

CamelCase

How does Java support multi-platforms?

Java works across multiple platforms by utilizing something known as the Java Runtime Environment (JRE) and a JVM or Java Virtual Machine. A Java Virtual Machine is component that executes Java bytecode for a program

How to realize encapsulation?

Use java private modifiers for fields with public getters and setters

What is polymorphism?

polymorphism refers to the ability of a class to provide different implementations of a method, depending on the type of object that is passed to the method. To put it simply, polymorphism in Java allows us to perform the same action in many different ways. ____ Polymorphism in Java allows a single object to take on multiple forms through inheritance or implementation of multiple interfaces. This allows the object to behave in multiple ways depending on the context in which it is used.

What is M2_HOME? How to setup Maven?

1. Download and install Maven from the official website (https://maven.apache.org/). 2. Set the M2_HOME environment variable to the directory where Maven is installed. 3. Add the Maven bin directory to the PATH environment variable. 4. Type mvn -v to verify installation

How to work with maven profile?

A Maven profile is a set of configuration values that can be activated to customize the Maven build process for different environments or scenarios. Profiles are defined in the pom.xml file or the settings.xml file, and they can be activated using the -P command line option or the activeProfiles element in the settings.xml file. Profiles can be used to specify different dependencies, build settings, and plugin configurations for different environments, such as development, staging, and production.

What is collision? How to handle that?

A collision in a hash table occurs when two or more keys map to the same index in the array. There are several ways to handle collisions, such as separate chaining (using a linked list at each index), open addressing (finding the next empty index in the array), and rehashing (using a secondary hash function). The choice of strategy depends on the specific needs and constraints of the application.

What is a constructor? Default constructor? Why do we need them?

A constructor in Java is a special method that is used to initialize objects. The constructor is called when an object of a class is created. It can be used to set initial values for object attributes. Note that the constructor name must match the class name, and it cannot have a return type (like void). Also note that the constructor is called when the object is created. All classes have constructors by default: if you do not create a class constructor yourself, Java creates one for you. However, then you are not able to set initial values for object attributes. Constructors can also take parameters, which is used to initialize attributes.

Can we call non-static methods from static? Vice versa?

A static method can call only other static methods; it cannot call a non-static method.A static method can be called directly from the class, without having to create an instance of the class. A static method can only access static variables; it cannot access instance variables. The only way to call a non-static method from a static method is to have an instance of the class containing the non-static method. By definition, a non-static method is one that is called ON an instance of some class, whereas a static method belongs to the class itself.

What exception types do you know?

A. Built-in Exceptions: Built-in exceptions are the exceptions that are available in Java libraries. These exceptions are suitable to explain certain error situations. Checked Exceptions: Checked exceptions are called compile-time exceptions because these exceptions are checked at compile-time by the compiler. Unchecked Exceptions: (RUNTIME EXCEPTIONS) The unchecked exceptions are just opposite to the checked exceptions. The compiler will not check these exceptions at compile time. In simple words, if a program throws an unchecked exception, and even if we didn't handle or declare it, the program would not give a compilation error. Note: For checked vs unchecked exception, see Checked vs Unchecked Exceptions B. User-Defined Exceptions: Sometimes, the built-in exceptions in Java are not able to describe a certain situation. In such cases, users can also create exceptions, which are called 'user-defined Exceptions'. The advantages of Exception Handling in Java are as follows: Provision to Complete Program Execution Easy Identification of Program Code and Error-Handling Code Propagation of Errors Meaningful Error Reporting Identifying Error Types

What is an abstract class? Abstract method?

Abstract classes and methods cannot be instantiated directly, they have to be implemented by a child class. So if you have a Vehicle parent class that is abstract with an abstract method Drive(), you would need a Car class or Motorcycle child class that populates Drive() method to use it. An abstract class is a class that cannot be instantiated, but can be subclassed. It is used as a base class for one or more derived classes, and can contain both abstract methods (methods with no implementation) and concrete methods (methods with an implementation). An abstract method is a method that is declared in an abstract class, but does not have an implementation. It must be implemented by any concrete subclass of the abstract class. Abstract methods are used to specify a contract that must be followed by any concrete subclass, but the implementation of the method can be different in each subclass.

What is enum?

An enum is a type in Java that represents a fixed set of values. Enums are used to define a set of named constants, and they can be used in place of int constants or string constants. For example, suppose you want to define a set of named constants for the days of the week. You can define an enum like this: Copy code public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } Enums can also have fields, methods, and constructors, and they can be used in switch statements.

What are your lecturer's name and title

Andrey "Andrew" Nazarenko - Director of Engineering

What is an interface?

Another way to achieve abstraction in Java, is with interfaces. An interface is a completely "abstract class" that is used to group related methods with empty bodies To access the interface methods, the interface must be "implemented" (kinda like inherited) by another class with the implements keyword (instead of extends). The body of the interface method is provided by the "implement" class

What do you know about collections with Hash?

Collections with hash are Java data structures that use a hash table to store and retrieve elements. A hash table is a data structure that maps keys to values using a hash function, which converts the keys into indices in an array. Collections with hash, such as HashMap and HashSet, provide fast access to elements based on their keys, and can be used to store and manipulate large amounts of data efficiently. However, they do not maintain any order for the elements, and the performance of hash-based collections can degrade if the hash function does not distribute the keys evenly across the array.

What is a logger? Logger levels? What log aggregators do you know?

Each logger has their own levels such as OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE each level will log prev level. example: error will log off and fatal Log4j 2, Spring, Logstash

What is encapsulation?

Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates. Another way to think about encapsulation is, that it is a protective shield that prevents the data from being accessed by the code outside this shield. Advantages include Data Hiding, Increased Flexibility, reusability, encapsulated code is easier to test for unit testing.

What are the 3 main OOP approaches?

Encapsulation, Inheritance, and Polymorphism Encapsulation: the process of bundling data and methods that operate on that data within a single unit (e.g., class). Inheritance: the ability of a class to inherit properties and behavior from a parent class, which can be modified or extended. Polymorphism: the ability of a single object to take on multiple forms, either through inheritance or implementation of multiple interfaces. _____ Encapsulation: in OOP, you bundle code into a single unit where you can determine the scope of each piece of data. Inheritance: because a class can inherit attributes and behaviors from another class, you are able to reuse more code. Polymorphism: one class can be used to create many objects, all from the same flexible piece of code.

6 differences between an abstract class and an interface?

Final exam question: What's the difference? Interfaces - Represent an action - all fields are public, final, static ONLY! //example is painting an airplane from white to red, NO constructor bc all fields are final and you've already initialized them in fields. All methods are abstract by default. default keyword needs to be used for default method (if you want to put some code in there.) keyword implement and can implement several interfaces Abstract class - Represents an entity, has fields has constructor, has a general method by default that you can make abstract with keyword all methods are default extends keyword to extend only one abstract class _________________ An abstract class can contain both abstract methods (methods with no implementation) and concrete methods (methods with an implementation), while an interface can only contain abstract methods. An abstract class can have both static and non-static fields, while an interface can only have static and final fields. An abstract class can have a constructor, while an interface cannot. A class can extend only one abstract class, but it can implement multiple interfaces. An abstract class can be used to provide a common base class for a group of related classes, while an interface is used to define a set of related behaviors that a class can implement. An abstract class can be used to define a skeletal implementation that can be shared by multiple concrete subclasses, while an interface cannot provide any implementation.

What are the differences between OOP and functional programming?

Functional programming is a programming paradigm that emphasizes the use of pure functions, which are functions that have no side effects and always return the same output for a given input. In functional programming, the focus is on using functions as first-class citizens, and the program is constructed using function composition and immutable data structures. This approach can lead to more concise, easier-to-maintain code.

What is the start point of a Java application?

In Java programs, the point from where the program starts its execution or simply the entry point of Java programs is the main() method.

What is a generic

In Java, a generic is a type parameter that can be used to create a class, interface, or method that can work with multiple types. Generics allow you to write code that is independent of specific types, which makes it more reusable and flexible. To use a generic, you specify the type parameter within angle brackets (<>) after the class, interface, or method name.

What is an exception's hierarchy?

In Java, exceptions are represented by objects that are instances of classes that extend the Throwable class. The Throwable class is the base class for all exceptions and errors in Java, and it has two direct subclasses: Exception and Error. The Exception class is the base class for exceptions that can be handled by an application. It has several subclasses that represent different types of exceptions, such as IOException, SQLException, and NullPointerException. The Error class is the base class for errors that indicate serious problems that should not be caught or handled by an application. It has several subclasses that represent different types of errors, such as OutOfMemoryError and StackOverflowError. Overall, the hierarchy of exception classes in Java is organized into a tree structure, with the Throwable class at the root, the Exception and Error classes as its direct subclasses, and various subclasses of Exception and Error representing different types of exceptions and errors. Error: An Error indicates a serious problem that a reasonable application should not try to catch. Exception: Exception indicates conditions that a reasonable application might try to catch.

What is collection hierarchy?

In Java, the collection hierarchy is a group of interfaces and classes that provide various ways of storing and manipulating collections of objects. The main interfaces in the collection hierarchy are: Collection: the root interface for all collections. It defines common operations for working with collections, such as adding and removing elements, and checking the size of the collection. List: an interface that extends Collection and represents an ordered collection of elements that can contain duplicates. Set: an interface that extends Collection and represents a collection of elements that cannot contain duplicates. Queue: an interface that extends Collection and represents a collection of elements that are processed in a first-in, first-out (FIFO) order. There are several concrete classes that implement these interfaces, such as ArrayList, LinkedList, HashSet, and PriorityQueue. These classes provide different ways of storing and manipulating collections, and have different characteristics in terms of performance, memory usage, and functionality. Overall, the collection hierarchy in Java provides a rich set of tools for working with collections of objects, and allows you to choose the class that is most appropriate for your needs based on the specific characteristics of your application.

When will you choose to switch or if?

In Java, you should use an if-else statement when you have multiple conditions that you want to test and you want to execute different code for each condition. On the other hand, you should use a switch statement when you have a single expression that can take on a limited number of values, and you want to execute different code for each value. The switch statement is generally more efficient than using multiple if-else statements for testing the same expression against a large number of values.

What do you know about local/remote repositories?

In Maven, a local repository is a directory on the local machine that stores the artifacts that are needed to build a project. The local repository is located in the .m2 directory in the user's home directory by default, but it can be customized using the localRepository element in the settings.xml file. The local repository is used to store the artifacts that have been downloaded from remote repositories, as well as the artifacts that have been built locally. A remote repository is a directory on a remote server that stores the artifacts that are not available in the local repository. Maven uses remote repositories to download the artifacts that are needed to build a project when they are not available in the local repository. Remote repositories are specified using the repositories element in the pom.xml file or the settings.xml file. Overall, Maven uses local and remote repositories to manage and store the artifacts that are needed to build a project. The local repository is used to store the artifacts that have been downloaded from remote repositories, while remote repositories are used to download artifacts when they are needed.

What is Stream?

In the Java programming language, a stream is a sequence of elements that supports various methods which can be pipelined to produce the desired result. The elements of a stream are typically objects or primitive data types. Java streams are useful for performing operations on collections of data in a declarative manner. They allow you to express complex operations on data in a concise and readable way, and can be parallelized to take advantage of multi-core processors. For example, you can use a stream to filter a collection of objects, transform the objects in some way, and then perform an action on each transformed object, all in a single line of code.

What is JAVA_HOME? PATH?

JAVA_HOME is an environment variable that specifies the location of the JDK on your system. PATH is an environment variable that specifies a list of directories where executable programs are located. The PATH variable may be updated to include the bin directory of the JDK, which allows you to use the JDK tools from any directory without specifying the full path.

How to call the method using reflection?

Java reflection allows you to inspect and modify Java objects at runtime. To call a method using reflection, you need to get a Class object for the class containing the method, get a Method object for the method using getMethod(), and then call invoke() on the Method object, passing in the instance of the class (for non-static methods) and any required arguments.

What is reflection?

Java reflection is a feature of the Java programming language that allows code to inspect and modify the properties and behaviors of objects at runtime. This is accomplished through the use of the java.lang.reflect package, which contains classes and interfaces that provide reflection capabilities. Reflection allows Java programs to dynamically discover and access the methods, fields, and constructors of classes, and to invoke them at runtime. It is a powerful tool that can be used to inspect, modify, and extend the behavior of existing Java classes, and is often used in testing, debugging, and runtime code generation scenarios.

What lambda functions do you know? Where are they located?

Lambda expressions are a feature of the Java programming language and are used to represent functions. They are not standalone functions, but rather a concise way to represent a function in Java. Lambda expressions are typically used in functional interfaces, which are interfaces that have a single abstract method. The functional interface defines the signature of the function that the lambda expression represents. For example, the java.util.function package contains a number of functional interfaces that can be used with lambda expressions, such as Consumer, Function, and Predicate. These functional interfaces represent functions that take one or more arguments and return a value.

How we can iterate the Map?

Map<String, Integer> map = new HashMap<>(); // add elements to the map map.entrySet().stream().forEach(entry -> { String key = entry.getKey(); Integer value = entry.getValue(); // do something with the key and value });

Describe maven project structure.

Maven follows a standard project structure that consists of the following directories: src/main/java: This directory contains the source code for the project. src/main/resources: This directory contains resource files, such as configuration files, that are needed by the project. src/test/java: This directory contains the source code for the test cases for the project. src/test/resources: This directory contains resource files, such as configuration files, that are needed by the test cases. target: This directory is generated by Maven and contains the compiled classes, test results, and other artifacts produced by the build process. Overall, the standard project structure in Maven is designed to keep the source code, resources, and generated artifacts separate and organized, and to make it easier to build and maintain the project.

Will you handle RuntimeExceptions in try-catch block?

No, Runtime Exceptions are unchecked and typically occur due to human error.

What do you know about class Object?

Object class is present in java.lang package. Every class in Java is directly or indirectly derived from the Object class. If a class does not extend any other class then it is a direct child class of Object and if extends another class then it is indirectly derived. Therefore the Object class methods are available to all Java classes. Hence Object class acts as a root of the inheritance hierarchy in any Java Program. The Object class provides multiple methods which are as follows: tostring() method hashCode() method equals(Object obj) method finalize() method getClass() method clone() method wait(), notify() notifyAll() methods

Why do we need OOP? What problem does it solve?

Object-Oriented Programming (OOP) is a programming paradigm that organizes code into smaller, reusable units called "objects". It helps to improve the modularity and maintainability of software by encapsulating data and code, and allows for the creation of hierarchical class structures to model real-world relationships between objects. OOP helps to solve the problem of managing complexity in software development by providing a structured approach for organizing and reusing code.

How to work with maven plugin?

Overall, Maven plugins are a powerful tool for extending the Maven build process and adding custom functionality to a project. They are specified and configured in the pom.xml file, and their goals can be executed using the mvn command. To work with Maven plugins, specify the plugin in the build element of the pom.xml file and configure it using the configuration element. Execute plugin goals using the mvn command with the plugin's goal as an argument. <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build>

What's the difference between the pom and settings xml files?

Overall, the pom.xml file is specific to a Maven project, while the settings.xml file is global and applies to all Maven projects on a machine. The pom.xml file defines the project's dependencies and build settings, while the settings.xml file specifies the local and remote repositories, plugin settings, and other Maven-related configurations.

What is the difference between Overloading and Overriding?

Overloading refers to the ability of a class to have multiple methods with the same name but different signatures. This allows you to create multiple methods with the same name that can be called with different sets of arguments. Overriding refers to the ability of a subclass to provide a new implementation of a method that is inherited from a parent class. When a method is overridden, the subclass's implementation of the method will be used instead of the parent class's implementation when the method is called on an instance of the subclass. In summary, overloading allows you to have multiple methods with the same name that can be called with different arguments, while overriding allows you to provide a new implementation of an inherited method for a subclass.

What enum types do you know?

Regular enums are the most common type of enums, and they are used to define a set of named constants. Regular enums can have fields, methods, and constructors, and they can be used in switch statements. Specialized enums are a type of enum that is optimized for a specific use case, such as EnumSet, EnumMap, and Enum.

What are the differences between Set, List, Queue, Map?

Set: No duplicates, no order, no element access/manipulation based on position. List: Ordered, can contain duplicates, element access/manipulation based on position. Queue: FIFO order, element insertion/removal at head/tail. Map: Key-value pairs, no order, value access/manipulation based on key.

How to extend String?

Strings are immutable in Java it means once created you cannot modify the content of String. If you modify it by using toLowerCase(), toUpperCase(), or any other method, It always results in new String. Since String is final there is no way anyone can extend String or override any of String functionality. Now if you are puzzled why String is immutable or final in Java. checkout the link.

Why do we need Iterable interface?

The Iterable interface in Java is a marker interface that indicates that a class can be iterated over using an Iterator. An Iterator is an object that allows you to traverse a sequence of elements and access their values one by one. By implementing the Iterable interface, a class indicates that it can provide an Iterator to iterate over its elements, and that it can be used in a for-each loop or with the iterator method of the Collections class. The Iterable interface is a generic interface, and it specifies a type parameter that indicates the type of the elements that can be iterated over. For example: Copy code public interface Iterable<T> { // code } In this example, T is the type parameter for the Iterable interface, and it indicates the type of the elements that can be iterated over.

JDK vs JRE?

The Java Development Kit (JDK) is a software development kit that provides tools for developing Java applications. It includes the Java Runtime Environment (JRE), which is the core Java runtime and provides the necessary libraries and tools for executing Java programs. The Java Virtual Machine (JVM) is a virtual machine that executes Java bytecode. It is the runtime component of the JDK, and is included in the JRE. The JVM is responsible for interpreting and executing the Java bytecode, which allows Java programs to run on any device that has a compatible JVM installed. In summary, the JDK is a complete package that includes the tools needed to develop, debug, and run Java programs, while the JRE is the runtime component that allows Java programs to be executed. The JVM is the component that actually executes the Java bytecode.

How does method hashcode connected with equals?

The equals method is used to determine whether two objects are equal, while the hashCode method is used to generate a numerical value that represents the object's state. In Java, the hashCode method is used by hash-based collections (such as HashMap and HashSet) to determine where to store an object in the collection. If two objects are equal according to their equals method, then they should have the same hashCode. This is because hash-based collections use the hashCode of an object to determine where to store it, and if two equal objects have different hashCodes, they may be stored in different locations, which would violate the contract of the equals method. Therefore, it is important to override both the equals and hashCode methods when you define a custom class that will be used as a key in a hash-based collection.

Why do we need the exception hierarchy?

The exception hierarchy in Java allows you to catch and handle specific types of exceptions, specify the types of exceptions that a method can throw, and create custom exception classes for your application. It helps to organize and classify exceptions, and allows you to handle and specify exceptions in a more structured and informative way.

What do you know about pom.xml file structure?

The pom.xml file (short for "Project Object Model") is a configuration file for a Maven project that contains information about the project, such as the project's dependencies, build settings, and other metadata. The pom.xml file is located in the root directory of the project and is used to build and manage the project. The pom.xml file has a specific structure that consists of a number of elements that define the project's metadata, dependencies, build settings, and other aspects of the Maven build process. Some of the most commonly used elements in the pom.xml file are: - project: This element is the root element of the pom.xml file and contains the project's metadata, such as the groupId, artifactId, and version. - dependencies: This element specifies the dependencies that the project has on other artifacts, such as libraries, frameworks, and other components. - build: This element specifies the build settings for the project, such as the plugins to use, the output directory, and other build-related configurations.

What is settings.xml file for?

The settings.xml file in Maven is a configuration file that contains information about the local repository, remote repositories, plugin settings, and other settings related to the Maven build process. It is used to customize the Maven build process and tailor it to the specific needs of a project.

Is String a primitive type?

The string data type is a non-primitive data type but it is predefined in java, some people also call it a special ninth primitive data type. This solves the case where a char cannot store multiple characters, a string data type is used to store the sequence of characters.

What is target directory?

The target directory in Maven is a generated directory that contains the compiled classes, test results, and other artifacts produced by the Maven build process. The target directory is located in the root directory of the project and is created by Maven when the project is built. It contains the output of the Maven build, such as the compiled classes, the packaged JAR or WAR file, and the test results. The target directory is typically not checked into version control and is regenerated every time the project is built.

When we can use try-catch with resources? What is the requirement?

The try-catch with resources construct in Java allows you to automatically close resources that implement the AutoCloseable interface. To use it, declare the resource in the try statement using a resource specification, and the resource will be closed when the try block completes. This construct is only available in Java 7 and later.

What primitive types do you know?

There are 8 primitive types of data built into the Java language. These include: int, byte, short, long, float, double, boolean, and char.

What Maven flags do you know?

There are many command-line options, or "flags," that can be used with the mvn command to customize the Maven build process. Some of the most commonly used flags are: -X: This flag enables debug output, which can be useful for troubleshooting issues with the build process. -e: This flag causes Maven to print the full stack trace of any exceptions that occur during the build process. -o: This flag tells Maven to run the build process in offline mode, which means that Maven will not try to connect to the internet to download artifacts or perform other tasks that require an internet connection. -D: This flag allows you to set a system property for the Maven build process. For example, you can use -DskipTests to skip running the tests for the project. -U: This flag forces Maven to check for updates to the dependencies and plugins that are used in the project. -P: This flag allows you to specify one or more Maven profiles to be activated for the build process. Overall, the mvn command has many flags that can be used to customize the Maven build process and tailor it to the specific needs of a project.

What stream operations do you know? Why do we need them?

There are many stream operations available in Java, and they can be broadly classified into two categories: intermediate operations and terminal operations. Intermediate operations are operations that are performed on a stream, and they return a new stream as a result. This allows you to chain multiple intermediate operations together to form a pipeline. Some common intermediate operations include: filter(): This operation filters elements based on a given predicate (a boolean-valued function). map(): This operation transforms the elements of the stream using a given function. sorted(): This operation sorts the elements of the stream based on a given comparator. Terminal operations are operations that are performed on a stream and produce a result. Terminal operations terminate the stream pipeline and return the result. Some common terminal operations include: forEach(): This operation performs an action for each element in the stream. count(): This operation returns the number of elements in the stream. findFirst(): This operation returns the first element of the stream, or an empty optional if the stream is empty.

What do you know about threadsafe collections?

Thread-safe collections are Java collections that can be safely used by multiple threads concurrently without the need for external synchronization. Thread-safe collections provide thread-safety by using internal synchronization or by using an immutable data structure. Some examples of thread-safe collections in Java include ConcurrentHashMap, CopyOnWriteArrayList, and SynchronizedList. Overall, thread-safe collections are an important tool for building multithreaded applications in Java, as they allow you to safely share data between threads without the need for explicit synchronization.

How to create lambda in Java?

To create a lambda expression in Java, you need to specify the function's parameters, an arrow, and the function's body. For example, suppose you want to create a lambda expression that represents a function that takes two integers and returns their sum. You can create the lambda expression like this: Copy code (int x, int y) -> x + y

How to create objects from reflection?

To create an object using reflection in Java, obtain a Class object for the class you want to create an object of and use the newInstance() method to create a new instance. If the class does not have a public no-arg constructor, use getConstructor() to obtain a Constructor object for the desired constructor and call newInstance() on it, passing in any required arguments.

How we can extend generic class, interface?

To extend a generic class or interface in Java, specify a type parameter that is a subclass or subinterface of the type parameter of the class or interface you are extending. For example, to extend a generic class MyClass<T>, you can define a subclass MySubClass<T extends MyClass>, and to extend a generic interface MyInterface<T>, you can define a subinterface MySubInterface<T extends MyInterface>. This allows you to create a class or interface that is generic and can work with multiple types that are related in a specific way.

What is final?

When a variable is declared with the final keyword, its value can't be modified, essentially, a constant. This also means that you must initialize a final variable. If the final variable is a reference, this means that the variable cannot be re-bound to reference another object, but the internal state of the object pointed by that reference variable can be changed i.e. you can add or remove elements from the final array or final collection. It is good practice to represent final variables in all uppercase, using underscore to separate words. Illustration: final int THRESHOLD = 5; The only difference between a normal variable and a final variable is that we can re-assign the value to a normal variable but we cannot change the value of a final variable once assigned. Hence final variables must be used only for the values that we want to remain constant throughout the execution of the program.

When finally block will be executed?

always after try catch block no matter what, even if an exception is thrown

What operators do you know?

and &&, or ||, assignment =, equality != ==, additive + -, multiplicative * / %

What modifiers do you know? What are the differences between them?

https://www.w3schools.com/java/java_modifiers.asp

What is static?

static means static variables belong to the class and can be used without initializing an object. Since they belong to the class they have only one instance.

Describe maven lifecycle. Each step.

validate - validate the project is correct and all necessary information is available compile - compile the source code of the project test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed package - take the compiled code and package it in its distributable format, such as a JAR. verify - run any checks on results of integration tests to ensure quality criteria are met install - install the package into the local repository, for use as a dependency in other projects locally deploy - done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.


Ensembles d'études connexes

Health Assessment Exam 3 Practice Questions

View Set

Introduction to Java Programming: Ch. 4 quiz

View Set

CHAPTER 7: Credit cards and consumer loans

View Set

1-Network Fundamentals - Basic Question_14548700_2023_01_05_20_23

View Set

PassPoint - Mood, Adjustment, and Dementia Disorders

View Set

NCLEX Questions for Nursing 102 Exam #2

View Set

Math SAT Level I - Chapter 4 Ratios and Proportions

View Set

E-business Management- Ch.10 Online Content and Media

View Set