René's URL Explorer Experiment


Title: [Pattern] · Issue #129 · javaevolved/javaevolved.github.io · GitHub

Open Graph Title: [Pattern] · Issue #129 · javaevolved/javaevolved.github.io

X Title: [Pattern] · Issue #129 · javaevolved/javaevolved.github.io

Description: Category language Slug call-c-from-java Title Calling out to C code from Java Difficulty advanced Since JDK 22 Summary Simplifies C/C++ code to be called from Java, allowing most existing libraries to be used without adapters or cumberso...

Open Graph Description: Category language Slug call-c-from-java Title Calling out to C code from Java Difficulty advanced Since JDK 22 Summary Simplifies C/C++ code to be called from Java, allowing most existing libraries...

X Description: Category language Slug call-c-from-java Title Calling out to C code from Java Difficulty advanced Since JDK 22 Summary Simplifies C/C++ code to be called from Java, allowing most existing libraries...

Opengraph URL: https://github.com/javaevolved/javaevolved.github.io/issues/129

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Pattern]","articleBody":"### Category\n\nlanguage\n\n### Slug\n\ncall-c-from-java\n\n### Title\n\nCalling out to C code from Java\n\n### Difficulty\n\nadvanced\n\n### Since JDK\n\n22\n\n### Summary\n\nSimplifies C/C++ code to be called from Java, allowing most existing libraries to be used without adapters or cumbersome C code modification.\n\n### Old code label\n\nJava 1.1+\n\n### Old code\n\n```java\npublic class CallCFromJava {\n\tstatic { System.loadLibrary(\"hello-jni\"); }\n\tpublic static native int greet(String name);\n\tpublic static void main(String[] args) {\n\t\tint ret = greet(\"Bambi\");\n\t\tSystem.out.println(\"Return value \" + ret);\n\t}\n}\n\nThen run javac -h, then view the generated .h file, then write your .c file:\n\n#include \"CallCFromJava.h\"\n\nJNIEXPORT int JNICALL Java_CallCFromJava_greet(JNIEnv *env, jclass this, jstring str) {\n\tconst char* name = (*env)-\u003eGetStringUTFChars(env, str, NULL);\n\tprintf(\"Hello %s\\n\", name);\n\treturn 0;\n}\n```\n\n### Modern code label\n\nJava 22+\n\n### Modern code\n\n```java\npublic class CallCFromJava {\n  void main() throws Throwable {\n\n    try (Arena arena = Arena.ofConfined()) {\n      SymbolLookup ourLib = \n        SymbolLookup.libraryLookup(\"libhello-ffi.so\", arena);\n      Optional\u003cMemorySegment\u003e segment = ourLib.find(\"greet\");\n      MemorySegment foreignFuncAddr = segment.get();\n      FunctionDescriptor greet_sig= // return and input parameter\n          FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.ADDRESS);\n      MethodHandle greetMethod =\n        Linker.nativeLinker().downcallHandle(foreignFuncAddr, greet_sig);\n      var ret = (long) greetMethod.invokeExact(arena.allocateFrom(\"Bambi\"));\n      System.out.println(\"Return value \" + ret);\n    }\n  }\n}\n\nC Code:\nint greet(char* name) {\n    printf(\"Hello %s\\n\", name);\n    return 0;\n}\n```\n\n### Explanation\n\nJava has two techniques for interfacing between Java and C/C++ code, the traditional JNI and the newer FFM. With JNI you simply declare your method as native, but then you have to run `javac -h` to generate a C-language .h (header) file, then have your C code implement that, and deal with the slightly cumbersome JNI C-language API. \n\nFFM simplifies the C code to the point that it doesn't have to know anything about Java. This makes it *much* easier to interface with existing C/C++-language libraries.  It does take a few more lines of Java code, but the net effect is more readable and more maintainable. Compare the C code in both versions and you'll see the difference!\n\nMinimal runnable demo can be found at https://github.com/IanDarwin/javaevolved-java_callling_c \n\n### Why the modern way wins\n\n👁 Better readability — C code doesn't have to learn Java!\n⚡ More flexible - can directly call most existing C/C++ libraries\n⚡ Easier - don't have to stop, run javac -h, and implement the \"interface\" defined in .h file.","author":{"url":"https://github.com/IanDarwin","@type":"Person","name":"IanDarwin"},"datePublished":"2026-03-02T14:15:02.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/129/javaevolved.github.io/issues/129"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:0b2cae82-a979-c9dc-34c0-127fc072d193
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE43E:8F66F:295A31:38FFA1:6A602746
html-safe-nonceb51d595a22f471d5c60169d8943f258c3c4388cdc5473cc7c71132be90fef6ed
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDNFOjhGNjZGOjI5NUEzMTozOEZGQTE6NkE2MDI3NDYiLCJ2aXNpdG9yX2lkIjoiNzY5ODIwNjc2NjQ2MDMxNTQ2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacaa2f248e11b48ed0e068153ac6f78d53297178035305ebe3e5eef2fdf42a28f6
hovercard-subject-tagissue:4011516185
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/javaevolved/javaevolved.github.io/129/issue_layout
twitter:imagehttps://opengraph.githubassets.com/fbaf5e5968dd216ce6b6e25eb7a6929c84dfc721d237b174221810b96cd27fdc/javaevolved/javaevolved.github.io/issues/129
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/fbaf5e5968dd216ce6b6e25eb7a6929c84dfc721d237b174221810b96cd27fdc/javaevolved/javaevolved.github.io/issues/129
og:image:altCategory language Slug call-c-from-java Title Calling out to C code from Java Difficulty advanced Since JDK 22 Summary Simplifies C/C++ code to be called from Java, allowing most existing libraries...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameIanDarwin
hostnamegithub.com
expected-hostnamegithub.com
None60da8c2a42fa2bbf5f7567474990ec467836a84444262a58e200fa91b7f3d2d0
turbo-cache-controlno-preview
go-importgithub.com/javaevolved/javaevolved.github.io git https://github.com/javaevolved/javaevolved.github.io.git
octolytics-dimension-user_id261976795
octolytics-dimension-user_loginjavaevolved
octolytics-dimension-repository_id1159421298
octolytics-dimension-repository_nwojavaevolved/javaevolved.github.io
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1159421298
octolytics-dimension-repository_network_root_nwojavaevolved/javaevolved.github.io
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release9824515e740d83d5eb82168a089b806ab0fe04a1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/javaevolved/javaevolved.github.io/issues/129#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fjavaevolved%2Fjavaevolved.github.io%2Fissues%2F129
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fjavaevolved%2Fjavaevolved.github.io%2Fissues%2F129
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=javaevolved%2Fjavaevolved.github.io
Reloadhttps://github.com/javaevolved/javaevolved.github.io/issues/129
Reloadhttps://github.com/javaevolved/javaevolved.github.io/issues/129
Reloadhttps://github.com/javaevolved/javaevolved.github.io/issues/129
Please reload this pagehttps://github.com/javaevolved/javaevolved.github.io/issues/129
javaevolved https://github.com/javaevolved
javaevolved.github.iohttps://github.com/javaevolved/javaevolved.github.io
Notifications https://github.com/login?return_to=%2Fjavaevolved%2Fjavaevolved.github.io
Fork 25 https://github.com/login?return_to=%2Fjavaevolved%2Fjavaevolved.github.io
Star 375 https://github.com/login?return_to=%2Fjavaevolved%2Fjavaevolved.github.io
Code https://github.com/javaevolved/javaevolved.github.io
Issues 2 https://github.com/javaevolved/javaevolved.github.io/issues
Pull requests 1 https://github.com/javaevolved/javaevolved.github.io/pulls
Discussions https://github.com/javaevolved/javaevolved.github.io/discussions
Actions https://github.com/javaevolved/javaevolved.github.io/actions
Projects https://github.com/javaevolved/javaevolved.github.io/projects
Security and quality 0 https://github.com/javaevolved/javaevolved.github.io/security
Insights https://github.com/javaevolved/javaevolved.github.io/pulse
Code https://github.com/javaevolved/javaevolved.github.io
Issues https://github.com/javaevolved/javaevolved.github.io/issues
Pull requests https://github.com/javaevolved/javaevolved.github.io/pulls
Discussions https://github.com/javaevolved/javaevolved.github.io/discussions
Actions https://github.com/javaevolved/javaevolved.github.io/actions
Projects https://github.com/javaevolved/javaevolved.github.io/projects
Security and quality https://github.com/javaevolved/javaevolved.github.io/security
Insights https://github.com/javaevolved/javaevolved.github.io/pulse
#130https://github.com/javaevolved/javaevolved.github.io/pull/130
[Pattern]https://github.com/javaevolved/javaevolved.github.io/issues/129#top
#130https://github.com/javaevolved/javaevolved.github.io/pull/130
https://github.com/brunoborges
https://github.com/copilot-swe-agent
slugNew or updated pattern snippet (category/slug.json)https://github.com/javaevolved/javaevolved.github.io/issues?q=state%3Aopen%20label%3A%22slug%22
https://github.com/IanDarwin
IanDarwinhttps://github.com/IanDarwin
on Mar 2, 2026https://github.com/javaevolved/javaevolved.github.io/issues/129#issue-4011516185
https://github.com/IanDarwin/javaevolved-java_callling_chttps://github.com/IanDarwin/javaevolved-java_callling_c
brunoborgeshttps://github.com/brunoborges
Copilothttps://github.com/apps/copilot-swe-agent
slugNew or updated pattern snippet (category/slug.json)https://github.com/javaevolved/javaevolved.github.io/issues?q=state%3Aopen%20label%3A%22slug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.