Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9172053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:15:12+00:00 2026-06-17T16:15:12+00:00

I’m looking at java bytecode listings and Wikipedia, and they all seem to be

  • 0

I’m looking at java bytecode listings and Wikipedia, and they all seem to be basic operations (branch, push, pop, cast, etc.). And many articles use these basic examples. But what happens when I read a line from the console, or create a new JButton? Where’s the bytecode for opening a port?

I believe I saw something for “making a system call” (although I didn’t find it today, skimming through the list several times). Do these “special” calls have their own code, which are directly delegated (don’t know how to say it technically) to the OS by the VM? I know there are ways to open up the bytecode, but I’m looking for a general explanation, not weeks of learning advanced bytecode.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:15:14+00:00Added an answer on June 17, 2026 at 4:15 pm

    There is no byte code for opening a port or drawing graphics to the screen. There are classes that perform these tasks. These classes have native methods, those are methods written in C (or any other language that can be compiled to a native library) and as they are native, they can access the network and graphcis libraries of your operating system to perform those tasks. So you are instantiating these classes and call some of their methods. Java Byte Code offers byte code for instantiating classes and for calling methods of objects. If the JVM sees that this is a native method, it will call the native code that belongs to this method and this native code can do pretty much anything a C or C++ program could do.

    So for example, if you call System.out.println in Java, roughly the following happens:

    System is a class with a static variable out. This variable points to an object of type java.io.PrintStream which has already been created by the JVM before your main method is ever executed. The out variable is initialized like this:

    FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
    setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
    

    And the method setOut0 is defined as

    private static native void setOut0(PrintStream out);
    

    This means setOut0 is a native method, written in C, or some other language that can be compiled and linked to a native library, though at least the interface between Java and this library is usually written in C.

    Java will search in all loaded libraries for a symbol (in that case symbol means function name) with the name Java_java_lang_System_setOut0, this is Java_ClassName_MethodName and call it. A sample C code I have found for this method looked like this:

    JNIEXPORT void JNICALL
    Java_java_lang_System_setOut0(JNIEnv *env, jclass cla, jobject stream)
    {
        jfieldID fid =
            (*env)->GetStaticFieldID(env,cla,"out","Ljava/io/PrintStream;");
        if (fid == 0)
            return;
        (*env)->SetStaticObjectField(env,cla,fid,stream);
    }
    

    Yet this is not the real magic, the real magic happens elsewhere. PrintStream.write() calls BufferedWriter.write(). This method again calls OutputStreamWriter.write() (not directly, but sooner or later it ends up there) and this method calls StreamEncoder.write(). Wow, it’s getting hard to trace that call. The StreamEncoder calls BufferedOutputStream.write(), this one calls FileOutputStream.write() and this one calls FileOutputStream.writeBytes() and finally, finally we are there! FileOutputStream.writeBytes() is a native method. It will look something like this:

    JNIEXPORT void JNICALL
    Java_java_io_FileOutputStream_writeBytes(JNIEnv *env,
        jobject this, jbyteArray bytes, jint off, jint len) {
        writeBytes(env, this, bytes, off, len, fos_fd);
    }
    

    So it calls a function named writeBytes and this function looks different depending on your operating system, e.g. whether this is Windows, Linux or OS X. On UNIX/Linux systems this function may call another function (and so on), but somewhere is a simple C function call to write something to a C FILE * stream or a file descriptor (which is just an int in C). So it could be a printf()/fprintf() or a puts()/fputs() call that writes to stdout or a write() call that writes to STDOUT_FILENO. In Windows it is usually a call to WriteFile(), though it could also be a printf()/fprintf() (those are C standard functions, all platforms must support them).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.