How to create object from primitive data type ???

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


public class CreateObjectFromPrimitiveDataType
{
public static void main(String[]args)
{
//PRIMITIVE TYPE : boolean
boolean a=true;
Boolean booleanObject=new Boolean(a);//CREATE OBJECT FROM a

//PRIMITIVE TYPE : byte
byte b=(byte)9;
Byte byteObject=new Byte(b);

//PRIMITIVE TYPE : char
char c='a';
Character charObject=new Character(c);

//PRIMITIVE TYPE : short
short d=(short)9;
Short shortObject=new Short(d);

//PRIMITIVE TYPE : integer
int e=9;
Integer intObject=new Integer(e);

//PRIMITIVE TYPE : long
long f=9L;
Long longObject=new Long(f);

//PRIMITIVE TYPE : float
float g=9.9F;
Float floatObject=new Float(g);

//PRIMITIVE TYPE : double
double h=9.9D;
Double doubleObject=new Double(h);

//PRINT VALUE FOR EACH OBJECT
System.out.println("VALUE FOR BOOLEAN : "+booleanObject.booleanValue());
System.out.println("VALUE FOR BYTE : "+byteObject.byteValue());
System.out.println("VALUE FOR CHARACTER : "+charObject.charValue());
System.out.println("VALUE FOR SHORT: "+shortObject.shortValue());
System.out.println("VALUE FOR INTEGER: "+intObject.intValue());
System.out.println("VALUE FOR LONG : "+longObject.longValue());
System.out.println("VALUE FOR FLOAT : "+floatObject.floatValue());
System.out.println("VALUE FOR DOUBLE: "+doubleObject.doubleValue());
}
}


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

How to get hash code from a java object ???

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


public class GetObjectHashCode
{
public static void main(String[]args)
{
//Create a String object with value Hello
String stringObject=new String("Hello");

//Print hash code for the object
System.out.println("HASH CODE VALUE : "+stringObject.hashCode());
}
}


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

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

RELAXING NATURE VIDEO