Java Flashcards

1
Q

what is JDK?

A

Java Development Kit and it’s used to create and run java programs

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

Main Method?

A

It is the entry point of any java program and like any other method it has a number of statements that execute a number of operations

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

Can reserved keywords used in any order?

A

no reserved keywords must be used in a specific order like public static void can’t be public void static

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

Statement

A

is a complete command to be executed and can contain one or more expressions

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

Variables

A

are a way to store our information in Ram

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

Declaration Statement

A

used to define a variable by giving it a datatype and a name and optionally an expression to set the initial value

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

how many data types are in java and what are they?

A

they r eight … int , float , double ,short , long , char , boolean , byte

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

Wrapper class

A

there is a wrapper class for each primitive type to be able to deal with the primitive types like methods and such

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

what are overflow and underflow?

A

is to exceed to maximum number or minimum number which in turn just skips to the opposite direction

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

how many bits does byte , short , int , long occupy in memory?

A

8 , 16 , 32 , 64

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

Casting

A

is the process of converting on type to another using (type)

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

which occupies more memory and has more percision float or double?

A

double has 64 bit and more precise while float has 32 bit

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

should we use float or double for precise calculations?

A

No. we should use BigDecimal class due to limitations of how float and double are stored in memory and that’s not a java problem

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

is Char type 1 byte or 2 bytes

A

it’s 2 bytes because it allows unicode to be stored meaning it’s 16 bit

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

Unicode

A

it’s an international encoding standard to represent characters or digits or symbols as unique numerics

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

what is a string?

A

a string is an immutable class of characters back to back which means it’s can’t be changed instead it is created again and the variable is assigned the new value and using this method is actually inefficient and better use StringBuffer

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

Operator

A

is a special symbol that performs an operation on two or more operands

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

Conditional logic

A

allow us to check to check for a condition and based on the result a certain piece of code is executed

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

Method OverLoading

A

it’s a feature that allows us to use the same name of method but different parameters meaning different implementations

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

an example of built in java overloading?

A

println

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

benefits of overloading

A

increase readability and re-usability and it’s easier to remember one method and achieves consistency in naming and flexibility

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

how to parse string

A

using wrapper.Parseprimitivetype

like Integer.parseint()

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

how to read user input?

A
by using the scanner class
Scanner scanner = new Scanner(System.in)
scanner.nextline()
scanner.nextint()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

do u have to create the constructor manually?

A

No java has a default constructor

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

how many times a constructor is called?

A

only once at the intialization of the object

26
Q

can u overload constructors?

A

yes

27
Q

can u call a constructor inside of another construcotr

A

yes by using this()

28
Q

what is the only rule to call a constructor inside of another constructor?

A

the call must be in the first line

29
Q

what is mandatory when u create a class that extends another class?

A

u must create a default constructor to call the parent constructor

30
Q

what is super keyword?

A

it deals with methods and field of parent class

31
Q

what is a class?

A

it’s the blueprint to make objects from

32
Q

what is an object or an instance?

A

it’s an instance of a class

33
Q

what is a reference

A

it’s the variable holding the address pointing to that object in memory

34
Q

what happens when u change something on one reference?

A

it changes the other as both of them point to the same physical entity

35
Q

what is derefrencing?

A

it’s making one reference point to another object

36
Q

is there anyway to access the object directly?

A

no u must have a reference

37
Q

what is a common way to call super

A

when overriding a method in a parent class

38
Q

what is this keyword

A

it’s user to reference methods or variables in the same class

39
Q

this() vs super()

A

this or super calls the constructor and it must be the first statement and they can only be used in a constructor

40
Q

can u call this() and super() at the same time?

A

No

41
Q

is overloading related to polymorphism?

A

No, but some developers like to call it compile time polymorphism because at compile time the compiler decided what method to call based and it’s name , return type , parameter list

42
Q

can u overload a static method?

A

yes as well as instance methods

43
Q

can u overload in a subclass?

A

yes by having a different name

44
Q

what are the rules for method overloading?

A

1 - must have the same name
2- different argument list

they may or may not have the following
1 - same return type
2 - throw an exception
3 - have different access modifiers

45
Q

what is a method overriding?

A

it’s defining a method with the same name and arguments (same signature) that already exists in the parent class

46
Q

what the the overriding polymorphism called?

A

RunTime polymorphism or run time dispatch because the method that is getting called is decided at run time by the JVM

47
Q

what is @Override

A

it’s an annotation that tells the compiler that we are overriding a method and it will show an error if we don’t override correctly

48
Q

can we override a static method?

A

No we can only override an instance method

49
Q

what are the rules for method overriding?

A
1 - they must have the same name and arguments
2- the return type can be a subclass of the parent
3 - the access modifier can't be a lower visibility of the parent class
50
Q

what are the methods that can’t be overriden?

A

constructors , private , final

51
Q

can overriden method throw a broader exception or different one?

A

no

52
Q

what is a covariant return type?

A

when a class extends another class they are called covariants

53
Q

what is a static method?

A

it’s a method that can’t be called with “this” which points to an instance of that method and it can’t access any instance method or instance variable

54
Q

how do u call a static method?

A

with the class name

55
Q

how to access an instance method?

A

u must have an instance of the class and they can access static and instance methods and variables

56
Q

static or instance method?

A

if u use any instance variable? then use instance else use static

57
Q

what is a static variable?

A

it’s a variable shared among all the instances of that class so if that variable changes then all other instances change

58
Q

an example to use a static variable?

A

scanner

59
Q

what is an instance variable?

A

every instance of a class has a copy of that variable

60
Q

what is encapsulation?

A

it’s protecting the inner workings of a class from outside behavior

61
Q

what is the type of primitive?

A

value types meaning they are copied where each variable works independently

62
Q

what is the type of an object or an array

A

reference type which means that the address get stored both pointing to the same object