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
how many times a constructor is called?
only once at the intialization of the object
26
can u overload constructors?
yes
27
can u call a constructor inside of another construcotr
yes by using this()
28
what is the only rule to call a constructor inside of another constructor?
the call must be in the first line
29
what is mandatory when u create a class that extends another class?
u must create a default constructor to call the parent constructor
30
what is super keyword?
it deals with methods and field of parent class
31
what is a class?
it's the blueprint to make objects from
32
what is an object or an instance?
it's an instance of a class
33
what is a reference
it's the variable holding the address pointing to that object in memory
34
what happens when u change something on one reference?
it changes the other as both of them point to the same physical entity
35
what is derefrencing?
it's making one reference point to another object
36
is there anyway to access the object directly?
no u must have a reference
37
what is a common way to call super
when overriding a method in a parent class
38
what is this keyword
it's user to reference methods or variables in the same class
39
this() vs super()
this or super calls the constructor and it must be the first statement and they can only be used in a constructor
40
can u call this() and super() at the same time?
No
41
is overloading related to polymorphism?
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
can u overload a static method?
yes as well as instance methods
43
can u overload in a subclass?
yes by having a different name
44
what are the rules for method overloading?
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
what is a method overriding?
it's defining a method with the same name and arguments (same signature) that already exists in the parent class
46
what the the overriding polymorphism called?
RunTime polymorphism or run time dispatch because the method that is getting called is decided at run time by the JVM
47
what is @Override
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
can we override a static method?
No we can only override an instance method
49
what are the rules for method overriding?
``` 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
what are the methods that can't be overriden?
constructors , private , final
51
can overriden method throw a broader exception or different one?
no
52
what is a covariant return type?
when a class extends another class they are called covariants
53
what is a static method?
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
how do u call a static method?
with the class name
55
how to access an instance method?
u must have an instance of the class and they can access static and instance methods and variables
56
static or instance method?
if u use any instance variable? then use instance else use static
57
what is a static variable?
it's a variable shared among all the instances of that class so if that variable changes then all other instances change
58
an example to use a static variable?
scanner
59
what is an instance variable?
every instance of a class has a copy of that variable
60
what is encapsulation?
it's protecting the inner workings of a class from outside behavior
61
what is the type of primitive?
value types meaning they are copied where each variable works independently
62
what is the type of an object or an array
reference type which means that the address get stored both pointing to the same object