THE ULTIMATE PANEL STUDY GUIDE REVATURE

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is JUnit?

"- JUnit is a testing framework to write repeatable tests for java programming language. - simple and open source - use to manage test script for WebDriver. "

What is multi-threading?

Multi threading is a programming concept to run multiple tasks in a concurrent manner within a single program. Threads share same process stack and running in parallel. It helps in performance improvement of any program.

Where are Strings stored in memory?

String pool, which is inside the heap

What is base class of all exceptions? What interface do they all implement?

Throwable: The Throwable class is the superclass of all errors and exceptions in the Java language

What is the difference between == and .equals()?

== -checks if both objects point to the same memory location. equals() evaluates to the comparison values in the objects.

How would you prevent a test from being run without commenting it out?

@Ignore annotation along with the @Test annotation.

Difference between FileReader and BufferedReader?

A FileReader class is a general tool to read in characters from a File. The BufferedReader class can wrap around Readers, like FileReader, to buffer the input and improve efficiency.

What is a POJO vs a bean?

A JavaBean follows certain conventions. Getter/setter naming, having a public default constructor, being serialisable A POJO (plain-old-Java-object) isn't rigorously defined. It's a Java object that doesn't have a requirement to implement a particular interface or derive from a particular base class, or make use of particular annotations in order to be compatible with a given framework, and can be any arbitrary (often relatively simple) Java object. Share

What is the difference between TreeSet and HashSet?

A TreeSet is a set where the elements are sorted. A HashSet is a set where the elements are not sorted or ordered. It is faster than a TreeSet.

What is the difference between an object and a class?

A class is a blueprint from which you can create the instance (objects). An object is the instance of the class, which helps programmers to use variables and methods from inside the class.

Can abstract methods have concrete methods? Can concrete (non-abstract) classes have abstract methods?

A concrete class cannot contain abstract methods. Abstract methods can have concrete methods.

What is a Marker interface? What does Serializable interface do?

A marker interface is an interface that has no methods or constants inside it. It provides run-time type information about objects, so the compiler and JVM have additional information about the object. Serializable interface. Serializable is a marker interface (has no data member and method). It is used to "mark" Java classes so that the objects of these classes may get a certain capability. ... It must be implemented by the class whose object you want to persist.

What is the difference between an Array and an ArrayList?

An array is a fixed length data structure that can hold both primitives and objects. An ArrayList is a variable length collection class that can only store objects.

What is the purpose of the Iterable interface? What about Iterator?

An iterable interface allows an object to be the target of enhanced for loop(for-each loop). Iterator in Java is used to traverse each and every element in the collection.

What are annotations?

Annotations - Java annotations are used to provide meta data for your Java code. Being meta data, Java annotations do not directly affect the execution of your code, although some types of annotations can actually be used for that purpose.

What is the difference between ArrayList and Vector?

ArrayList is non-synchronized. Vector is synchronized. ArrayList increments 50% of its current size if element added exceeds its capacity. Vector increments 100% of its current size if element added exceeds its capacity.

What is autoboxing / unboxing?

Autoboxing is the automatic conversion that the java compiler makes between the primitive types and their corresponding wrapper classes. Unboxing is the conversion from a primitive wrapper type back to a regular primitive type.

Why are strings immutable in java? How would you make your own objects immutable?

Being immutable automatically makes the String thread safe since they won't be changed when accessed from multiple threads. Don't add any setter method. Declare all fields final and private.

In what ways can you create a thread?

By extending the Thread Class or by implementing the Runnable Interface Extends Thread class. Create a thread by a new class that extends Thread class and create an instance of that class.

What is Maven?

Maven is a project management and comprehension tool. Maven provides developers a complete build lifecycle framework. Development team can automate the project's build infrastructure in almost no time as Maven uses a standard directory layout and a default build lifecycle.

What can you do with the Reflections API that you can't do in normal code?

Reflection is also more powerful: you can retrieve the definition of a protected or final member, remove the protection and manipulate it as if it had been declared mutable!

Explain the principles of the SOLID acronym

SOLID stands for: S - Single-responsiblity Principle. O - Open-closed Principle. L - Liskov Substitution Principle. I - Interface Segregation Principle. D - Dependency Inversion Principle

How do you serialize / deserialize an object in Java?

Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory.

What are the interfaces in the Collections API?

Set List Queue

What are Singleton / Factory design patterns?

Singleton pattern is a design pattern in which only one instance of a class is present in the Java virtual machine. A singleton class (implementing singleton pattern) has to provide a global access point to get the instance of the class. In other words, a singleton pattern restricts the instantiation of a class.

List several ways to iterate over a Collection. How would you iterate over a Map?

You can use a while loop, a for loop, or a for-each loop to iterate over a Collection. You can use a for-each loop, keySet() and values method, or Map.Entry<K, V> for a Map.

List some classes and methods of the Reflections API

getMethod() getDeclaredMethod()

What is the difference between the Comparable and Comparator interfaces?

:Comparable: The class whose objects you want to sort must implement comparable interface. It provides single sorting sequences. Comparator: Class, whose objects you want to sort, do not need to implement a comparator interface. It provides multiple sorting sequences.

What is the difference between final, .finalize(), and finally?

Finally is used to place important code, it will be executed whether exception is handled or not. Finalize is used to perform clean up processing just before object is garbage collected. Final is a keyword. Finally is a block.

What are generics? What is the diamond operator (<>)?

Generics allow type (Integer, String, ... etc, and user-defined types) to be a parameter to methods, classes, and interfaces. Using Generics, it is possible to create classes that work with different data types. The purpose of the diamond operator is to simplify instantiation of generic classes.

What is the difference between HashTable and HashMap?

HashMap is non synchronized. It is not-thread safe and can't be shared between many threads without proper synchronization code whereas Hashtable is synchronized. ... HashMap allows one null key and multiple null values whereas Hashtable doesn't allow any null key or value.

If two objects are equal, do they have the same hashcode? If not equal?

If the objects are equal, then they must have the same hashcode. If two objects have the same hashcode then they are NOT necessarily equal. So not equal objects may have the same hashcode.

What is a stored procedure and how would you call it in Java?

1. User defined piece of code written in SQL which may return a value that is invoked by calling it explicitly. 2. Invoke the connection.preparecall method to create a callable statement object ,Invoke callable statement object, Invoke callablestatement.registeroutparameter, Invoke callablestatement.get, Invoke callablestatement.close

What is a stack frame? When are these created?

A stack frame is a frame of data that gets pushed onto the stack. In the case of a call stack, a stack frame would represent a function call and its argument data. When a function is called, a new stack frame is created at the current esp location. A stack frame acts like a partition on the stack.

What are transient variables?

A transient variable is a variable that can not be serialized.

What is the difference between an abstract class and an interface?

Abstract classes can have constants, members, method stubs (method without a body) and defined methods. An interface can only have constants and method stubs.

What are the 4 pillars of OOP? Explain each and give examples of you implement them in Java code

Abstraction - the process of showing only essential features of an entity/object to the outside world and hiding the irrelevant information. Encapsulation - wrapping up data and member function together into a single unit. Another way to think about encapsulation is, it is a protective shield that prevents the data from being accessed by the code outside this shield. Inheritance - enables new objects to take on the properties of existing objects. There is single inheritance, mulit-level inheritance, and hierarchical inheritance. You can use inheritance to create a series of classes that inherit from one another for example a dog class that inherits from an animal class. Polymorphism - the ability to redefine methods for derived classes.An example of this would be creating a child and a parent class and having the child inherit from the parent and then overriding some of the parents methods.

How would you perform constructor chaining?

Calling a constructor from the another constructor of same class is known as Constructor chaining. The real purpose of Constructor Chaining is that you can pass parameters through a bunch of different constructors, but only have the initialization done in a single place.

What are collections in Java?

Collections are a framework that provides an architecture to store and manipulate a group of objects.

Which interface is responsible for transaction management?

Connection Interface

What are covariant return types? What rules apply to return types for overridden methods?

Covariant return type refers to return type of an overriding method. It allows to narrow down return type of an overridden method without any need to cast the type or check the return type. Covariant return type works only for non-primitive return types.

What are the logging levels of log4j?

DEBUG Level. INFO Level. WARN Level. ERROR Level. FATAL Level. ALL Level. OFF Level. TRACE Level.

What are the core interfaces / classes in JDBC?

DriverManager, Driver, Statement, PreparedStatement, CallableStatement, Connection, ResultSet, ResultSetMetaData.

What is an enhanced for loop and what is a forEach loop?

Enhanced for loop - is a loop that executes in sequence, the counter is always increased by one and can only iterate in incremental order. forEach loop - is a loop that processes an instance of each element in a collection. A forEach loop cannot modify a collection.

What are enumerations (enums)?

Enumerations represent a group of constants.

Steps to executing an SQL query using JDBC.

Establish a connection. Create a statement. Execute a query. Process the ResultSet Object. Close the connection.

When do you use extends or implements keywords?

Extends is used when you want attributes of a parent class or interface, extends does not have to use all of the methods in a super class.Implements is used when you want attributes of an interface in your class, implements has to use all of the methods of the interface.

Can you force garbage collection in Java? When is an object eligible for GC?

If you want to force garbage collection you can use the System object from the java. lang package and its gc() method or the Runtime. An object is marked as eligible to be garbage collected when it can no longer be accessed, which can happen when the object goes out of scope. It can also happen when an object's reference variable is assigned an explicit null value or is reinitialized.

What makes a class immutable?

Immutable class means that once an object is created, we cannot change its content. In Java, all the wrapper classes (like Integer, Boolean, Byte, Short) and String class is immutable

How to pass multiple values with a single parameter into a method?

Implement the use of an Array or a Collection.

Multi-catch block - can you catch more than one exception in a single catch block?

In Java SE 7 and later, a single catch block can handle more than one type of exception. This feature can reduce code duplication and lessen the temptation to catch an overly broad exception.

Are Maps in the Collections API? What makes Map different from other interfaces?

Map is not a part of the Collections API. A map cannot contain duplicate values. Each key can map to one value.

What are the 3 usages of "super" keyword?

It can refer to the immediate parent class of an instance. It can invoke immediate parent class method It can invoke immediate parent class constructor and should be the first line in a child class constructor.

What is JDBC?

JDBC is a set of Java API for executing SQL statements. This API consists of a set of classes and interfaces to enable programs to write pure Java Database applications.

What is JRE / JDK / JVM?

JRE - Java Runtime Environment is a software layer that runs on top of a computer's operating system software and provides the class libraries and other resources that a specific Java program needs to run. JDK - The Java Development Kit is the on-disk part of Java that creates the Java Virtual Machine. JVM - Java Virtual Machine is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode.

What are the annotations in JUnit? Order of execution?

JUNIT ANNOTATIONS is a special form of syntactic meta-data that can be added to Java source code for better code readability and structure. @BeforeClass Executed before the first @Test method in JUnit test class @Before Executed before all the @Test methods @Test Executed for all @Test methods @After Executed after all @Test methods

What is Java? / Explain some features of Java

Java is a class based, object oriented programming language that is designed to have the least implementation dependencies possible.

Is Java pass by value or pass by reference?

Java is strictly pass by value.

What is a static block?

Java static block is the group of statements that gets executed when the class is loaded into memory by Java ClassLoader. It is used to initialize static variables of the class. Mostly it's used to create static resources when class is loaded.

What is the difference between a Set and a List?

List is a type of ordered collection that maintains the elements in insertion order and it allows duplicates. Set is a type of unordered collection so elements are not maintained in any order and it does not allow duplicates.

What is log4j?

Log4J is a logging infrastructure that helps in collecting information about the executions that were run. Also helps you track different logging levels including trace, debug, info, warn, error, and fatal.

What are the advantages to using a logging library?

Logging libraries provide APIs for creating, structuring, formatting, and transmitting log events in a consistent way.

What is the difference between method overloading and overriding? What are the rules for changing the method signature of overloaded methods?

Method Overloading is a compile time polymorphism. In method overloading, return type doesn't have to be the same, but you must change the parameters. Method overriding is a run time polymorphism. In method overriding the derived class provides the specific implementation of the method that is already provided by the base class or parent class. Return type must be the same. Method overloading may have different return types, different access modifiers, throw different checked or unchecked exceptions.

Explain the lifecycle of a thread.

New - The thread is in new state if you create an instance of Thread class but before the invocation of start() method. Runnable - The thread is in runnable state after invocation of start() method, but the thread scheduler has not selected it to be the running thread. Running - The thread is in running state if the thread scheduler has selected it. Non-Runnable (Blocked) - This is the state when the thread is still alive, but is currently not eligible to run. Terminated - A thread is in terminated or dead state when its run() method exits.

Can you overload / override a main method? static method? a private method? a default method? a protected method?

No you can't override a main method but, you can overload a main method. No you can't override a static method but you can overload a static method. No you can't override a private method, but you can overload a private method .No you can't override a default method, but you can overload a default method. Yes you can override a protected method, and you can overload a protected method.

How to execute stored procedures using JDBC?

Prepare the callable statement, Register the output parameters, Set the input parameters, Execute the callable statement.

What is Reflection API?

Reflection is an API which is used to examine or modify the behavior of methods, classes, interfaces at runtime. Reflection gives us information about the class to which an object belongs and also the methods of that class which can be executed by using the object.

What is the difference between Statement and PreparedStatement?

Statement will be used for executing static SQL statements and can't accept parameters. PreparedStatement will be used for executing SQL statements many times dynamically. It will accept input parameters.

What are static imports?

Static Imports - allow fields and methods which have been scoped within their container class as public static, to be used in Java code without specifying the class in which the field has been defined.

Can static methods access instance variables? Can non-static methods access static variables?

Static methods cannot access instance variables. Non-static methods can access static variables.

List all non-access modifiers.

Static, Final, Abstract, Synchronized, Volatile, Transient

What are the non-access modifiers in Java?

Static, Final, Abstract, Synchronized, Volatile, Transient

What is TDD?

Test Driven Development. Unit Test fail fix

What is the difference between String, StringBuilder, and StringBuffer?

The String class is an immutable class whereas StringBuffer and StringBuilder classes are mutable. StringBuffer is synchronized i.e. thread safe. It means two threads can't call the methods of StringBuffer simultaneously. StringBuilder is non-synchronized i.e. not thread safe.

What is the default Maven build lifecycle?

The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project's site documentation.

What is the first line of any constructor?

The first line is either a call on the superclass constructor or on another constructor in the same class (this()).

What are the implicit modifiers for interface variables? Methods?

The implicit modifiers for interface variables are public, static, and final. The implicit modifiers for interface methods are public.

Where / when does Maven retrieve dependencies from? Where are they stored locally?

The local repository of Maven is a directory on the local machine, where all the project artifacts are stored. Maven local repository by default get created by Maven in %USER_HOME% directory.

What is the difference between static and final variables?

The main difference between a static and final keyword is that static is keyword is used to define the class member that can be used independently of any object of that class. Final keyword is used to declare, a constant variable, a method which can not be overridden and a class that can not be inherited.

Explain stack vs heap

The major difference between Stack memory and heap memory is that the stack is used to store the order of method execution and local variables while the heap memory stores the objects

How would you create a Singleton?

The most popular approach is to implement a Singleton by creating a regular class and making sure it has: A private constructor. A static field containing its only instance. A static factory method for obtaining the instance.

Explain the try-with-resources syntax

The try -with-resources statement is a try statement that declares one or more resources. A resource is an object that must be closed after the program is finished with it. The try -with-resources statement ensures that each resource is closed at the end of the statement.

What data types are supported in switch statements?

The value of the expressions in a switch-case statement must be an ordinal type i.e. integer, char, short, long, etc. Float and double are not allowed. The case statements and the default statement can occur in any order in the switch statement.

Are variable references stored on the stack or heap? What about the objects they refer to?

The variable references are stored in the stack and objects are stored in the heap.

List the methods in the Thread class and Runnable interface

Thread Class: run() - Entry point for a thread sleep() - suspend thread for a specified time start() - start a thread by calling run() method activeCount() = Returns an estimate of the number of active threads in the current thread's thread group and its subgroups. Runnable Interface: public void run() - This method takes in no arguments. When the object of a class implementing Runnable class is used to create a thread, then the run method is invoked in the thread which executes separately.

What is a deadlock?

When two threads are waiting each other and can't precede the program is said to be deadlock.

What happens if you don't define a constructor for a class? Can you still instantiate it?

When we do not explicitly define a constructor for a class, then java creates a default constructor for the class. It is essentially a non-parameterized constructor, i.e. it doesn't accept any arguments. The default constructor's job is to call the super class constructor and initialize all instance variables.

What is a wrapper class? List them.

Wrapper classes provide a way to use primitive data types as objects. boolean - Boolean byte - Byte short - Short char - Character int - Integer float - Float double - Double long - Long

Do you need a catch block? Can you have more than 1? Is there an order to follow?

Yes, we can have try without catch block by using finally block. You can use try with finally. As you know finally block always executes even if you have exception or return statement in try block except in case of System.

What are the default values for all data types in Java?

boolean -> false byte -> 0 short -> 0 char -> '\u0000' int -> 0 float -> 0.0f double -> 0.0d long -> 0L

What are the primitive data types in Java?

boolean -> size = 1 bit byte -> size = 1 byte short -> size = 2 bytes char -> size = 2 bytes int -> size = 4 bytes float -> size = 4 bytes double -> size = 8 bytes long -> size = 8 bytes

List some checked and unchecked exceptions?

checked exceptions: IOException SQLException ParseException unchecked exceptions: NullPointerException. ArrayIndexOutOfBoundsException. ArithmeticException. IllegalArgumentException. NumberFormatException.

What is the root class from which every class extends?

java.lang.Object

List some methods in the Scanner class

nextDouble() Reads a double value from the user nextFloat() Reads a float value from the user nextInt() Reads an int value from the user nextLine() Reads a String value from the user

What are the access modifiers in Java? Explain them.

public - Visible to the world protected - Visible to the package and all subclasses. Default - Visible to the package, no modifiers needed. private - Visible to the class only.

Create and instantiate a generic class. Create and use a generic method.

public class Box<T> { // T stands for "Type" private T t; public void set(T t) { this.t = t; } public T get() { return t; } }

What are the different variable scopes in Java?

static / class scope object / instance scope method scope block scope

What is the synchronized keyword?

synchronized keyword - acts like a lock to a particular resource. This helps achieve communication between threads such that only one thread accesses the synchronized resource and other threads wait for the resource to become free.

Explain throw vs throws vs Throwable

throws : Used when writing methods, to declare that the method in question throws the specified (checked) exception. ... throw : Instruction to actually throw the exception. (Or more specifically, the Throwable). The throw keyword is followed by a reference to a Throwable (usually an exception).

What methods are available in the Object class?

toString() hashCode() equals(Object obj) getClass() finalize() clone() wait() notify() notifyAll()


संबंधित स्टडी सेट्स

Fundamentals of Nursing: Chapter 40: Fluid, Electrolyte, and Acid-Base Balance

View Set

Principles of Real Estate I: Ethics of Practice as License Holder

View Set

AP Psychology Psychological Disorders Study Guide

View Set