Welcome!

Java IoT Authors: Pat Romanski, Yeshim Deniz, Elizabeth White, Liz McMillan, Paul Simmons

Related Topics: Java IoT

Java IoT: Article

Developing Wireless Bluetooth Applications in J2ME

Portable, secure, and highly usable

Mobile communication comes into our daily lives very quickly, and as of today several wireless technologies have become standard. In this article I'll briefly review Bluetooth principles and the principles of Java development for Bluetooth on mobile devices.

The Java APIs for the Bluetooth wireless technology (JABWT) standard, defined by the JSR 82 specification (www.jcp.org/en/jsr/detail?id=82), supports the rapid development of Bluetooth applications that are portable, secure, and highly usable. Wireless device manufacturers have responded to the JABWT specification by announcing mobile phones and other products that will run JABWT applications.

What Is Bluetooth?
According to the latest Bluetooth 1.2 specification (www.bluetooth.org/spec/), Bluetooth wireless technology is a short-range communications system that's intended to replace the cable(s) connecting portable and/or fixed electronic devices. The Bluetooth core system consists of a radio frequency (RF) transceiver, baseband, and protocol stack. The system offers services that enable the connection of devices and the exchange of a variety of classes of data between these devices. Actually it's a wireless communication protocol that, like HTTP or FTP, operates in a client/server architecture. It uses the 2.4 GHz band known in the U.S. as the Industrial-Scientific-Medical (ISM) band. The 802.11b wireless LAN protocol operates in this band as well, although they are intended for different needs and don't interfere with each other.

Bluetooth Architecture
Bluetooth is a completely different way to communicate compared to cables, since during a typical operation a physical radio channel is shared by a group of devices that are synchronized to a common clock. One device provides the synchronization reference and is known as the master. All other devices are known as slaves. A group of devices synchronized in this way form a so-called piconet. A master and a single slave use point-to-point communication; if there are multiple slaves, point-to-multipoint communication is used. A master unit is the device that initiates the communication. A device in one piconet can communicate to another device in another piconet, forming a scatternet. The physical channel is subdivided into time units known as slots. Data is transmitted between Bluetooth devices in packets that are positioned in these slots. Above the physical channel there is a layering of links and channels and associated control protocols. The hierarchy of channels and links from the physical channel upward consists of a physical channel, a physical link, logical transport, a logical link, and a L2CAP channel. In Figure 1 we can see a high-level view of the architecture of the Bluetooth protocol stack.

The radio layer is the physical wireless connection. To avoid interference with other devices that communicate in the ISM band, the modulation is based on fast frequency hopping. Bluetooth divides the 2.4 GHz frequency band into 79 channels, 1 MHz apart (from 2.402 to 2.480 GHz), and uses this spread spectrum to hop from one channel to another, up to 1,600 times per second.

The baseband layer is responsible for controlling and sending data packets over the radio link. It provides transmission channels for both data and voice. The baseband layer maintains Synchronous Connection-Oriented (SCO) links for voice and Asynchronous Connectionless (ACL) links for data. SCO packets are never retransmitted but ACL packets are to ensure data integrity. The Host Controller Interface (HCI) controls the low-level operation of the radio and is the interface between the Bluetooth device and the host computer. Logical Link Controller Adaptation Protocol (L2CAP) multiplexes all data passing through the Bluetooth device. However, audio signals have direct access to the HCI. The Service Discovery Protocol (SDP) finds services on remote Bluetooth devices. RFCOMM is widely known as the virtual serial port protocol, because it allows a Bluetooth device to simulate the functionality of a serial port.

At the application level it can be any application that needs to exchange data through a wireless connection. Object Exchange Protocol (OBEX) is widely used and allows you to exchange object data (such as files). It's interesting that the Object Exchange (OBEX) API was developed by Java enthusiasts and became a subpackage of JSR 82.

Bluetooth Interacting
Bluetooth profiles exist to ensure interoperability among Bluetooth-enabled devices and applications from different manufacturers and vendors. A profile defines the roles and capabilities for specific types of applications. Bluetooth devices cannot interact unless they conform to a particular profile. There are a number of different profiles in a Bluetooth specification, such as Synchronization, Serial Port, and LAN Access. The Synchronization Profile defines the application requirements for Bluetooth devices that need to synchronize data on two or more devices. The Serial Port Profile defines the requirements for Bluetooth devices that need to set up connections that emulate serial cables and use the RFCOMM protocol. The LAN Access Profile defines how Bluetooth devices can access the services of a LAN using PPP, and shows how PPP mechanisms can be used to form a network consisting of Bluetooth devices.

Security is provided in three ways: pseudo-random frequency hopping, authentication, and encryption. Frequency hops make it difficult for anyone to eavesdrop. Authentication allows a user to limit connectivity to specified devices. Encryption uses secret keys to make data intelligible only to authorized parties.

Java API
Now we can see how easy it is to connect two devices with Bluetooth using Java. The Java Bluetooth API relies on the Java Generic Connection Framework, which limited it to J2ME for a long time. However, now it's been proposed to include GCF in J2SE, and the Bluetooth API can be made accessible for a broader range of systems. The Java APIs for Bluetooth define two packages: javax.bluetooth for the core Bluetooth API and javax.obex for the Object Exchange (OBEX) protocol. Any Bluetooth application has these components: stack initialization, device management, device discovery, service discovery, and communication. According to JSR 82, the underlying Bluetooth system must support a Bluetooth Control Center (BCC), a control panel much like the application that allows a user or OEM to define specific values for certain configuration parameters in a stack. In particular, it will be used in a stack initialization.

Stack Initialization
Prior to starting wireless communication the Bluetooth device should be initialized. This is done in a vendor-dependent way, and exact steps for stack initialization are beyond the scope of the Bluetooth API specification. As shown by Bruce Hopkins, the author of Bluetooth for Java, in his article "Getting Started with Java and Bluetooth" (http://today.java.net/pub/a/today/2004/07/27/bluetooth.html), it is done using several settings in the Atinav Java Bluetooth SDK (see Listing 1). It is important that these calls are not part of JSR 82. Other JSR 82 implementations may incorporate other ways to initialize the stack.

Device Management
The JSR 82 API introduces two classes that can be used for device management: LocalDevice to request static information about the Bluetooth device, and RemoteDevice to retrieve information about devices in the Bluetooth neighborhood, e.g., a remote device Bluetooth Address. LocalDevice depends on the javax.bluetooth.DeviceClass class to retrieve the device's type and the kinds of services it offers. The RemoteDevice class represents a remote device (a device within a range of reach) and provides methods to retrieve information about the device, including its Bluetooth address and name. Every Bluetooth device has a unique hardware address, like the MAC address for computers. You can set the level of device discovery, enabling other Bluetooth devices to find the current device by calling the setDiscoverable() method in the LocalDevice object (see Listing 2).

More Stories By Peter V. Mikhalenko

Peter Mikhalenko holds a masters in computer science from Moscow State University. He has made code contributions to several worldwide open source projects and has written many articles on XML and Java. Peter is a Sun certified professional and works in Deutsche Bank co-developing a finance transactional system.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world.
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
As data explodes in quantity, importance and from new sources, the need for managing and protecting data residing across physical, virtual, and cloud environments grow with it. Managing data includes protecting it, indexing and classifying it for true, long-term management, compliance and E-Discovery. Commvault can ensure this with a single pane of glass solution – whether in a private cloud, a Service Provider delivered public cloud or a hybrid cloud environment – across the heterogeneous enter...
DXWorldEXPO LLC announced today that ICC-USA, a computer systems integrator and server manufacturing company focused on developing products and product appliances, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of ...
More and more brands have jumped on the IoT bandwagon. We have an excess of wearables – activity trackers, smartwatches, smart glasses and sneakers, and more that track seemingly endless datapoints. However, most consumers have no idea what “IoT” means. Creating more wearables that track data shouldn't be the aim of brands; delivering meaningful, tangible relevance to their users should be. We're in a period in which the IoT pendulum is still swinging. Initially, it swung toward "smart for smart...
Headquartered in Plainsboro, NJ, Synametrics Technologies has provided IT professionals and computer systems developers since 1997. Based on the success of their initial product offerings (WinSQL and DeltaCopy), the company continues to create and hone innovative products that help its customers get more from their computer applications, databases and infrastructure. To date, over one million users around the world have chosen Synametrics solutions to help power their accelerated business or per...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
In an era of historic innovation fueled by unprecedented access to data and technology, the low cost and risk of entering new markets has leveled the playing field for business. Today, any ambitious innovator can easily introduce a new application or product that can reinvent business models and transform the client experience. In their Day 2 Keynote at 19th Cloud Expo, Mercer Rowe, IBM Vice President of Strategic Alliances, and Raejeanne Skillern, Intel Vice President of Data Center Group and ...
Founded in 2000, Chetu Inc. is a global provider of customized software development solutions and IT staff augmentation services for software technology providers. By providing clients with unparalleled niche technology expertise and industry experience, Chetu has become the premiere long-term, back-end software development partner for start-ups, SMBs, and Fortune 500 companies. Chetu is headquartered in Plantation, Florida, with thirteen offices throughout the U.S. and abroad.
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
"We are a well-established player in the application life cycle management market and we also have a very strong version control product," stated Flint Brenton, CEO of CollabNet,, in this SYS-CON.tv interview at 18th Cloud Expo at the Javits Center in New York City, NY.
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
Most people haven’t heard the word, “gamification,” even though they probably, and perhaps unwittingly, participate in it every day. Gamification is “the process of adding games or game-like elements to something (as a task) so as to encourage participation.” Further, gamification is about bringing game mechanics – rules, constructs, processes, and methods – into the real world in an effort to engage people. In his session at @ThingsExpo, Robert Endo, owner and engagement manager of Intrepid D...
Recently, WebRTC has a lot of eyes from market. The use cases of WebRTC are expanding - video chat, online education, online health care etc. Not only for human-to-human communication, but also IoT use cases such as machine to human use cases can be seen recently. One of the typical use-case is remote camera monitoring. With WebRTC, people can have interoperability and flexibility for deploying monitoring service. However, the benefit of WebRTC for IoT is not only its convenience and interopera...
Michael Maximilien, better known as max or Dr. Max, is a computer scientist with IBM. At IBM Research Triangle Park, he was a principal engineer for the worldwide industry point-of-sale standard: JavaPOS. At IBM Research, some highlights include pioneering research on semantic Web services, mashups, and cloud computing, and platform-as-a-service. He joined the IBM Cloud Labs in 2014 and works closely with Pivotal Inc., to help make the Cloud Found the best PaaS.
Everything run by electricity will eventually be connected to the Internet. Get ahead of the Internet of Things revolution. In his session at @ThingsExpo, Akvelon expert and IoT industry leader Sergey Grebnov provided an educational dive into the world of managing your home, workplace and all the devices they contain with the power of machine-based AI and intelligent Bot services for a completely streamlined experience.
Cloud-enabled transformation has evolved from cost saving measure to business innovation strategy -- one that combines the cloud with cognitive capabilities to drive market disruption. Learn how you can achieve the insight and agility you need to gain a competitive advantage. Industry-acclaimed CTO and cloud expert, Shankar Kalyana presents. Only the most exceptional IBMers are appointed with the rare distinction of IBM Fellow, the highest technical honor in the company. Shankar has also receive...
Business professionals no longer wonder if they'll migrate to the cloud; it's now a matter of when. The cloud environment has proved to be a major force in transitioning to an agile business model that enables quick decisions and fast implementation that solidify customer relationships. And when the cloud is combined with the power of cognitive computing, it drives innovation and transformation that achieves astounding competitive advantage.
Personalization has long been the holy grail of marketing. Simply stated, communicate the most relevant offer to the right person and you will increase sales. To achieve this, you must understand the individual. Consequently, digital marketers developed many ways to gather and leverage customer information to deliver targeted experiences. In his session at @ThingsExpo, Lou Casal, Founder and Principal Consultant at Practicala, discussed how the Internet of Things (IoT) has accelerated our abilit...
In his session at Cloud Expo, Alan Winters, U.S. Head of Business Development at MobiDev, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to maximize project result...