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 convert double to int
Java How to convert Double to int
Related Links Convert Double to int Convert double to int Call a method Call a Class Next Page >>>
Notes:
  1. Primitive Conversion: Call valueOf method on Double class passing double and call intValue() method to get int value.
  2. Wrapper Class: Call intValue() on Double Wrapper Class.
  3. Cast: Type cast primitive double to primitive int.
/**
 * Example showing how to convert double to int & Double to int
 * 
 * @author www.f5java.com
 * @return : void
 */
public void convertDoubleToInt() {
	double firstDouble = 5.0; // Primitive
	Double secondDouble = 10.0; // Wrapper class
	
	// 1. Primitive Conversion: Call valueOf method on Double class passing double and 
	// call intValue() method to get int value 
	int firstDoubleValue = Double.valueOf(firstDouble).intValue();
	// 2. Call intValue() on Double Wrapper Class
	int secondDoubleValue = secondDouble.intValue();
	// 3. Type cast double to int
	int typeCasting = (int)firstDouble;
	
	System.out.println("firstDoubleValue is " + firstDoubleValue);
	System.out.println("secondDoubleValue is " + secondDoubleValue);
	System.out.println("typeCasting value is " + typeCasting);
}
Java How to call a method
Steps:
  1. Create an instance of the Class.
  2. Invoke method on a class.
  3. Static method can be accessed in static way as fully qualified ClassName.MethodName.
public class ExampleClass { // Class
	// Static method
	public static void staticMethod() {
		System.out.println("I am inside staticMethod");
	}
	// Instance Method
	public void instanceMethod() {
		System.out.println("I am inside instanceMethod");
	}
}

/**
 * Example showing how to call a method
 * 
 * @author www.f5java.com
 * @return : void
 */
public void callAMethod() {
	// 1. Create an instance of the Class
	ExampleClass example = new ExampleClass();
	// 2. Invoke method on a class
	example.instanceMethod();
	example.staticMethod(); // Not recommended way to call static method
	
	// Also static method can be accessed in static way 
	// as fully qualified ClassName.MethodName
	ExampleClass.staticMethod();
}
Java How to call a method from another Class
Steps:
  1. Create an instance of the Class.
  2. Invoke method on a class.
public class ExampleClass { // Class
	// Static method
	public static void staticMethod() {
		System.out.println("I am inside staticMethod");
	}

	// Instance Method
	public void instanceMethod() {
		System.out.println("I am inside instanceMethod");
	}
}

public class AnotherClass { // Class
	/**
	 * Example showing how to call a method of another class
	 * 
	 * @author www.f5java.com
	 * @return : void
	 */
	public void accessAnotherClassMethod() {
		// 1. Create an instance of the Class
		ExampleClass example = new ExampleClass();
		// 2. Invoke method on a class
		example.instanceMethod();
	}
}