Java Native Interface (Java JNI)

What is Java Native Interface (Java JNI)? Java JNI is a programming framework that enables the Java native code running in a Java virtual machine to call native applications specific to the operating system and hardware. JNI enables one to write native methods to handle situations when an application cannot be written entirely in the Java programming language. Here I am describing how to do programming with JNI with an example. JNI is difficult, as it involves two languages and runtimes. I shall assume that you are familiar with: Java C/C++ and the GCC Compiler (For Windows) Gygwin or MinGW. (For IDE) Eclipse C/C++ Development Tool (CDT) Here, I am giving an example of C programming language. Step 1: Write a Java class that uses native methods public class HelloJNI { static { System.loadLibrary(“hello”); /* hello.dll (Windows) or libhello.so (Unixes)*/ } /* A native method that receives nothing and returns void*/ private native void sayHello(); public static void main(String[] args) { /* invoke the native method*/ new HelloJNI().sayHello(); } } Here we can see a static block, which will load the library hello.dll in Windows and libhello.so in unix systems during the class loading. The library should be available in the java’s library path otherwise it will throw UnsatisfiedLinkError. You can include the library in Java’s library path via VM argument, -Djava.library.path=path_to_lib. Next, we declare the method sayHello() as a native instance method, via the keyword native, which denotes that this method is implemented in another language. A native method does not contain a body. The sayHello() is contained in the native library loaded. The main() method allocates an instance of HelloJNI and invokes the native method sayHello(). Step 2: Compile the java file javac HelloJNI.java This will create HelloJNI.class file. Step 3: Create the C/Header file – HelloJNI.h Using javah utility, we can create header file for the corresponding HelloJNI class. javah HelloJNI It will generate the following file HelloJNI.h /* DO NOT EDIT THIS FILE – it is machine generated */ #include <jni.h> /* Header for class HelloJNI */ #ifndef _Included_HelloJNI #define _Included_HelloJNI #ifdef __cplusplus extern “C” { #endif /* * Class: HelloJNI * Method: sayHello * Signature: ()V */ JNIEXPORT void JNICALL Java_HelloJNI_sayHello (JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif Here, it defines a C function Java_HelloJNI_sayHello as follows JNIEXPORT void JNICALL Java_HelloJNI_sayHello(JNIEnv *, jobject); The naming convention for C function is Java_{package_and_classname}_{function_name}(JNI arguments). The dot in package name shall be replaced by underscore. The arguments: JNIEnv*: reference to JNI environment, which lets you access all the JNI fucntions. jobject:reference to “this” Java object The extern “C” is recognized by C++ compiler only. It notifies the C++ compiler that these functions are to be compiled using C’s function naming protocol (instead of C++ naming protocol). C and C++ have different function naming protocols as C++ support function overloading and uses a name mangling scheme to differentiate the overloaded functions. Step 4: C Implementation – HelloJNI.c #include <jni.h> #include <stdio.h> #include “HelloJNI.h” JNIEXPORT void JNICALL Java_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) { printf(“Hello World!\n”); return; } save this file as “HelloJNI.c”. The header “jni.h” is available under the “JAVA_HOME>\include” and “<JAVA_HOME>\include\win32″ directories, where <JAVA_HOME> is your JDK installed directory (e.g., “c:\program files\java\jdk1.7.0″). The C function will print “Hello World” in the console. Compile this program depends on the C compiler you use. gcc -Wl,–add-stdcall-alias -I”<JAVA_HOME>\include” -I”<JAVA_HOME>\include\win32″ -shared -o hello.dll HelloJNI.c The compiler options used are: -Wl: The -Wl to pass linker option –add-stdcall-alias to prevent UnsatisfiedLinkError (symbols with a stdcall suffix (@nn) will be exported as-is and also with the suffix stripped). (Some people suggested to use -Wl,–kill-at.) -I: for specifying the header files directories. In this case “jni.h” (in “<JAVA_HOME>\include”) and “jni_md.h” (in “<JAVA_HOME>\include\win32″), where <JAVA_HOME> denotes the JDK installed directory. Enclosed the directory in double quotes if it contains spaces. -shared: to generate share library. -o: for setting the output filename “hello.dll”. You can also compile and link in two steps: // Compile-only with -c flag. Output is HElloJNI.o > gcc -c -I”<JAVA_HOME>\include” -I”<JAVA_HOME>\include\win32″ HelloJNI.c // Link into shared library “hello.dll” > gcc -Wl,–add-stdcall-alias -shared -o hello.dll HelloJNI.o Step 5:Run the Java Program java HelloJNI or java -Djava.library.path=. HelloJNI You may need to specify the library path of the “hello.dll” via VM option -Djava.library.path=<path_to_lib>, as shown above. Have questions? Contact the technology experts at InApp to learn more.

Exposure in Image and Video Processing

Video and image processing enables us to acquire, process, and analyze images and video data for data visualization and manipulation. We have explored the following open-source API for video and image manipulation: OpenCV: OpenCV (Open Source Computer Vision Library) is mainly focused on real-time image processing applications. It supports Windows, Linux, Mac OS, iOS, and Android and has been written in optimized C/C++. FFMPEG: FFmpeg is a command-line tool to convert multimedia files between formats. This is mainly used to decode, encode, transcode, stream, filter, and play the media file. It runs on the following platforms: Windows, Linux, Mac OS, iOS, and Android. Xuggler: Xuggler is a Java library that allows the decoding and encoding of a variety of media file formats. It supports Windows XP or later, 32 or 64-bit versions, Linux using libc version 6, 32 or 64-bit (i.e. Ubuntu 11.10 and later), Mac OS X 10.7 32 or 64-bit. JMTF: The Java Motion Tracking Framework is a modular framework for detecting and tracking motion in prerecorded sequences of frames. It is pure java and therefore requires no other native libraries. JMF: The Java Media Framework API is used for capture, playback, streaming, and transcoding multiple media formats, and extends the Java 2 Platform, Standard Edition (J2SE) for multimedia developers by providing a powerful toolkit to develop scalable, cross-platform technology. Java with JMF can be used to implement a motion detection Some of our projects have featured video processing functionalities like: Frame Extraction: Extract the frames from the video with respect to the frame rate. Video Trimming: Trim the video with a specific duration. Audio extraction: Using the FFmpeg library we can extract the audio channels from a video file Video generation: Generating video from the sequence of frames. Video Shake Reduction: We can reduce the shake in the video by calculating the optical flow. Optical flow is the relative motion between two images. Further, we have undertaken projects that involved image processing functionalities like: Background subtraction: Helps to differentiate between the background and foreground of the image. Object Extraction: This is the process of identifying and extracting the object from the image. SURF: SURF stands for “Speeded Up Robust Features” for detecting the local feature from an image. Face recognition: Recognize the human face from the image. Edge detection: Detect the edge of the image primarily for identifying an object Overlaying: Overlay the two images with transparency property, useful for creating strobe images Stroboscope: Stroboscope is the representation of a series of shots from a continuous motion of a moving object and is obtained by stitching together the strobe images obtained from a video. Insert text/image: Text and images can be overlayed and is useful for animating the image or video. Have questions? Contact the technology experts at InApp to learn more.

Cloud Testing – Nuts & Bolts

Need for Cloud Testing – Issues and Challenges Traditional testing has limitations like latency, performance, concurrency, and planning issues and is way too expensive. Cloud testing is a big game changer and surpasses the challenges faced by traditional testing. It can be used to provide a flexible, scalable, and affordable testing environment at all times or on demand. Cloud testing typically involves monitoring and reporting on real-world user traffic conditions as well as load balance and stress testing for a range of simulated usage conditions. The availability of virtual machines eases the process of setting up, using, reusing, and running test setups. Complex test setups are available as stacked templates, making it easy to integrate complex automation into various processes to build complex cloud testing systems. Cloud testing is a great fit for an agile environment. It can leverage the whole life cycle of web or mobile app development, right from the beginning of development until the application is in production. Today, if you need to generate thousands of virtual users to test a specific web application then the number of servers required for that test can be deployed within a couple of minutes. Best of all, you only need to pay those servers for the duration of the test thus making it more economical and viable. Cloud testing is flexible enough that it can be used for continuous performance testing. Test maker runs tests in multiple cloud testing environments making it possible to manage performance from different geographical locations. Tester gets a real-time testing experience of applications on browsers and OS rather than simulated environments. Cloud testing eliminates the cost of building and maintaining a test lab for load and performance testing. If a specific test environment is required, just use it via the cloud. There is no need to provision expensive and difficult-to-manage quality test labs. Cloud-based testing poses different operational challenges in the real-world scenario. One of the major challenges would be creating an on-demand test environment. The current cloud technology does not have any supporting solutions that will help cloud engineers build a cost-effective cloud test environment. For scalability and performance testing, the current framework and solutions do not support the features such as dynamic scalability, scalable testing environments, SLA-based requirements, and cost models. Testing security is yet another concern inside clouds as security services become a necessary part of modern cloud technology. Engineers must deal with issues and challenges in security validation and quality assurance for SaaS (Software as a Service) and clouds. Integration testing in the cloud may not be performed due to lack of time or additional integration cost which subsequently affects the performance of the application. Cloud testing is under constant evolution, continuously bringing in new opportunities and challenges. It reduces the need for hardware and software resources and offers a flexible and efficient alternative to traditional testing. Finally, moving testing to the cloud is seen as a safe bet as it does not include sensitive corporate data and has minimal impact on the organization’s business activities. Migration of self-testing to the cloud would bring about a notion of test support as-a-service. Have questions? Contact the cloud testing experts at InApp to learn more.

Again Java Is The World’s No.1 Programming Language

Java has reclaimed the No.1 spot of the TIOBE Index, ending C’s four-month stay at the top of the programming rankings. The TIOBE Programming Community Index is an indicator of the popularity of programming languages. The index is updated once a month. The ratings are based on the number of skilled engineers worldwide, courses, and third-party vendors. Popular search engines such as Google, Bing, Yahoo!, Wikipedia, Amazon, YouTube, and Baidu are used to calculate the ratings. Observe that the TIOBE index is not about the best programming language or the language in which most lines of code have been written. The biggest casualties from this rethink are C and Objective C. While both only fell one spot in the rankings (C to 2nd, Objective to 4th), they lost 1.65% and -2.17% of the total share respectively. The winners from August’s changes include Google’s garbage collecting language Go (up 16 places to 26th) visual dataflow dialect LabVIEW (from 100 to 49) and business application language OpenEdge ABL (from 129 to 57). Fellow JVM languages Scala (37) and Groovy (44) remain in the Top 50. Very Long Term History To see the bigger picture, please find the positions of the top 10 programming languages from 5, 15, and 25 years ago in the table below. Have questions? Contact the technology experts at InApp to learn more.

JQuery – Use The “On()” Method Instead Of “Live()”

JQuery – Use The “On()” Method Instead Of “Live()”

As of jQuery 1.7, the .live() method is deprecated.Use.on() to attach event handlers. Description: Attach an event handler function for one or more events to the selected elements. The .on() method attaches event handlers to the currently selected set of elements in the jQuery object. Syntax:- .on(events[,selector][,data],handler(eventObj)) .on(eventType, selector, function) Examples:- $(“body”).on(“click”, “#element”, function(){ $(“#my”).html(result); }); $(“body”).on(“click” , “p” ,function(){ alert($(this).text()); }); Migration from .live() to .on() before: $(‘#mainmenu a’).live(‘click’, function) after, you move the child element (a) to the .on() selector: $(‘#mainmenu’).on(‘click’, ‘a’, function) Have questions? Contact the technology experts at InApp to learn more.

What is Apache Airavata? Its Features and Architecture

What is Apache Airavata? Its Features and Architecture

What is the meaning of Airavata? Airavata is a mythological white elephant that carries the Hindu god Indra. It is also called ‘abhra-Matanga’, meaning “Elephant of the Clouds” (http://en.wikipedia.org/wiki/Airavata) What is Apache Airavata? Apache Airavata is a software framework for executing and managing computational jobs and workflows on distributed computing resources including local clusters, supercomputers, national grids, and academic and commercial clouds. Airavata has the capability of composing, managing, executing, and monitoring a variety of distributed applications and workflows that runs on computational resources. Concepts of service-oriented computing, distributed messaging, workflow composition, and orchestration provide the foundation for Airavata. You can visit the official website of Apace Airavata at https://airavata.apache.org/ What are the Features of Apache Airavata? Desktop tools and browser-based web interface components for managing applications, workflows, and generated data. Sophisticated server-side tools for registering and managing scientific applications on computational resources. Graphical user interfaces to construct, execute, control, manage, and reuse scientific workflows. Interfacing and interoperability with various external (third party) data, workflow, and provenance management tools. Airavata Architecture The architecture is designed to be a modular, componentized software framework as illustrated in the following Figure. The goal of the Airavata framework is minimalist architectural design (i.e., a thin layer), a conceptually simple to understand architecture; and easier to install, maintain and use. Have questions? Contact the technology experts at InApp to learn more.

Testing Web Services using ApacheBench

Testing Web Services using ApacheBench

ApacheBench (ab) is a tool for benchmarking an Apache Hypertext Transfer Protocol (HTTP) server. This shows how many requests per second the server is capable of handling. A point to note is that ApacheBench will only use one operating system thread regardless of the concurrency level; specified by the -c parameter. In some cases, especially when benchmarking high-capacity servers, a single instance of ApacheBench can itself be a bottleneck. To overcome this, additional instances of ApacheBench may be used in parallel to more fully saturate the target URL. ApacheBench was recently used to test the capability of the Caleum server, to find the threshold of the total number of web requests it can concurrently serve, in its current configuration. Working with ApacheBench Installing on a Windows machine Download the software from the link http://www.apache.org/dist/httpd/binaries/win32/ by selecting any mirrors on the site. Select the latest version of the software or later Double-click and install the software. While installing provide the information Network Domain: localhost Server Name: localhost Admin Email: provide a real or fake email Leave all default checkboxes checked After installation, an icon will be displayed in the system tray. This means Apache2.2 has been installed and started. To verify further type http://localhost/ in the browser. If Apache 2.2 has been started the message “It works!” in bold will be loaded in the browser. To stop/restart the server click on the icon ->Apache 2.2->Stop/Restart. To measure the performance of a server you may need to point your files to Apache. Since we are doing a web service testing this step is optional. Execution: Open the command prompt and go to the path where ApacheBench is installed say “C:\Program Files\Apache Software Foundation\Apache2.2\bin” Type ab –n 100 –c 10 http://{webserver hostname:port}/{document path} You can also provide the authentication details as the parameters in the document path. Other options that can be used are Options are: -n requests Number of requests to perform -t timelimit Seconds to max. wait for responses -v verbosity How much troubleshooting info to print -b windowsize Size of TCP send/receive buffer, in bytes -C attribute Add cookie, eg. ‘Apache=1234. (repeatable) -H attribute Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’ Inserted after all normal header lines. (repeatable) -A attribute Add Basic WWW Authentication, the attributes are a colon-separated username and password. -P attribute Add Basic Proxy Authentication, the attributes are a colon-separated username and password. -x attributes String to insert as table attributes -y attributes String to insert as tr attributes -z attributes String to insert as td or th attributes -Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers) -c concurrency Number of multiple requests to make -T content-type Content-type header for POSTing, eg. ‘application/x-www-form-urlencoded’. The default is ‘text/plain’ -g filename Output collected data to gnuplot format file. -e filename Output CSV file with percentages served -p postfile The file containing data to POST. Remember also to set -T -f protocol Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL) -X proxy:port Proxy server and port number to use -i Use HEAD instead of GET -V Print the version number and exit -k Use the HTTP KeepAlive feature -d Do not show the percentiles served table. -S Do not show confidence in estimators and warnings. -r Don’t exit on socket receive errors. -h Display usage information (this message) -w Print out results in HTML tables Output as below is displayed in the cmd prompt after the execution Concurrency Level: 10 Time taken for tests: 321.212 sec Complete requests: 1000 Failed requests: 11 (Connect: 0, Receive: 0, Length: 11, Exceptions: 0) Write errors: 0 Document length 21bytes Total transferred: 22124 bytes HTML transferred: 11994 bytes Requests per second: 1.01 [#/sec] (mean) Time per request: 1216.319 [ms] (mean) Time per request: 156.272 [ms] (mean, across all concurrent requests) Transfer rate: 1.81 [Kbytes/sec] received 1.61 kb/s sent 0.42 kb/s total Connection Times (ms) min mean [+/-sd] median max Connect: 200 200 121 212 3000 Processing: 301 2121 612.8 1921 3267 Waiting: 211 2112 21 121 1211 Total: 711 3546 799.3 3281 6547 Percentage of the requests served within a certain time (ms) 50% 1212 66% 3823 75% 2211 80% 4555 90% 5555 95% 6666 98% 7777 99% 8888 100% 8899 (longest request) It shows the total time to complete the entire test and the number of completed requests and failed requests. If there is any fail an additional line will be displayed. Connect:, Receive:, Length:, Exceptions: While testing the web server, we mainly focus on the fails in Connect and Receive. The failure in the length is due to the content length not being specified or some additional data like ads coming up in the page which goes beyond the specified length. Have questions? Contact the software testing experts at InApp to learn more.

WebSocket SaaS | WebSocket Protocol Handshake

WebSocket SaaS

There are many technologies that the server will send data to the client at the very moment it knows that the new data is available such as push, comet, etc. These all create an illusion that the server initiated the connection called long polling. With the long polling, the client opens an HTTP connection to the server and keeps it open until it receives a response. These techniques work quite well, we use them daily in applications such as Gtalk. All of these work-around have one problem such as they carry the overhead of HTTP and will not be suited for low-latency applications. WebSocket: Sockets into the web The WebSocket defines an API establishing a socket connection between a browser and a server. Simply, it is a persistent connection between the client and the server and both parties can send data at any time. It is an independent TCP-based protocol. Its only relationship to HTTP is that the handshake is handled using HTTP servers as an Upgrade request. WebSocket protocol handshake For establishing a WebSocket connection, the client sends a handshake request and the server sends back the handshake response as shown below. GET /chat HTTP/1.1 Host: inapp.com/ Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw== Sec-WebSocket-Protocol: chat Sec-WebSocket-Version: 13 Origin: http://old.inapp.com Server response HTTP/1.1 101 Switching Protocols Upgrade: WebSocket Connection: Upgrade Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk= Sec-WebSocket-Protocol: chat Getting started Create a WebSocket connection using javascript (supports only in modern HTML 5-enabled browsers). var connection = new WebSocket(‘ws://localhost:8080/test’); You might have noticed that ws:// which is the URL schema for websocket connection. There is also wss:// for a secure WebSocket connection. // When the connection is open, send some data to the server connection.onopen = function () { connection.send(‘Ping’); // Send the message ‘Ping’ to the server }; // Log errors connection.onerror = function (error) { console.log(‘WebSocket Error ‘ + error); }; // Log messages from the server connection.onmessage = function (e) { console.log(‘Server: ‘ + e.data); }; The Server-Side With the release of Windows Server 2012 and Windows 8, Internet Information Services (IIS) 8.0 has added support for the WebSocket Protocol. http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-websocket-protocol-support The apache-WebSocket module is an Apache 2.x server module that may be used to process requests using the WebSocket protocol (RFC 6455) by an Apache 2.x server. https://github.com/disconnect/apache-websocket Also, Tomcat 7 provides API for WebSocket but has not yet been finalized. http://tomcat.apache.org/tomcat-7.0-doc/web-socket-howto.html Have questions? Contact the technology experts at InApp to learn more.

Mobile App Installation Checklist

Mobile App Installation Checklist

Mobile App Installation Checklist: Ensure the test device is not the same as used for development or is is not set up as the development environment. Verify that application can be installed successfully following normal installation procedures. Verify that version number matches the version specified during submission Verify the application is seen in the installed applications list. Verify whether proper alert is displayed when we doesn’t follow the normal installation procedures. Check installation with low wifi connectivity. Test installation behaviour with wifi in disconnected mode. Check uninstallation and reinstallation. Check Application start/stop behavior — Start the application by selecting the icon or following the steps outlined in the submission statement. Check installation behaviour when receiving voice calls — while installation process is in progress, make a call to the test device. Check installation behaviour when receiving text messages — while installation process is in progress, send a text message to the test device. Check if the app is supported on an older firmware (ie: iOS 3.1.3), especially if it is part of the requirement, else an intelligent message should be displayed to the user.

InApp India Office

121 Nila, Technopark Campus
Trivandrum, Kerala 695581
+91 (471) 277 -1800
mktg@inapp.com

InApp USA Office

999 Commercial St. Ste 210 Palo Alto, CA 94303
+1 (650) 283-7833
mktg@inapp.com

InApp Japan Office

6-12 Misuzugaoka, Aoba-ku
Yokohama,225-0016
+81-45-978-0788
mktg@inapp.com
Terms Of Use
© 2000-2026 InApp, All Rights Reserved