Skip to content

apsrcreatix/15IT411J-IPT

Repository files navigation

15IT411J Integrative Programming And Technology Laboratory

1. Instructions for Java Native Interface

This section is only for 00-03 titled experiments (JNI related ) in this repository.

1.1 Requirements

  1. A Java Compiler “javac” which ships with the SDK
  2. A Java Virtual Machine “java” which ships with the SDK
  3. A native method c header file generator “javah” which ships with the SDK.
  4. A C/C++ compiler “cc” that can create shared library

1.2 Steps for output

To run the program related java native interface follow the following commands for linux on terminal :

  1. Compile the java code.
  • A
    • Java file name.
 javac A.java
  1. Create C/C++ header file.
  • A
    • class file name.
javah A
  1. Create a shared library file using the C/C++ file created using terminal.
  • A

    • Put lib and then the name for the file written inside the .java file under static block.

    • Example - JNIDemo.java

      • static
        {
        System.loadLibrary("JNIDemo");
        }

        Then library file's name should be libJNIDemo.so

  • B

    • C file name.
  • How to get jdk folder path in linux

    • If you don't have jdk1.8.0* then follow these commands if you are using ubuntu or any debian based distro :

      • sudo apt-get update
        sudo apt install default-jdk

        Enter password (if you have) and Press Y/y

    • Go to root directory and search for jdk1.8.0 or a file jni.h

    • You may get the folder then can copy the path for include folder and linux folder

gcc -fPIC -I"/usr/java/jdk1.8.0_181/include" -I"/usr/java/jdk1.8.0_181/include/linux" --shared -o A.so B.c
  1. Run the java program.
  • A - Name of class file.
java -Djava.library.path=. A

1.3 Reference

REFERENCE FOR MORE CODE

2. Instructions for Beans

This section will show you how to use these projects (04 - 07)

2.1 Non Visual Bean Project

For 04-jb-non-visual-bean

  • If you are a IntelliJ IDEA user then directly import the project or open this project in IDE.
  • If you are a Netbeans user then follow the steps :
    • Create a new project.
    • Choose JavaFx Application.
    • Name the project whatever you want and finish.
    • Go to workspace directory of Netbeans and delete src folder.
    • Paste src folder from 04-jb-non-visual-bean
    • Build and run the project now.