Java Fundamentals Flashcards

1
Q

What is Java?

A

Java is a class-based, object-oriented, platform-independent programming language that is designed to have as few implementation dependencies as possible.

	▪ Class-based and object-oriented: Allows grouping of objects that can be used across projects, saving you time  
	▪ Portable: Java runs on a ‘write once, use anywhere’ principle, meaning that once you have written code it can be used on other projects, rather than starting from scratch
	▪ Secure: Once created, all Java code is converted to bytecode, which cannot be read by humans, protecting your work from untrusted sources and viruses
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does Java do?

A

▪ Write software on one platform and run it on virtually any other platform.
▪ Create programs that can run within a web browser and access available web services.
▪ Develop server-side applications for online forums, stores, polls, HTML forms processing, and more.
▪ Combine applications or services using the Java language to create highly customized applications or services.
Write powerful and efficient applications for mobile phones, remote processors, microcontrollers, wireless modules, sensors, gateways, consumer products, and practically any other electronic device.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Is Java a pure object-oriented language?

A

No, because it uses primitive data types like ‘int’, ‘char’, and others, not just objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are wrapper classes in Java?

A

Wrapper classes are classes that are used to convert primitives into objects. They are used when developers need to have ‘null’ state or when other classes require an object (e.g. collections).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are abstract methods? Can an abstract class be final?

A
An abstract method is a method that is declared without an implementation. 
	An abstract class cannot be final because 
		- abstract classes can't be instantiated, and 
final classes can't be extended.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Does Java support multiple parent inheritance?

A
No, it is not possible to 'extend' more than one class in Java; 
	However, it is possible to implement multiple interfaces!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the “diamond problem” in the context of multiple inheritance? How is it solved in Java?

A

a. “Diamond problem” appears when a superclass A defines a method M, which is overridden by two classes B and C with their implementation. When single class D extends both B and C classes, it’s not clear which implementation should be used.
b. In Java, interfaces with default methods are used, so when an implementation class is made, it is necessary to specify the behavior in case of the same method conflict.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is method overloading?

A

(Static or Compile Time Polymorphism) Method overloading is the implementation of two methods for a class with the same name but different parameters.

				static int add(int a, int b) {
					return a+b;
				}  
				static int add(int a, int b, int c) {
					return a+b+c;
				}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is method overriding?

A

(Dynamic or Runtime Polymorphism) A method is overridden when a superclass’ method is implemented differently by a subclass but still has the same name and parameters.

				class Vehicle {  
				void run() {
					System.out.println("Vehicle is running");
					}  
				}  
				class Bike2 extends Vehicle {   
				void run() {
					System.out.println("Bike is running safely");
					}  
				}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Can you pass objects by value?

A

Yes. Object variables are references to the objects in the memory. Passing an object passes its reference, but the reference itself is still passed by value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Can you pass objects by reference?

A

No. Java parameters can only be passed by value. However, since object variables are just references, changing the object inside a function will make change to the original object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Can you modify an object that is passed to a function?

A

Yes. An object that is passed to a function can be modified inside that function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

(Functional Programming) What is a function with side-effects?

A

A function with side-effects means that it changes the state or value of something outside its scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly