Section 1

Preview this deck

Does Java use pointers?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (15)

Section 1

(15 cards)

Does Java use pointers?

Front

No, they can be unsafe and cause more complexity.

Back

Define a class in Java.

Front

A class in Java is a blueprint which includes all your data. A class contains fields (variables) and methods to describe the behavior of an object.

Back

Java vs. Kotlin

Front

Kotlin has Null Safety. Variables can't be null unless using a question mark. value num: Int? = null. Extension functions are available in Kotlin and not in Java. No checked exceptions in Kotlin

Back

What are wrapper classes in Java?

Front

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.

Back

What are the main concepts of OOPs in Java?

Front

1. Inheritance: Inheritance is a process where one class acquires the properties of another. 2. Encapsulation: Encapsulation in Java is a mechanism of wrapping up the data and code together as a single unit. 3. Abstraction: Abstraction is the methodology of hiding the implementation details from the user and only providing the functionality to the users. 4. Polymorphism: Polymorphism is the ability of a variable, function or object to take multiple forms.

Back

What are access modifiers in Java?

Front

Keywords which are used to restrict the access of a class, constructor, data member and method in another class. 1. Default 2. Private 3. Protected 4. Public

Back

What is an Interface and what can it do in Java?

Front

An interface cannot provide any code at all, just the signature. A Class may implement several interfaces. All methods of an Interface are abstract. An Interface cannot have instance variables. An Interface visibility must be public (or) none. If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method. An Interface cannot contain constructors. Interfaces are slow as it requires extra indirection to find the corresponding method in the actual class.

Back

What is special about Heap memory (vs Stack memory)?

Front

Memory: Heap memory is used by all the parts of the application. Access: Objects stored in the heap are globally accessible. Memory Management: Memory management is based on the generation associated with each object. Lifetime: Heap memory lives from the start till the end of application execution. Usage: Whenever an object is created, it's always stored in the Heap space.

Back

Why use composition over inheritance in Java?

Front

1. Java doesn't support multiple inheritance. 2. Composition offers better test-ability of a class than Inheritance. 3. Though both Composition and Inheritance allows you to reuse code, one of the disadvantage of Inheritance is that it breaks encapsulation.

Back

What is the difference between equals() and == in Java?

Front

equals(Object o) is the method provided by the Object class. The default implementation uses == operator to compare two objects. For example: method can be overridden like String class. equals() method is used to compare the values of two objects.

Back

What is an Abstract Class and what can it do in Java?

Front

An abstract class can provide complete, default code and/or just the details that have to be overridden. In the case of an abstract class, a class may extend only one abstract class. An abstract class can have non-abstract methods. An abstract class can have instance variables. An abstract class can have any visibility: public, private, protected. If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly. An abstract class can contain constructors. Abstract classes are fast.

Back

Explain public static void main(String args[]) in Java.

Front

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 if 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 instantiated 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.

Back

What is final keyword in Java? (for variable, methods, and classes)

Front

"final" is a special keyword in Java that is used as a non-access modifier. A final variable can be used in different contexts such as: final variable When the final keyword is used with a variable then its value can't be changed once assigned. In case the no value has been assigned to the final variable then using only the class constructor a value can be assigned to it. final method When a method is declared final then it can't be overridden by the inheriting class. final class When a class is declared as final in Java, it can't be extended by any subclass class but it can extend other class.

Back

What is an object in Java and how is it created?

Front

An object is a real-world entity that has a state and behavior. An object has three characteristics: 1. State 2. Behavior 3. Identity

Back

What is special about Stack memory (vs Heap memory)?

Front

Memory: Stack memory is used only by one thread of execution. Access: Stack memory can't be accessed by other threads. Memory Management: Follows LIFO manner to free memory. Lifetime: Exists until the end of execution of the thread. Usage: Stack memory only contains local primitive and reference variables to objects in heap space.

Back