Reputation: 243
I want to know what happens in background when I run a simple java hello world application without any extra initial parameters.
For example in background how java call windows functions like drawing a simple window:
public class example
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
or
public class example2 extends Jframe
{
public static void main(String args[])
{
new example2().setvisible(true);
}
}
Upvotes: 2
Views: 222
Reputation: 900
If you are asking how the JVM interacts with the underlying operating system, this article gives a general, platform-independent overview of its architecture.
I think you may be particularly interested in the section headed "The Byte Code Instruction Set", which states that when executing the line:
System.out.println("Hello world!");
At compile time, the Java compiler converts the single-line print statement to the following byte code:
0 getstatic #6 <Field java.lang.System.out Ljava/io/PrintStream;>
3 ldc #1 <String "Hello world!">
5 invokevirtual #7 <Method java.io.PrintStream.println(Ljava/lang/String;)V>
8 return
It may also be worth noting that JDK includes a tool that you can use to examine byte code, called the class file disassembler. You can make use of this tool using the javap command in your terminal of choice.
Upvotes: 1
Reputation: 81
First of all your first example of code only prints "Hello World!" into a terminal. As for calling a window, the OS handles it. In case you haven't noticed there is a difference between a window on OSX and one on Windows.
Upvotes: 0
Reputation: 28743
How java call windows functions like drawing a simple window?
I guess you are asking about Java Native Interface.
Upvotes: 1
Reputation: 3349
http://docs.oracle.com/javase/tutorial/ui/overview/intro.html
Java is intended to be platform independent. It's not using native windows calls, at least not directly.
Upvotes: 1