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
**************************************************************

Source code to know how long a java application is running

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


public class HowLongApplicationRunning
{
public static void main(String[]args)
{
long startTime=System.currentTimeMillis();

try
{
//MAKE YOUR APPLICATION SLEEP IN 10 SECONDS
Thread.sleep(10000);
}
catch(Exception exception)
{
exception.printStackTrace();
}

long endTime=System.currentTimeMillis();

//GET DURATION IN SECOND
long timeInSecond=(endTime-startTime)/1000;

System.out.println("Duration For Your Application Running Is : "+timeInSecond+" seconds");
}
}


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

Java source code to determine when application exit by print a line of text on command prompt

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


public class DetermineWhenApplicationExit
{
public static void main(String[]args)
{
Runtime.getRuntime().addShutdownHook(new Thread()
{
public void run()
{
//Application will print "BYE" when it close
System.out.println("BYE");
}
});

//Make this application terminate
System.exit(0);
}
}


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

Java source code for application terminate (Exit application)

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


public class ExitApplication
{
public static void main(String[]args)
{
//System.exit(0) will make your application exit
System.exit(0);
}
}


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

How to draw rotate string in java ???

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


import java.awt.Frame;
import java.awt.Panel;

import java.awt.Graphics;
import java.awt.Graphics2D;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import java.awt.geom.AffineTransform;

public class DrawRotateText extends Panel
{
public DrawRotateText()
{
Frame a=new Frame("Draw Rotate Text");
WindowListener wl=new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
};

a.addWindowListener(wl);
a.add(this);
a.setSize(400,400);
a.setVisible(true);
}

public void paint(Graphics g)
{
Graphics2D g2d=(Graphics2D)g;
AffineTransform at=new AffineTransform();
at.setToRotation(-Math.PI/4);//SET ROTATION HERE IN radians
g2d.setTransform(at);

g2d.drawString("HI EVERYONE !!",100,200);
}

public static void main(String[]args)
{
DrawRotateText drt=new DrawRotateText();
}
}


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

RELAXING NATURE VIDEO