How to clone a java object ???

**********************************************************
COMPLETE SOURCE CODE FOR : CloneObjectInJava.java
**********************************************************


//Class for object that you want to clone must overwrite method clone() first

public class CloneObjectInJava implements Cloneable
{
public void printAText()
{
System.out.println("HI");
}

//OVERWRITE METHOD CLONE
public Object clone()
{
Cloneable makeClone=new CloneObjectInJava();
return makeClone;
}

public static void main(String[]args)
{
//Create a CloneObjectInJava object name "coij"
CloneObjectInJava coij=new CloneObjectInJava();

try
{
//Create clone for "coij"
CloneObjectInJava coijClone=(CloneObjectInJava)coij.clone();
//Call method printAText using clone
coijClone.printAText();
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}


**********************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************

How to get amount of free memory in jvm ???

***********************************************************
COMPLETE SOURCE CODE FOR : FreeMemoryInJvm.java
***********************************************************


public class FreeMemoryInJvm
{
public static void main(String[]args)
{
System.out.println("Free Memory In Jvm is : "+Runtime.getRuntime().freeMemory()+" bytes");
}
}


***********************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************

How to know maximum amount of memory that will be use by jvm ???

******************************************************
COMPLETE SOURCE CODE FOR : MaxMemoryThatJvmWillUse.java
******************************************************


public class MaxMemoryThatJvmWillUse
{
public static void main(String[]args)
{
System.out.println("Max Amount Of Memory That Will Be Use By Jvm is : "+Runtime.getRuntime().maxMemory()+ " bytes");
}
}


******************************************************
JUST COMPILE AND EXECUTE IT
******************************************************

How to get total memory in jvm ???

*********************************************************
COMPLETE SOURCE CODE FOR : GetTotalMemoryInJvm.java
*********************************************************


public class GetTotalMemoryInJvm
{
public static void main(String[]args)
{
//Print total memory in java virtual machine in bytes
System.out.println("TOTAL MEMORY IN JVM : "+Runtime.getRuntime().totalMemory());
}
}


*********************************************************
JUST COMPILE AND EXECUTE IT
*********************************************************

What is java memory heap ???

What is java memory heap ???
It is an area in memory where an object are created

How to make java program output to a file instead of command prompt like usual ???

This source code will show you how to make java output that print in command prompt will be print in a file instead of command prompt.

**************************************************************
COMPLETE SOURCE CODE FOR : PutCommandPromptOutputToFile.java
**************************************************************


import java.io.PrintStream;

public class PutCommandPromptOutputToFile
{
public static void main(String[]args)
{
try
{
PrintStream newOuputChannel=new PrintStream("output.txt");
System.setOut(newOuputChannel);

System.out.println("HI");
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}


**************************************************************
JUST COMPILE AND EXECUTE IT
**************************************************************