What does <init> and (Native Method) mean?
Asked Answered
A

3

10

What do the symbols indicate and what does the (Native method) say about the java.io.FileStream.open method?

Exception in thread "main" java.io.FileNotFoundException: line23 (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:135)
at java.io.FileInputStream.<init>(FileInputStream.java:95)
at java.io.FileReader.<init>(FileReader.java:64) at Helper.readFile(Foo5.java:74)
at Bar2.main(Bar2.java:32)
Aberrant answered 23/7, 2013 at 6:29 Comment(0)
D
9

When you see < init > in a stacktrace, it refers to the constructor of the class.

Native Method means that the method is not implemented in Java, but in another low-level language like C or C++. In this case, open() is a method that requires low-level functions, which are different from OS to OS.

Dorsey answered 23/7, 2013 at 6:32 Comment(0)
G
1

The native method is implemented within the JVM (Java Virtual Machine). The Java developer isn't supposed to worry about their implementation as they relate to the inner working of the virtual machine.

In here java.io.FileStream.open() issuch an operation.

Gnu answered 23/7, 2013 at 6:38 Comment(0)
S
0

If you open the source of the class

java.io.FileStream

You can see that this method

private native void open(String name) throws FileNotFoundException;

which does not have any body.

The method is implemented in "native" code. That is, code that does not run in the JVM. It's typically written in C or C++.

Native methods are usually used to interface with system calls or libraries written in other programming languages.

To get the source of native methods, you would probably have to use some Open source JDk like OpenJDK

Sylvestersylvia answered 1/1, 2015 at 9:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.