Search character or word in a sentence using java

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


public class SearchCharacterOrWordInASentence
{
public static void main(String[]args)
{
//-1 mean the word or character that you search not exist

String a="Hello World !!!";

//SEARCH CHARACTER
int b=a.indexOf('H');
if(b!=-1)
{
System.out.println("H exist");
}

//SEARCH Hello IN Hello World !!!
int c=a.indexOf("Hello");
if(c!=-1)
{
System.out.println("Hello exist");
}
}
}


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

Get word from a sentence in java

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


public class GetWordFromASentence
{
public static void main(String[]args)
{
//This source code will show you how to get word Hello from sentence Hello World

//You can use method substring(index_for_first_letter_for_word,index_for_last_letter_plus_one)

//Index start with 0

//Blank space also count.In this case, space between Hello and world take 5 for it's index

String a="Hello world!!";
String b=a.substring(0,5);

System.out.println(b);
}
}


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

How to determine a word contain or not in a sentence using java ???

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


public class DetermineStringContainSubstring
{
public static void main(String[]args)
{
String a="Welcome to java world";

String substring1="Welcome to java world";
String substring2="elc";
String substring3="Wel";
String substring4=" t";
String substring5="rld";

//CHECK MATCH WHOLE WORD
if(a.matches(substring1))
{
System.out.println("substring1 match to a");
}

//CHECK SUBSTRING NOT LOCATE AT START OR END OF STRING
if(a.indexOf(substring2)>0)
{
System.out.println("substring2 contain in a");
}

//CHECK SUBSTRING NOT LOCATE AT START OR END OF STRING
if(a.indexOf(substring4)>0)
{
System.out.println("substring4 contain in a");
}

//CHECK SUBSTRING LOCATE AT START OF STRING
if(a.startsWith(substring3))
{
System.out.println("substring3 contain in a");
}

//CHECK SUBSTRING LOCATE AT END OF STRING
if(a.endsWith(substring5))
{
System.out.println("substring5 contain in a");
}
}
}


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

Determine what package from a class object ???

Source code below will print name for package that belong to it's own class object. It should print null because class object that create from java file below not belong to any package.

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


public class DeterminePackageForClassObject
{
public static void main(String[]args)
{
try
{
Class temp=Class.forName("DeterminePackageForClassObject");
System.out.println("PACKAGE FOR THIS CLASS OBJECT IS :"+temp.getPackage());
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}


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

Get all interface from a class object

This program will print name of interface that implemented by this class

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


import java.awt.event.ActionListener;//INTERFACE 1
//Runnable-INTERFACE 2
import java.awt.event.ActionEvent;

public class ListingAllInterfaceFromClassObject implements ActionListener,Runnable
{
public void actionPerformed(ActionEvent evt)
{
//NO IMPLEMENTATION
}

public void run()
{
//NO IMPLEMENTATION
}

public static void main(String[]args)
{
try
{
Class temp=Class.forName("ListingAllInterfaceFromClassObject");
Class[]allInterface=temp.getInterfaces();
int allInterfaceLength=allInterface.length;
int temp2=0;
while(temp2!=allInterfaceLength)
{
System.out.println("INTERFACE "+(temp2+1)+" :"+(allInterface[temp2].getSimpleName()));
temp2=temp2+1;
}
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}


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

Get superclass for an object class ???

Source code below will get superclass for it's own object class. It will print name for it's superclass.

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


public class GettingSuperclass
{
public static void main(String[]args)
{
try
{
Class temp=Class.forName("GettingSuperclass");
Class thisIsSuper=temp.getSuperclass();

System.out.println("Superclass for this class is : "+thisIsSuper.getSimpleName());
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}


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

Determine what is represent by a class object, whether an interface or a class ???

This tutorial will use CreateInterface.java to determine whether class object from it, is an interface or a class. You can get it at Java Interface ( Part 1). Before you compile and execute source code below, you must make sure CreateInterface.class is locate same location with this java file.

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


public class DetermineClassObjectIsClassOrInterface
{
public static void main(String[]args)
{
try
{
Class temp=Class.forName("CreateInterface");
if(temp.isInterface())
{
System.out.println("THIS CLASS OBJECT IS REPRESENT AN INTERFACE");
}
else
{
System.out.println("THIS CLASS OBJECT IS REPRESENT AN CLASS");
}
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}


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

Java Interface (Part 2)

This tutorial will show you, how to use a java interface that we create in my previous post. When we want to use a java interface, we must overwrite abstract method that contain in the interface. Source code below will overwrite abstract method in java interface (CreateInterface) called print(). Before we can use a java interface we must put implements keyword followed by interface name. You also must import interface into your program. In the example below, i don't import the interface because, it's location is same with this java file.

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


public class UseJavaInterface implements CreateInterface
{
public void print()
{
System.out.println("HI");
}
}


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

Java Interface (Part 1)

Source code below will create a java interface, named CreateInterface. When you want to create an interface, you just change "class" keyword after "public" keyword to "interface" keyword and after that followed by your java file name. In a java interface, all method is only abstract method. You don't need to put access modifier to abstract method in a java interface. This is because all of it will be set to public. So when you want to overwrite an abstract method from an interface you must know, access modifier that you must use is public, not private or protected. After that put return type followed by name for the abstract method. In source code below, abstract method is print(). What is java abstract method ??? The answer is, an abstract method is a method without body. If you can see, abstract method print() end after ")" ,not contain any implementation code. Where to put implementation code for a java abstract method ??? You will put it's implementation code in java concrete class that implements this interface by overwrite it.

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


public interface CreateInterface
{
void print();
}


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

Get class name from class object ???

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


public class GetClassNameFromClassObject
{
public static void main(String[]args)
{
try
{
//For example of this source code, we will use java predefined class named Object

//You can change class name instead of java.lang.Object
Class a=Class.forName("java.lang.Object");

//Now we will print the name of the class
System.out.println("IT'S NAME IS : "+a.getSimpleName());
}

catch(Exception exception)
{
exception.printStackTrace();
}
}
}


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

RELAXING NATURE VIDEO