Java General Concepts Flashcards
What are the basics of a computer program?
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 is code executed?
It is executed line by line. Except when there is conditionals attached to it and will only be run if the conditions are met.
Object Oriented Programming
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.
What is the this keyword?
It will reference the object that it is referring to
What happens if you do not specify a constructor?
It will revert back to the default constructor default(){}
it is the same as the class name with no parameters.
Objects are a run time item
That means that they do not exist until the program is running
What does all the work in a java applications?
Methods are what do all the work and the java program is looking for the main method.
What is the Stack?
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.
What is the heap?
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.
What is garbage collection?
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.
what is the difference between a heap and a stack?
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
What is the difference between importing a class and inheriting the class when invoking a method?
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.
What is a way to extend abstraction in objects?
Can use the type of the parent class and have access to the parent class methods while creating a method of the child class.
What does defining a type do for variable?
It gives access to all of the methods and variables of that type, but also restricts things to that type as well.
How do you deploy your program in Jar or create a JAR file or Java archive file?
Can create it in Eclipse , right click and export on project export destination , export files and finsih jar file will be composed.