Future Directions. 1. Java 3D API. 2. Java's Security Model. Table of Contents

Similar documents
Wrapper Generator using Java Native Interface

CS Software Engineering for Scientific Computing. Lecture 25:Mixed Language Programming.

Programming CAN-based Fieldbus Systems using Java

Numerical Algorithms Group

Installing Java (Windows) and Writing your First Program

CSE 452: Programming Languages. Acknowledgements. Contents. Java and its Evolution

Multithreading and Java Native Interface (JNI)!

Development_Setting. Step I: Create an Android Project

Installing Java. Table of contents

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

JDBC (Java / SQL Programming) CS 377: Database Systems

Java Software Development Kit (JDK 5.0 Update 14) Installation Step by Step Instructions

Database Access from a Programming Language: Database Access from a Programming Language

Database Access from a Programming Language:

Java Crash Course Part I

How to use the Eclipse IDE for Java Application Development

Applets, RMI, JDBC Exam Review

Chapter 1 Java Program Design and Development

CS/CE 2336 Computer Science II

Crash Course in Java

Contents. Java - An Introduction. Java Milestones. Java and its Evolution

Supplement IV.D: Tutorial for MS Access. For Introduction to Java Programming By Y. Daniel Liang

Introduction to Object-Oriented Programming

Using the Java Native Interface to Introduce Device Driver Basics

Supplement IV.C: Tutorial for Oracle. For Introduction to Java Programming By Y. Daniel Liang

To Java SE 8, and Beyond (Plan B)

Native code in Android Quad Detection

An Overview of Java. overview-1

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

FileMaker 14. ODBC and JDBC Guide

Software. Programming Language. Software. Instructor Özgür ZEYDAN. Bülent Ecevit University Department of Environmental Engineering

CS 253: Intro to Systems Programming

Java Programming Fundamentals

Enterprise Java. Where, How, When (and When Not) to Apply Java in Client/Server Business Environments. Jeffrey Savit Sean Wilcox Bhuvana Jayaraman

CSC 551: Web Programming. Spring 2004

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Java SE 7 Programming

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Java SE 7 Programming

Java SE 7 Programming

Java Application Developer Certificate Program Competencies

CS346: Database Programming.

Tutorial: Getting Started

What Perl Programmers Should Know About Java

Practice Fusion API Client Installation Guide for Windows

Developing, Deploying, and Debugging Applications on Windows Embedded Standard 7

A Short Introduction to Writing Java Code. Zoltán Majó

Java applets. SwIG Jing He

Introduction to Java

Introduction to Native Android Development with NDK

Web Integrated Solutions

InterBase 6. API Guide. Borland/INPRISE. 100 Enterprise Way, Scotts Valley, CA

SE 450 Object-Oriented Software Development. Requirements. Topics. Textbooks. Prerequisite: CSC 416

CS506 Web Design and Development Solved Online Quiz No. 01

Jaybird 2.1 JDBC driver. Java Programmer's Manual

CS 106 Introduction to Computer Science I

Japan Communication India Skill Development Center

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

Developing a Web Server Platform with SAPI Support for AJAX RPC using JSON

1001ICT Introduction To Programming Lecture Notes

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

How to Install Java onto your system

Image Acquisition Toolbox Adaptor Kit User's Guide

Java SE 8 Programming

Using the Remote Access Library

VOL. 3, NO.10 Oct, 2012 ISSN Journal of Emerging Trends in Computing and Information Sciences CIS Journal. All rights reserved.

Install Java Development Kit (JDK) 1.8

LAB 6: Code Generation with Visual Paradigm for UML and JDBC Integration

3 IDE (Integrated Development Environment)

Android Hands-On Labs

Programmierpraktikum

Application Development A Cocktail of Java and MCP. MCP Guru Series Dan Meyer & Pramod Nair

Opening a Command Shell

CS 209 Programming in Java #1

FTP Client Engine Library for Visual dbase. Programmer's Manual

Working With Derby. Version 10.2 Derby Document build: December 11, 2006, 7:06:09 AM (PST)

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

The JAVA Way: JDBC and SQLJ

Project Adding a System Call to the Linux Kernel

2. Follow the installation directions and install the server on ccc

Suite. How to Use GrandMaster Suite. Exporting with ODBC

Object-Oriented Programming in Java

Java and Java Virtual Machine security vulnerabilities and their exploitation techniques

Android NDK Native Development Kit

RTI Connext DDS. Core Libraries Getting Started Guide Addendum for Android Systems Version 5.2.0

How To Use A Sas Server On A Java Computer Or A Java.Net Computer (Sas) On A Microsoft Microsoft Server (Sasa) On An Ipo (Sauge) Or A Microsas (Sask

Creating a Java application using Perfect Developer and the Java Develo...

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

CS 377 Database Systems SQL Programming. Li Xiong Department of Mathematics and Computer Science Emory University

Java with Eclipse: Setup & Getting Started

Elements of Advanced Java Programming

DB2 Connect for NT and the Microsoft Windows NT Load Balancing Service

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

WHAT ARE PACKAGES? A package is a collection of related classes. This is similar to the notion that a class is a collection of related methods.

COSC344 Database Theory and Applications. Java and SQL. Lecture 12

JDBC. It is connected by the Native Module of dependent form of h/w like.dll or.so. ex) OCI driver for local connection to Oracle

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Why Is This Important? Database Application Development. SQL in Application Code. Overview. SQL in Application Code (Contd.

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Transcription:

Future Directions Table of Contents 1. Java 3D API... 1 2. Java's Security Model... 1 3. Native Methods... 2 3.1 Declare the Native Method... 3 3.2 Compile the HelloWorld Class... 4 3.3 Create the Native Method Header File... 4 3.4 Compile the C Source and Create a Native Library... 6 3.5 Run the Program... 6 4. JDBC... 7 Interfaces... 7 Classes... 7 Exceptions... 8 5. Remote Method Invocation (RMI)... 8 6. Java Servlet API... 8 7. The Java Media Framework... 8 8. Java Telephony API...8 9. Java Electronic Commerce Framework... 8 10. Java Communications API... 8 1. Java 3D API Based on OpenGL 2. Java's Security Model Java's security model - Broken into two pieces: The user adjustable security manager that checks various API operations like file access, The byte code verifier that asserts the validity of compiled byte code. public abstract class SecurityManager java.lang.securitymanager - Abstract class which different applications subclass to implement a particular security policy. Allows an application to determine whether or not a particular operation will generate a security exception. With one exception the following methods all throw security exceptions if an operation is not allowed. public void checkcreateclassloader() public void checkaccess(thread g) public void checkaccess(threadgroup g) public void checkexit(int status) public void checkexec(string cmd)

public void checklink(string lib) public void checkread(filedescriptor fd) public void checkread(string file) public void checkread(string file, Object context) public void checkwrite(filedescriptor fd) public void checkwrite(string file) public void checkdelete(string file) public void checkconnect(string host, int port) public void checkconnect(string host, int port, Object context) public void checklisten(int port) public void checkaccept(string host, int port) public void checkmulticast(inetaddress maddr) public void checkmulticast(inetaddress maddr, byte ttl) public void checkpropertiesaccess() public void checkpropertyaccess(string key) public boolean checktoplevelwindow(object window) public void checkprintjobaccess() public void checksystemclipboardaccess() public void checkawteventqueueaccess() public void checkpackageaccess(string pkg) public void checkpackagedefinition(string pkg) public void checksetfactory() public void checkmemberaccess(class c, int which) public void checksecurityaccess(string action) 3. Native Methods Can call code written in C, C++, or assembler. For performance and sometimes to access the underlying host operating system Java Native Interface. The process consists of the following steps: 1. Create a class (HelloWorld.java) that declares the native method. 2. Use javac to compile the HelloWorld source file, resulting in the class file HelloWorld.class. 3. Use javah -jni to generate a C header file (HelloWorld.h) containing the function prototype for the native method implementation. The javah tool is provided with JDK or Java 2 SDK releases. 4. Write the C implementation (HelloWorld.c) of the native method. 5. Compile the C implementation into a native library, creating Hello-World.dll or libhello-world.so. Use the C compiler and linker available on the host environment. 6. Run the HelloWorld program using the java runtime interpreter. Both the class file (HelloWorld.class) and the native library (HelloWorld.dll or libhelloworld.so) are loaded at runtime.

Figure 1 The processs to write a simple Java application that calls a C function to print "Hello World!". 3.1 Declare the Native Method You begin by writing the following program in the Java programming language. The program defines a class named HelloWorld that contains a native method, print. class HelloWorld { private native void print(); public static void main(string[] args) { new HelloWorld().print(); } static { System.loadLibrary("HelloWorld"); }}

The HelloWorld class definition begins with the declaration of the print native method. This is followed by a main method that instantiates the Hello-World class and invokes the print native method for this instance. The last part of the class definition is a static initializer that loads the native library containing the implementation of the print native method. There are two differences between the declaration of a native method such as print and the declaration of regular methods in the Java programming language. o A native method declaration must contain the native modifier. o The native modifier indicates that this method is implemented in another language. o Also, the native method declaration is terminated with a semicolon, the statement terminator symbol, because there is no implementation for native methods in the class itself. o Implement the print method in a separate C file. Before the native method print can be called, the native library that implements print must be loaded. In this case, we load the native library in the static initializer of the HelloWorld class. The Java virtual machine automatically runs the static initializer before invoking any methods in the HelloWorld class, thus ensuring that the native library is loaded before the print native method is called. Define a main method to be able to run the HelloWorld class. Hello-World.main calls the native method print in the same manner as it would call a regular method. System.loadLibrary takes a library name, locates a native library that corresponds to that name, and loads the native library into the application. We will discuss the exact loading process later in the book. For now simply remember that in order for System.loadLibrary("HelloWorld") to succeed, we need to create a native library called HelloWorld.dll on Win32, or libhelloworld.so on Solaris. 3.2 Compile the HelloWorld Class After the HelloWorld class is defined, save the source code in a file called HelloWorld.java. Then compile the source file using the javac compiler that comes with the JDK or Java 2 SDK release: javac HelloWorld.java This command will generate a HelloWorld.class file in the current directory. 3.3 Create the Native Method Header File Use the javah tool to generate a JNI-style header file that is useful when implementing the native method in C. You can run javah on the Hello-World class as follows: javah -jni HelloWorld

The name of the header file is the class name with a ".h" appended to the end of it. The command shown above generates a file named HelloWorld.h. The generated header file in its entirety here is long. The most important part of the header file is the function prototype for Java_HelloWorld_print, which is the C function that implements the HelloWorld.print method: JNIEXPORT void JNICALL Java_HelloWorld_print (JNIEnv *, jobject); Ignore the JNIEXPORT and JNICALL macros for now. You may have noticed that the C implementation of the native method accepts two arguments even though the corresponding declaration of the native method accepts no arguments. o The first argument for every native method implementation is a JNIEnv interface pointer. o The second argument is a reference to the HelloWorld object itself (sort of like the "this" pointer in C++). The JNI-style header file generated by javah helps you to write C or C++ implementations for the native method. The function that you write must follow the -prototype specified in the generated header file. You can implement the Hello-World.print method in a C file HelloWorld.c as follows: #include <jni.h> #include <stdio.h> #include "HelloWorld.h" JNIEXPORT void JNICALL Java_HelloWorld_print(JNIEnv *env, jobject obj) { printf("hello World!\n"); return; } The implementation of this native method is straightforward. It uses the printf function to display the string "Hello World!" and then returns. As mentioned before, both arguments, the JNIEnv pointer and the reference to the object, are ignored. The C program includes three header files: jni.h -- This header file provides information the native code needs to call JNI functions. When writing native methods, you must always include this file in your C or C++ source files. stdio.h -- The code snippet above also includes stdio.h because it uses the printf function.

HelloWorld.h -- The header file that you generated using javah. It includes the C/C++ prototype for the Java_HelloWorld_print function. 3.4 Compile the C Source and Create a Native Library Remember that when you created the HelloWorld class in the HelloWorld.java file, you included a line of code that loaded a native library into the program: System.loadLibrary("HelloWorld"); Now that all the necessary C code is written, you need to compile Hello-World.c and build this native library. Different operating systems support different ways to build native libraries. On Solaris, the following command builds a shared library called libhello-world.so: cc -G -I/java/include -I/java/include/solaris HelloWorld.c -o libhelloworld.so The -G option instructs the C compiler to generate a shared library instead of a regular Solaris executable file. Because of the limitation of page width in this book, we break the command line into two lines. You need to type the command in a single line, or place the command in a script file. On Win32, the following command builds a dynamic link library (DLL) HelloWorld.dll using the Microsoft Visual C++ compiler: cl -Ic:\java\include -Ic:\java\include\win32 -MD -LD HelloWorld.c -FeHelloWorld.dll The -MD option ensures that HelloWorld.dll is linked with the Win32 multithreaded C library. The -LD option instructs the C compiler to generate a DLL instead of a regular Win32 executable. Of course, on both Solaris and Win32 you need to put in the include paths that reflect the setup on your own machine. 3.5 Run the Program At this point, you have the two components ready to run the program. The class file (HelloWorld.class) calls a native method, and the native library (Hello-World.dll) implements the native method. Because the HelloWorld class contains its own main method, you can run the program on Solaris or Win32 as follows: java HelloWorld You should see the following output: Hello World! It is important to set your native library path correctly for your program to run. The native library path is a list of directories that the Java virtual machine searches when loading native

libraries. If you do not have a native library path set up correctly, then you see an error similar to the following: java.lang.unsatisfiedlinkerror: no HelloWorld in library path at java.lang.runtime.loadlibrary(runtime.java) at java.lang.system.loadlibrary(system.java) at HelloWorld.main(HelloWorld.java) Make sure that the native library resides in one of the directories in the native library path. If you are running on a Windows 95 or Windows NT machine, make sure that HelloWorld.dll is in the current directory, or in a directory that is listed in the PATH environment variable. In Java 2 SDK 1.2 release, you can also specify the native library path on the java command line as a system property as follows: java -Djava.library.path=. HelloWorld The "-D" command-line option sets a Java platform system property. Setting the java.library.path property to "." instructs the Java virtual machine to search for native libraries in the current directory. 4. JDBC The Java Database Connectivity API, JDBC java.sql package. Enables Java programs to connect to and interact with relational, SQL databases like MySQL, Interfaces CallableStatement Connection DatabaseMetaData Driver PreparedStatement ResultSet ResultSetMetaData Statement Classes Date DriverManager DriverPropertyInfo Time Timestamp Types

Exceptions DataTruncation SQLException SQLWarning 5. Remote Method Invocation (RMI) RMI and its related technology, object serialization Allow objects in one virtual machine to invoke methods on objects in other virtual machines, even when the other virtual machine is on a physically separate host somewhere else on the Internet. 6. Java Servlet API The Java Servlet API is a class library for servlets. Servlets are Java programs that run on the server and send data to the client, much like CGI programs but with a few advantages in terms of performance. 7. The Java Media Framework The Java Media Framework is a standard extension to Java 1.2 Provides much more powerful support for multimedia including timing, sound, animation, and video. 8. Java Telephony API Java was originally developed to be embedded in consumer electronics. Java Telephony API for integrating smart phone systems with computers. 9. Java Electronic Commerce Framework Provides the infrastructure for monetary transactions on the Internet by any Java capable browser. 10. Java Communications API For serial and parallel port communications