# J/Direct

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/J%2FDirect
> Markdown URL: https://mediated.wiki/source/J%2FDirect.md
> Source: https://en.wikipedia.org/wiki/J%2FDirect
> Source revision: 1309506964
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

'''J/Direct''' was a technology included in some versions of [Microsoft Java Virtual Machine](/source/Microsoft_Java_Virtual_Machine), which allowed direct calls into the [Windows API](/source/Windows_API). J/Direct was specific of Microsoft's Virtual Machine, in replacement of the standard [Java Native Interface](/source/Java_Native_Interface) (JNI).

A Java program which used J/Direct would not run on [platform](/source/Platform_(computing))s other than [Microsoft Windows](/source/Microsoft_Windows).

The release of J/Direct (along with [AFC](/source/Application_Foundation_Classes) and [WFC](/source/Visual_J%2B%2B)), was part of an effort by Microsoft to gain leadership on the growing [Java](/source/Java_(programming_language)) community.<ref>{{cite web
 |last1=McMillan |first1=Robert
 |date=1997-07-01 |df=mdy
 |url=https://www.infoworld.com/article/2076977/microsoft-s-j-direct-called-death-of-java.html
 |title=Microsoft's J/Direct called death of Java
 |publisher=[JavaWorld](/source/JavaWorld)
 |accessdate=2020-07-16
}}</ref>

Since this destroyed one of the main advantages of Java, its [cross-platform](/source/cross-platform) nature, J/Direct was often seen as an attempt by Microsoft to undermine Java's [cross-platform](/source/cross-platform) capabilities, and an example of the tactic of [embrace, extend and extinguish](/source/embrace%2C_extend_and_extinguish).<ref>{{cite web
 |date=1997-08-01
 |url=http://www.xent.com/FoRK-archive/july97/0491.html
 |title=JFC; Microsoft declares war
 |publisher=xent.com
 |accessdate=2007-07-14
}}</ref>

After the drop by Microsoft of their specific [Java virtual machine](/source/Java_virtual_machine), and the switch to the [.NET](/source/.NET_Framework) environment, J/Direct was no longer maintained.

==Architecture==
J/Direct used a kind of [annotation](/source/Java_annotation) in Java code to make the link between [Java](/source/Java_(programming_language)) and [Windows](/source/Microsoft_Windows) functions. As annotations did not exist in Java when J/Direct was designed, Microsoft used a special syntax in Java comments.

For example, to declare the <code>GetSysColor</code> function in the [User32](/source/Windows_USER) [API](/source/Application_programming_interface):<ref>{{cite web
 |url=http://msdn.microsoft.com/en-us/library/aa233951%28v=VS.60%29.aspx
 |title=Aliasing (Method Renaming)
 |publisher=[Microsoft](/source/Microsoft)
 |accessdate=2010-11-20
}}</ref>
<syntaxhighlight lang=java>
/** @dll.import("USER32", entrypoint="GetSysColor") */
static native int getSysColor(int nIndex);
</syntaxhighlight>

The [Microsoft Java implementation](/source/Visual_J%2B%2B) already provided a pre-defined [package](/source/Java_package) which provided a set of pre-defined classes bound to the [User32](/source/Windows_USER), [Gdi32.dll](/source/Microsoft_Windows_library_files), and [Kernel32.dll](/source/Microsoft_Windows_library_files) APIs.<ref>{{cite web
 |url=http://www.codeguru.com/java/tij/tij0193.shtml
 |title=J/Direct
 |date=March 2001
 |publisher=codeguru.com
 |accessdate=2010-11-20
}}</ref>

Additionally, the Microsoft VM used some built-in rules to be able to bind automatically the Java code to some [Windows API](/source/Microsoft_Windows_library_files) functions. For example, it chose automatically between ANSI and Unicode versions of [Windows API](/source/Windows_API) functions.<ref>{{cite web
 |url=http://msdn.microsoft.com/en-us/library/aa264867%28v=VS.60%29.aspx
 |title=How the VM Chooses Between ANSI and Unicode
 |publisher=[Microsoft](/source/Microsoft)
 |accessdate=2010-11-20
}}</ref>

==See also==
* [Java Native Interface](/source/Java_Native_Interface)
* [Java Native Access](/source/Java_Native_Access)
* [P/Invoke](/source/Platform_Invocation_Services), the equivalent [.NET](/source/.NET_Framework) API

==References==
{{Reflist|colwidth=30em}}

==External links==
* [https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-6.0/aa242534(v=vs.60) Writing Windows-Based Applications with J/Direct]

{{DEFAULTSORT:J Direct}}
Category:Java virtual machine

{{compu-prog-stub}}

---
Adapted from the Wikipedia article [J/Direct](https://en.wikipedia.org/wiki/J%2FDirect) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/J%2FDirect?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
