-3

I have been programming in Java for a while now. However during all this time there was a concept I never understood and finally now I would like to close this knowledge gap:

A Java class may consists of several parts like methods, members variables, comments and maybe other stuff. I think of these as mere tools for pushing around numbers, string etc. However knowing of the existence of libraries one may find that he can do a lot more with one's code: For example, reading from or writing to files on the local hard drive, recording Audio data, getting the current system time etc. But how does that work?

Java classes and stuff that needs hardware (a microphone for example) are completely separate things! As far as I know the Java libraries I import in my code also include only Java classes, stuff to help pushing around integers, strings etc.

Where is the "exit" point, when one "leaves" the class and works with stuff, that is not somewhere inside the JVM?

EDIT: Found my answers, posted here below:

In short: https://stackoverflow.com/a/557610/5152565

In a bit more detail: https://stackoverflow.com/a/30636097/5152565

Community
  • 1
  • 1
blauerschluessel
  • 219
  • 1
  • 3
  • 14
  • 2
    A `native` method. See, for example, [`sun.misc.Unsafe`](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/sun/misc/Unsafe.java?av=f). – Boris the Spider Apr 19 '17 at 18:19
  • 2
    I don't understand, how is it useless in any way? You specifically asked "_where is the 'exit' point where one 'leaves' the class_". This answer to this is **exactly** a `native` method. Could you please explain why you find my comment useless? (And at the same time explain why you are being rude to someone who is helping you on their own time?) – Boris the Spider Apr 19 '17 at 18:24
  • @BoristheSpider Simply giving something a name doesn't tell you anything about how it works or what's made of. At this point I would like to reference this answer here: http://stackoverflow.com/a/6101324/5152565 and in particular the comment below. Before you edited, your comment sufficed only the absolutely minimum one could provide as a help. Anyone who is not already familiar with that concept, won't find himself knowing more after reading it. – blauerschluessel Apr 19 '17 at 18:41
  • 1
    Possible duplicate of [What is the native keyword in Java for?](http://stackoverflow.com/questions/6101311/what-is-the-native-keyword-in-java-for) – Tom Apr 19 '17 at 22:16
  • @blauerschluessel The question is pretty vague and the subject very broad so it's very hard to know what would interest you or why you need to know this. In this case I suggest you do some further research on what `native` methods are and look at some examples in the JDK. BTW native methods are just more libraries written in C instead of Java. Those libraries in turn call system libraries which come with your OS. In the end they all do something with hardware. – Peter Lawrey Apr 20 '17 at 07:57
  • 1
    You appear to have linked the same answer twice, is the "in a bit more detail" supposed to be a different link? – Peter Lawrey Apr 20 '17 at 07:58
  • @BoristheSpider, but to frank: I am the one who is deeply offended. Mainly because I have rethought my comment and deleted it very shortly after posting it and still being accused of insult and secondly because I seem to be accredited a 'misdeed' most didn't actually see. Also being formal and simply stating an apparent, not harmful fact is by no means rude. Much in contrast however you should be rather thankful to me, that I pointed out your comment being not helpful, so that you could rethink it. Since you didn't do that, you never seemed to have the intention to really help. That is rude. – blauerschluessel Apr 22 '17 at 09:12

1 Answers1

1

A native method call from your Java library might qualify as an exit point to your Java code. Beyond this point the native code will have to work with the operating system libraries to execute the task. eg : Java native code to read a File

Geek
  • 23,089
  • 20
  • 71
  • 85