English
Follow Us Online
Twitter    YouTube(TM)
Break out of for loop
Convert String to int
Convert int to String
String to Date object
Convert Double to int
Convert String to int
Convert int to String
String to Date object
Convert Double to int
Convert double to int
Call a method
Call method in Class
Call a Class
Call Super Class method
Check if a file exists
Check String is Number
Declare a variable
Declare a String
Declare an Array
Declare constants
Define enum
Define a method
Exit program
Exit a for loop
Exit a method
Format date
Format double
Find current directory
Get current date
Get user input
Get Class name
Java How to A B C D E F G H I J K L M N O P Q R S T U V W Y W Z
More How to C1 C2
Java How to call Super Class method
Related Links Call Super Class method Check if a file exists Check if String is a Number Next Page >>>
Notes:
  1. Use super keyword to access methods in Super Class.
  2. Alternatively, call the super class method is inherited by subclass, you can invike the super class method directly.
public class Car extends Vehicle { // Sub Class extending the Vehicle Class
	/**
	 * Example showing how to call a method in Super Class
	 * 
	 * @author www.f5java.com
	 * @return : void
	 */
	public void callSuperClassMethod() {
		// 1. use super keyword to access methods in Super Class
		super.run();
		// Alternatively, call the super class method is inherited by
		// subclass, you can invike the super class method directly
		run();
	}
}
Java How to check if a file exists
Steps:
  1. Create an instance of File by passing pathname as String.
  2. Call exits method to check if file exits.
  3. Alternatively you can use isFile() method.
/**
 * Example checking if a file exits in a given path
 * In this case this is checking for a file in the path C:\temp\test.txt
 * 
 * @author www.f5java.com
 * @return : void
 */
public void checkIfFileExists(){
	// 1. Create an instance of File by passing pathname as String	
	File f = new File("C:/temp/test.txt");
	
	// 2. Call exits method to check if file exits
	if(f.exists()){ // f.exists() returns true if file exits
		System.out.println("Found the file");
	}else{
		System.out.println("File not found");
	}
	
	// 3. Alternatively you can use isFile method 
	if(f.isFile()){ // returns true if file exits in the given path name
		System.out.println("Found the file");
	}else{
		System.out.println("File not found");
	}
}
Java How to check if String is a Number
Steps:
  1. Instantiate Scanner passing String input.
  2. Use Scanner’s various methods to check different types of Numbers
/**
 * Example checking if a String is Number
 * 
 * @author www.f5java.com
 * @return : void
 */
public void isStringANumber(){
	String score = "100"; // Number represented as String
	// 1. Instantiate Scanner passing String input
	Scanner scanner = new Scanner(score);  
	if (scanner.hasNextBigInteger()) {  // Scanner has various methods to check different types of Numbers
	    Integer scoreInt = scanner.nextInt();
	    System.out.println(scoreInt);
	 }
}