Revature Java Interview

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

Extending Multiple Interfaces

A Java class can only extend one parent class. Multiple inheritance is not allowed. Interfaces are not classes, however, and an interface can extend more than one parent interface.

The Set Interface

A Set is a Collection that cannot contain duplicate elements. It models the mathematical set abstraction.

Abstract Class

A class which is declared as abstract is known as an abstract class. It can have abstract and non-abstract methods. It needs to be extended and its method implemented. It cannot be instantiated. Some points to remember : An abstract class must be declared with an abstract keyword. It can have abstract and non-abstract methods. It cannot be instantiated. It can have constructors and static methods also. It can have final methods which will force the subclass not to change the body of the method.

Class

A class, in the context of Java, are templates that are used to create objects, and to define object data types and methods. Core properties include the data types and methods that may be used by the object

Do..While Loop

A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.

For Loop

A for loop is a repetition control structure that allows you to efficiently write a loop that needs to be executed a specific number of times.

Foreign Key

A foreign key is a key used to link two tables together. This is sometimes also called as a referencing key. A Foreign Key is a column or a combination of columns whose values match a Primary Key in a different table. The relationship between 2 tables matches the Primary Key in one of the tables with a Foreign Key in the second table.

Package?

A java package is a group of similar types of classes, interfaces and sub-packages. Package in java can be categorized in two form, built-in package and user-defined package.

Loops In Java

A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages.

Catching Exceptions

A method catches an exception using a combination of the try and catch keywords. A try/catch block is placed around the code that might generate an exception.

Abstract Method

A method which is declared as abstract and does not have implementation is known as an abstract method.

Primary Key

A primary key is a field in a table which uniquely identifies each row/record in a database table. Primary keys must contain unique values. A primary key column cannot have NULL values. A table can have only one primary key, which may consist of single or multiple fields. When multiple fields are used as a primary key, they are called a composite key. If a table has a primary key defined on any field(s), then you cannot have two records having the same value of that field(s).

Relational Database Management System

A relational database management system (RDBMS) is a program that allows you to create, update, and administer a relational database. Most relational database management systems use the SQL language to access the database.

SWITCH Statement

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.

While Loop

A while loop statement in Java programming language repeatedly executes a target statement as long as a given condition is true.

Exception Hierarchy

All exception classes are subtypes of the java.lang.Exception class. The exception class is a subclass of the Throwable class. Other than the exception class there is another subclass called Error which is derived from the Throwable class.

Object

An Object can be defined as an instance of a class. An object contains an address and takes up some space in memory. Objects can communicate without knowing the details of each other's data or code. The only necessary thing is the type of message accepted and the type of response returned by the objects.

IF..ELSE IF Statement

An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement. When using if, else if, else statements there are a few points to keep in mind. An if can have zero or one else's and it must come after any else if's. An if can have zero to many else if's and they must come before the else. Once an else if succeeds, none of the remaining else if's or else's will be tested.

IF..ELSE Statement

An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.

IF Statement

An if statement consists of a Boolean expression followed by one or more statements.

Similarities between an interface and a class

An interface can contain any number of methods. An interface is written in a file with a .java extension, with the name of the interface matching the name of the file. The byte code of an interface appears in a .class file. Interfaces appear in packages, and their corresponding bytecode file must be in a directory structure that matches the package name.

Extending Interfaces

An interface can extend another interface in the same way that a class can extend another class. The extends keyword is used to extend an interface, and the child interface inherits the methods of the parent interface.

Interface?

An interface is a reference type in Java. It is similar to class. It is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. Along with abstract methods, an interface may also contain constants, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods. Writing an interface is similar to writing a class. But a class describes the attributes and behaviors of an object. And an interface contains behaviors that a class implements. Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class.

Declaring Interfaces

An interface is implicitly abstract. You do not need to use the abstract keyword while declaring an interface. Each method in an interface is also implicitly abstract, so the abstract keyword is not needed. Methods in an interface are implicitly public.

Polymorphism

Any Java object that can pass more than one IS-A test is considered to be polymorphic. In Java, all Java objects are polymorphic since any object will pass the IS-A test for their own type and for the class Object.

ArrayList

ArrayList is a part of collection framework and is present in java.util package. It provides us dynamic arrays in Java. Though, it may be slower than standard arrays but can be helpful in programs where lots of manipulation in the array is needed.

Enhanced For Loop

As of Java 5, the enhanced for loop was introduced. This is mainly used to traverse collection of elements including arrays.

Categories of Exceptions

Checked Exceptions Unchecked Exceptions Errors

Advantages of Arrays

Code Optimization: It makes the code optimized, we can retrieve or sort the data efficiently. Random access: We can get any data located at an index position

Encapsulation

Encapsulation in Java is a process of wrapping code and data together into a single unit, for example, a capsule which is mixed of several medicines.

Unchecked Exceptions

Errors and RuntimeExceptions are unchecked — that is, the compiler does not enforce (check) that you handle them explicitly. Methods do not have to declare that they throw them (in the method signatures). It is assumed that the application cannot do anything to recover from these exceptions (at runtime).

Exceptions?

Exceptions are events that occur during the execution of programs that disrupt the normal flow of instructions (e.g. divide by zero, array access out of bound, etc.). In Java, an exception is an object that wraps an error event that occurred within a method and contains: Information about the error including its type The state of the program when the error occurred Optionally, other custom information

Generalization

Generalization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass. Shared characteristics can be attributes, associations, or methods.

Method Overloading

If a class has multiple methods having same name but different in parameters, it is known as Method Overloading

Method Overriding

If a subclass provides the specific implementation of the method that has been declared by one of its parent class, it is known as method overriding.

"this" : to refer current class instance variable

If there is ambiguity between the instance variables and parameters, this keyword resolves the problem of ambiguity.

Static variable

If you declare any variable as static, it is known as a static variable. The static variable can be used to refer to the common property of all objects (which is not unique for each object), for example, the company name of employees, college name of students, etc. The static variable gets memory only once in the class area at the time of class loading.

Using packagename.classname

If you import package.classname then only declared class of this package will be accessible.

Using fully qualified name

If you use fully qualified name then only declared class of this package will be accessible. Now there is no need to import. But you need to use fully qualified name every time when you are accessing the class or interface. It is generally used when two packages have same class name e.g. java.util and java.sql packages contain Date class.

Using packagename.*

If you use package.* then all the classes and interfaces of this package will be accessible but not subpackages. The import keyword is used to make the classes and interface of another package accessible to the current package.

Usage of "this" keyword

In java, this is a reference variable that refers to the current object.

Design

In systems design the design functions and operations are described in detail, including screen layouts, business rules, process diagrams and other documentation. The output of this stage will describe the new system as a collection of modules or subsystems.

Nested IF Statement

It is always legal to nest if-else statements which means you can use one if or else if statement inside another if or else if statement.

Advantages of Encapsulation

It provides you the control over the data. Suppose you want to set the value of id which should be greater than 100 only, you can write the logic inside the setter method. You can write the logic not to store the negative numbers in the setter methods.

Relational Database

It uses a structure that allows us to identify and access data in relation to another piece of data in the database. Often, data in a relational database is organized into tables.

Advantages Of Packages

Java package is used to categorize the classes and interfaces so that they can be easily maintained. Java package provides access protection. Java package removes naming collision.

String Length

Methods used to obtain information about an object are known as accessor methods. One accessor method that you can use with strings is the length() method, which returns the number of characters contained in the string object.

Can a static method be overridden?

No, a static method cannot be overridden. It is because the static method is bound with class whereas instance method is bound with an object. Static belongs to the class area, and an instance belongs to the heap area.

Advantages of OOPs over Procedure Oriented Programming

OOPs makes development and maintenance easier whereas in a procedure-oriented programming language it is not easy to manage if code grows as project size increases. OOPs provides data hiding whereas in a procedure-oriented programming language a global data can be accessed from anywhere.

SELECT Query

SELECT statement is used to fetch the data from a database table which returns this data in the form of a result table.

Sequence of program

Sequence of the program must be package then import then class.

Types of Array

Single Dimensional Array Multidimensional Array

4 Types Of Inheritance In Java

Single, Multi-level, Hierarchical, Hybrid

Disadvantages of Arrays

Size Limit: We can store only the fixed size of elements in the array. It doesn't grow its size at runtime. To solve this problem, collection framework is used in Java which grows automatically.

Specialization

Specialization means creating new subclasses from an existing class. If it turns out that certain attributes, associations, or methods only apply to some of the objects of the class, a subclass can be created.

Investigation

The 1st stage of SDLC is the investigation phase. During this stage, business opportunities and problems are identified, and information technology solutions are discussed.

Collection Interface

The Collection interface is the foundation upon which the collections framework is built. It declares the core methods that all collections will have.

The List Interface

The List interface extends Collection and declares the behavior of a collection that stores a sequence of elements. Elements can be inserted or accessed by their position in the list, using a zero-based index. A list may contain duplicate elements. In addition to the methods defined by Collection, List defines some of its own, which are summarized in the following table. Several of the list methods will throw an UnsupportedOperationException if the collection cannot be modified, and a ClassCastException is generated when one object is incompatible with another.

The Map Interface

The Map interface maps unique keys to values. A key is an object that you use to retrieve a value at a later date.

Queue

The Queue interface is available in java.util package and extends the Collection interface. The queue collection is used to hold the elements about to be processed and provides various operations like the insertion, removal etc. It is an ordered list of objects with its use limited to insert elements at the end of the list and deleting elements from the start of list i.e. it follows the FIFO or the First-In-First-Out principle. LinkedList, ArrayBlockingQueue and PriorityQueue are the most frequently used implementations.

WHERE Query

The SQL WHERE clause is used to specify a condition while fetching the data

Testing

The code is tested at various levels in software testing. Unit, system and user acceptance testings are often performed.

Checked Exceptions

The compiler enforces that you handle them explicitly. Methods that generate checked exceptions must declare that they throw them. Methods that invoke other methods that throw checked exceptions must either handle them (they can be reasonably expected to recover) or let them propagate by declaring that they throw them.

Operations and Maintenance

The deployment of the system includes changes and enhancements before the decommissioning or sunset of the system. Maintaining the system is an important aspect of SDLC. As key personnel change positions in the organization, new changes will be implemented, which will require system.

Final Keyword

The final keyword in java is used to restrict the user. The java final keyword can be used in many context. Final can be:

Finally Block

The finally block follows a try block or a catch block. A finally block of code always executes, irrespective of occurrence of an Exception. Using a finally block allows you to run any cleanup-type statements that you want to execute, no matter what happens in the protected code.

System Analysis

The goal of system analysis is to determine where the problem is in an attempt to fix the system.

Static Keyword

The static keyword in Java is used for memory management mainly. We can apply java static keyword with variables, methods, blocks and nested class. The static keyword belongs to the class than an instance of the class.

"this" : to invoke current class constructor

The this() constructor call can be used to invoke the current class constructor. It is used to reuse the constructor. In other words, it is used for constructor chaining.

Rules for SWITCH Statement

The variable used in a switch statement can only be integers, convertable integers (byte, short, char), strings and enums. You can have any number of case statements within a switch. Each case is followed by the value to be compared to and a colon. The value for a case must be the same data type as the variable in the switch and it must be a constant or a literal. When the variable being switched on is equal to a case, the statements following that case will execute until a break statement is reached. When a break statement is reached, the switch terminates, and the flow of control jumps to the next line following the switch statement. Not every case needs to contain a break. If no break appears, the flow of control will fall through to subsequent cases until a break is reached. A switch statement can have an optional default case, which must appear at the end of the switch. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case.

Errors

These are not exceptions at all, but problems that arise beyond the control of the user or the programmer. Errors are typically ignored in your code because you can rarely do anything about an error. For example, if a stack overflow occurs, an error will arise. They are also ignored at the time of compilation.

Why is multiple inheritance is not supported in Java?

To reduce the complexity and simplify the language, multiple inheritance is not supported in java.

Implementing Interfaces

When a class implements an interface, you can think of the class as signing a contract, agreeing to perform the specific behaviors of the interface. If a class does not perform all the behaviors of the interface, the class must declare itself as abstract. A class uses the implements keyword to implement an interface. The implements keyword appears in the class declaration following the extends portion of the declaration.

Usage of the "new" keyword

When you are declaring a class in java, you are just creating a new data type. A class provides the blueprint for objects. You can create an object from a class.

Usage of "super" keyword

Whenever you create the instance of subclass, an instance of parent class is created implicitly which is referred by super reference variable.

Types Of Loops

While loop For loop Do..While loop

Differences between an interface and a class

You cannot instantiate an interface. An interface does not contain any constructors. All of the methods in an interface are abstract. An interface cannot contain instance fields. The only fields that can appear in an interface must be declared both static and final. An interface is not extended by a class, it is implemented by a class. An interface can extend multiple interfaces.

"this" : to invoke current class method

You may invoke the method of the current class by using the this keyword. If you don't use the this keyword, compiler automatically adds this keyword while invoking the method.

Inheritance

a mechanism in which one object acquires all the properties and behaviors of a parent object.

SQL - Structured Query Language

a programming language used to communicate with data stored in a relational database management system. SQL syntax is similar to the English language, which makes it relatively easy to write, read, and interpret.

What is a String?

a sequence of characters. In Java programming language, strings are treated as objects.

The Throw/Throws Keyword

f a method does not handle a checked exception, the method must declare it using the throws keyword. The throws keyword appears at the end of a method's signature. One can throw an exception, either a newly instantiated one or an exception that you just caught, by using the throw keyword. Understand the difference between throws and throw keywords, throws is used to postpone the handling of a checked exception and throw is used to invoke an exception explicitly.

Accessing a package from other packages

import package.*; import package.classname; fully qualified name.

Database

is a collection of information that is organized so that it can be easily accessed, managed and updated.

Abstraction

it shows only essential things to the user and hides the internal details, for example, sending SMS where you type the text and send the message. You don't know the internal processing about the message delivery.

Object-Oriented Programming

methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts

Array

n array is a collection of similar type of elements that have a contiguous memory location. Java array is an object which contains elements of a similar data type. It is a data structure where we store similar elements. We can store only a fixed set of elements in a Java array. Array in java is index-based, the first element of the array is stored at the 0 index.

4 types of java access modifiers

private default protected public

Tables : Rows and Columns

rows are often called records. Tables can also have many columns of data. Columns are labeled with a descriptive name (say, age for example) and have a specific data type.

Concatenating Strings

string1.concat(string2); This returns a new string that is string1 with string2 added to it at the end. You can also use the concat() method with string literals "My Name is".concat("Zara"); Strings are most commonly concatenated with the "+" operator "Hello," + " world" + "!"


Ensembles d'études connexes

Are you happy? Focus on vocabulary test 1

View Set

BATTLE OF THE BOOKS Questions & Answers 2016-2017

View Set