Java General Concepts Flashcards

1
Q

What are the basics of a computer program?

A

Basically it is a list of instructions for the computer to follow. It will tell the computer about variables and methods and memory that needs to be allocated for these values.

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

How is code executed?

A

It is executed line by line. Except when there is conditionals attached to it and will only be run if the conditions are met.

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

Object Oriented Programming

A

Again with those instructions, the Class gives instructions on creating objects, it includes the variables and methods and the constructor to give the initial values to the object.

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

What is the this keyword?

A

It will reference the object that it is referring to

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

What happens if you do not specify a constructor?

A

It will revert back to the default constructor default(){}

it is the same as the class name with no parameters.

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

Objects are a run time item

A

That means that they do not exist until the program is running

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

What does all the work in a java applications?

A

Methods are what do all the work and the java program is looking for the main method.

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

What is the Stack?

A

When you hit run button, the program will run and will call the main method and will keep space in the main frame of the Stack. when the program goes to the next line it is also added to the stack and more space is given for variables. Once the method is executed it is removed from the stack. A stack maintains method invokations.

Java Stack memory is used for the execution of a thread. They contain method-specific values that are short-lived and references to other objects in the heap that is getting referred from the method.

Stack memory is always referenced in LIFO (Last-In-First-Out) order. Whenever a method is invoked, a new block is created in the stack memory for the method to hold local primitive values and reference to other objects in the method.

As soon as the method ends, the block becomes unused and becomes available for the next method.
Stack memory size is very less compared to Heap memory.

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

What is the heap?

A

A memory is reserved to maintain the slot. The actual object that is created lives in the heap. and the my car variable is a reference to the variable in the heap.

The heap is the runtime data area from which memory for all class instances and arrays is allocated. The heap is created on virtual machine start-up. Heap storage for objects is reclaimed by an automatic storage management system (known as a garbage collector); objects are never explicitly deallocated.

Java Heap space is used by java runtime to allocate memory to Objects and JRE classes. Whenever we create an object, it’s always created in the Heap space.

Garbage Collection runs on the heap memory to free the memory used by objects that don’t have any reference. Any object created in the heap space has global access and can be referenced from anywhere of the application.

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

What is garbage collection?

A

Process that runs in the heap and eliminates objects that are not used to save memory. Also the variables in the object are also have memory in the heap.

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

what is the difference between a heap and a stack?

A

Difference between Java Heap Space and Stack Memory
Heap memory is used by all the parts of the application whereas stack memory is used only by one thread of execution. Whenever an object is created, it’s always stored in the Heap space and stack memory contains the reference to it

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

What is the difference between importing a class and inheriting the class when invoking a method?

A

If you are invoking a method from an imported class then need to reference the class Class.method if it is inherited then do not need to reference the class.

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

What is a way to extend abstraction in objects?

A

Can use the type of the parent class and have access to the parent class methods while creating a method of the child class.

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

What does defining a type do for variable?

A

It gives access to all of the methods and variables of that type, but also restricts things to that type as well.

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

How do you deploy your program in Jar or create a JAR file or Java archive file?

A

Can create it in Eclipse , right click and export on project export destination , export files and finsih jar file will be composed.

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

What is important about the manifest file for Java?

A

What is the class name that contains the main method so it knows where to start the program.

17
Q

What are some methods on the Scanner class to read lines in file?

A

nextLine()

18
Q

What is another way to read data from files?

A

Can use BufferedReader class

19
Q

What is another way to read data from files?

A

Can use BufferedReader class and the file Reader class

20
Q

what is a type safe language?

A

It makes sure that every line has the type checked so there are not errors on run time.

21
Q

Array list details

A

The parameter in ArrayList<> can’t be a primative type it can only be a class or non-primitive type. if you want to put in a primitive type need to put in the wrapper etc…

22
Q

What are the two most popular class of List?

A

The arrayList and LinkedList are the most popular and have different strenghts, linked list to manipulate lists and array lists to add to it. often times will just use the List datatype as the defining the data type of variable.

23
Q

How do you sort collections?

A

Add the Collections.sort(array);

24
Q

What is the Comparable interace?

A

It uses the compareTo method to compare instances of objects

25
Q

What is the steps when a java program runs?

A

First the java program goes to the main method and the builds the stack and goes line by line and goes to each method and the stack has an allocation for the variable And the heap is the memory area and the variable is to point to where the memory is stored. The garbage collector is going to look for objects that don’t have a reference in the stack.

26
Q

What is the keyword this stand for?

A

It represents the instance of the object .

27
Q

If you have a method what does the type on the left of the name of the method do?

A

It defines the return values that the method that will return when it is run.

28
Q

Go into details on the variable between type and value.

A

The value will define the value and the type will define the type of the value.

29
Q

What does the new keyword do?

A

It instantiates a new object from the class.

30
Q

When are objects created?

A

Objects are created during run time.

31
Q

What happens if a class does not have a constructor?

A

it will have a default constructor class(){}

32
Q

What are created during runtime?

A

The objects are created at runtime. Objects exist during run time. How objects will behave when the program is running.

33
Q

What is a linear program/algorithm?

A

It means there is a single loop

34
Q

What is a quadratic program/algorithm?

A

It means there is a loop inside of a loop

35
Q

What is an algorithm?

A

It is a series of instructions for a computer to follow to generate a response or value.

36
Q

What is a dictionary?

A

util.Dictionary is an abstract class, representing a key-value relation and works similiar to a map. Given a key you can store values and when needed can retrieve the value back using its key. Thus, it is a list of key-value pair.