Subjects
PRICING
COURSES
SIGN IN
Start Free Trial
Harsh V.
Tutor for 6 years
Tutor Satisfaction Guarantee
Java Programming
TutorMe
Question:

Explain the garbage collection in Java.

Harsh V.
Answer:

Java manages memory implicitly. We as a programmer don't have to allocate and deallocate memory. Garbage collector is a major feature of Java Virtual Machine. When we create a variable that reference to a complex object, the object itself is stored in the area of memory called Heap Memory. As long as any variable references an object in the memory that object will be retained and will not be eligible for garbage collection. When all references to the object expire, that is when you cannot get to the object through your code anymore, then that object is eligible for garbage collection. When do references expire? 1. Variables local to functions or code blocks expire when function is complete. for example: void func(int temp){ int hello =1; } here the variable "hello" expires when the function "func" finishes. 2. We can explicitly expire persistent objects by setting to null. For example: String exp = " going to expire"; exp = null; How Garbage Collection works? 1. Garbage Collection runs its own thread so it doesn't affect our application. 2. When the garbage collection identifies a de-referenced object, it can destroy it and reclaim memory- but it doesn't have to. It has its own algorithm which manages it. 3.We as a programmer cannot force garbage collection. 4.Methods like System.gc() and Runtime.gc() can request garbage collection, but there is no guarantee it will happen. 5. If no memory is available for a newly requested object, JVM throws OutOfMemoryError.

C++ Programming
TutorMe
Question:

What are functions in C++? Explain call by value and call by reference.

Harsh V.
Answer:

Functions are fundamental to C++. All code in the C++ programs are written in the functions starting from the main function. They are the block of codes that may be called by and may return values to other codes. In simple terms they are the sub-routines which allow to generalize and modularize code by creating containers for logical subsets of codes and by allowing code to be reused. Functions are identified using their signatures. Function signature include : Function return type, Function name, Function argument type. Call by Value: Arguments in C++ can be passed by value. So when you call a function and pass a variable, copy of the content of the variable is passed to the function. The function me change the value of the copy but the caller's copy remain unchanged. For example: int a=1; f(a); cout<<a; void f( int a){ a++; } in this example the value of the variable 'a' is 1 and then the function is being called which increments the value of the argument it receives. But since we are passing the variable by copy, only a copy is being sent so if we print the variable back in our original code, it still is 1. Call by Reference: The alternative to call by value is call by reference and this has to be done explicitly by passing the reference. For example: int a=1; f(&a); cout<<a; void f( int* a){ ( *a)++; } in this example we are passing the reference of variable 'a' or the address of variable 'a' which is a pointer. And in the function we are incrementing the value stored in the variable by changing the value at the address of the variable and thus explicitly doing it by reference.

Android Programming
TutorMe
Question:

What are fragments? How to include them in the activity and how do they communicate?

Harsh V.
Answer:

Fragments are the portion of interface that in simple terms are superimposed on the activity. There can be several fragments in a single activity depending upon the need of the interface of the app. Fragments have their separate life cycles and can be handled through the activity that they are put on. There are two ways to include fragments to an activity. First way is the static way in which fragment is added as a widget to the XML layout of the activity to which we are including it. And then later referencing and inflating it in the activity class. Second way is the dynamic way in which fragment are dynamically added to the activity class using a set of functions and objects ( fragment manager and fragment transaction). In this case the type of layout that is fragment is going to use is added in the XML layout of the activity. There can be several ways in which fragments can interact(like transactions, etc) but the best way is to create and implement a custom made communicator interface in the activity and have objects of this interface in the fragments to interact with. So now the communication becomes fragment A-activity-fragment B.

Send a message explaining your
needs and Harsh will reply soon.
Contact Harsh
Ready now? Request a lesson.
Start Session
FAQs
What is a lesson?
A lesson is virtual lesson space on our platform where you and a tutor can communicate. You'll have the option to communicate using video/audio as well as text chat. You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.
How do I begin a lesson?
If the tutor is currently online, you can click the "Start Session" button above. If they are offline, you can always send them a message to schedule a lesson.
Who are TutorMe tutors?
Many of our tutors are current college students or recent graduates of top-tier universities like MIT, Harvard and USC. TutorMe has thousands of top-quality tutors available to work with you.