Wednesday, July 30, 2014
Friday, July 25, 2014
appcompat_v7 automatic create in android eclipse

if we use
minSdkVersion="14"
appcompat_v7 doesnt get created.
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
second solution is :-
Your google play services library is being exported from other dependencies of your project and at the compile time the dex compiler gets confused.
If you're using Gradle then including this in your project's build.gradle should exclude the support library from being exported into your main project.
we can make multiple .apk files by using appcompat_v7 so then we use this updated library and making multiple apks .
google play .dex file compile at same time it confuse which apk or dex to execute .
Thanks
Wednesday, July 23, 2014
this keyword in Java
This keyword:-
1) this
keyword represent current instance of class.
2) You can synchronize on this in synchronized
block in Java
3) this keyword can be used to call overloaded
constructor in java. if used than it must be first statement in constructor this()
will call no argument constructor and this(parameter) will call one argument
constructor with appropriate parameter. here is an example of using this() for constructor chaining:
4) this can be used to return object. this is a valid return value. here is an example of using as return
value.
public
Loan getLoan(){
return
this;
}
5) this can be used to refer static
members in Java as well but its
discouraged and as per best practices
this should be used on non static reference.
6) "this"
keyword can not be used in static context i.e. inside static methods or static
initializer block.
if use this inside static context you will get
compilation error as shown in below example:
public
static void main(String args){
this.toString{}; //compilation error:
non static variable this can not be used in static context
}
this keyword refers to the object that is currently
executing. It is useful for a method to reference instance variables
relative to the this keyword.
Example 1 : Program that creates class Square and assigns
values to variables using constructor and this keyword
class Square
{
int height;
int width;
Square(int height, int
width)
{
// Note that constructor variable and instance variable names are
same
this.height = height;
this.width = width;
}
}
class ImplSquare
{
public static void main(String args[])
{
Square sObj1 = new Square(2,3);
System.out.println("Variable values of object
: ");
System.out.println("Object height =
" + sObj1.height);
System.out.println("Object width = " +
sObj1.width);
}
}
Output
Variable values of object
:
Object height = 0
Object width = 0
As in above example you can note
that constructor variable and instance variable names are same. But using this
keyword compiler can differentiates constructor variables and
instance variables.
- this keyword can be used to refer current class instance variable.
- this() can be used to invoke current class constructor.
- this keyword can be used to invoke current class method (implicitly)
- this can be passed as an argument in the method call.
- this can be passed as argument in the constructor call.
- this keyword can also be used to return the current class instance.
- This keyword can never static it make only dynamic values which are change .
Stack memory in Java ..How to release memory of stack ....
·
Each thread has its own stack when ever thread
initialize then that thread gowns to memory of stack
·
If there is no
memory left in stack for storing function call or local variable, JVM will
throw
·
Exceptions of stack
java.lang.StackOverFlowError, while if there is no more heap space for creating
object, JVM will
throw
java.lang.OutOfMemoryError:
Java Heap Space. Read more about how to deal
with c:- java.lang.OutOfMemoryError
A) If you
are using Recursion, on which method calls itself,
You can quickly fill up stack memory. Another difference between stack and heap
is that size of stack memory is lot lesser than size of heap memory in Java.
B)
Variables stored in stacks are only visible to the owner Thread, while objects
created in heap are visible to all thread. In other words stack memory is kind
of private memory of Java Threads, while heap memory is shared among all
threads
·
Heap and stack both store in RAM
· Can an object be stored on the stack instead of the heap?
·
Yes, an object can be stored on the
stack. If you create an object inside a function without using the “new”
operator then this will create and store the object on the stack, and not on
the heap
How long does memory on the stack last versus memory on the heap?
Once a function call runs to completion, any data on the stack created specifically for that function call will automatically be deleted. Any data on the heap will remain there until it’s manually deleted by the programmer.
·
We cannot increase the size of stack but we can
increase the size of heap
·
By the help of commands
·
Xss> increase to stack
·
Xms>
·
Xmx> increase to heap memory.
Both of them initialized memory at
dynamic time mostly it can static also
Which is faster – the stack or the heap? And why?
The stack is much faster than the heap. This is because of the way that memory is allocated on the stack. Allocating memory on the stack is as simple as moving the stack pointer up.How is memory deallocated on the stack and heap?
Data on the stack is automatically
deal located when variables go out of scope.
free, delete, or delete[ ].
Other languages like Java and .NET use garbage collection to automatically
delete memory from the heap, without the programmer having to do anything..
What can go wrong with the stack and the heap?
If the stack runs out of memory, then this is called a stack overflow – and could cause the program to crash. The heap could have the problem of fragmentation, which occurs when the available memory on the heap is being stored as noncontiguous (or disconnected) blocks – because used blocks of memory are in between the unused memory blocks. When excessive fragmentation occurs, allocating new memory may be impossible because of the fact that even though there is enough memory for the desired allocation, there may not be enough memory in one big block for the desired amount of memory.Which one should I use – the stack or the heap?
For people new to programming, it’s probably a good idea to use the stack since it’s easier. Because the stack is small, you would want to use it when you know exactly how much memory you will need for your data, or if you know the size of your data is very small. It’s better to use the heap when you know that you will need a lot of memory for your data, or you just are not sure how much memory you will need (like with a dynamic array).MultiThreading in Java
Multi threading:-
It is light weight which is use in gaming
·
It executes multiple threads simultaneously at a
time.
·
Thread is a light wait it takes small unit of
time of processing.
·
Multithreading is a achieving of multitasking
because of multithread share common memory area
·
They do not allocate separate memory to thread.
·
Context switch get less time to make processing them.
Multitasking types
1:- process based
2:- thread based
1:- process based multitasking:-
·
Each process has its own address in memory
process allocate separate memory area .so it takes time to save process in
memory area.
·
Cost of communication is high
·
Switch for one process to another then it take
time to saving process in memory.
2:- Thread based multithreading:-
·
Thread have same address space
·
Cost communication is low
·
Thread is light weight.
Note: - each process required one thread.
Thread is light weight sub process it take
separate path of execution it share separate area of memory execution

Life cycle of thread :-
- New
- Runnable
- Running
- Non-Runnable (Blocked)
- Terminated
Subscribe to:
Posts (Atom)


