Home » Java programming language

Java StackTraceElement isNativeMethod() method with example

StackTraceElement Class isNativeMethod() method: Here, we are going to learn about the isNativeMethod() method of StackTraceElement Class with its syntax and example.
Submitted by Preeti Jain, on December 24, 2019

StackTraceElement Class isNativeMethod() method

  • isNativeMethod() method is available in java.lang package.
  • isNativeMethod() method is used to check whether the method is native or not that contains the execution point denoted by this StackTraceElement.
  • isNativeMethod() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • isNativeMethod() method does not throw an exception at the time of checking the native method.

Syntax:

    public boolean isNativeMethod();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is boolean – it returns a boolean value based on the given cases,

  • It returns true when the method that contains the execution point denoted by this StackTraceElement is native.
  • It returns false when the method that contains the execution point denoted by this StackTraceElement is a non-native method.

Example:

// Java program to demonstrate the example 
// of boolean isNativeMethod () method of StackTraceElement 

import java.io.*;
import java.util.*;

public class Native {
    public static void main(String args[]) {
        System.out.println("Native Method :");
        for (int k = 0; k < 2; ++k) {
            // check native method in a thread by using
            // isNativeMethod () method
            System.out.print(Thread.currentThread().getStackTrace()[k].getClassName() + " ");
            System.out.println(Thread.currentThread().getStackTrace()[k].isNativeMethod());
        }
    }
}

Output

Native Method :
java.lang.Thread false
Native false



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.