Wednesday May 15, 2013

Series On Embedded Development (Part 6) - Power Efficiency

Let's not forget efficieny as it pertains to power...important for embedded devices, especially battery powered ones. I mentioned avoiding idle tasks in the last installment and the suggestions here build on that same theme (CPU (therefore power) conservation):

Avoid inefficient polling - inefficient polling will keep the CPU busy and waste power. You should spend time thinking about your polling algorithm and optimize it to reduce CPU usage. Can you poll when the CPU isn't being utilized much?

Avoid idling and block waiting on asynchronous events - these are also things which will consume CPU. Instead of waiting, implement a listener pattern so your application is event-driven.

Provide quiet periods to allow the CPU to sleep - any time the CPU is asleep, power is being conserved.

Don’t assume there are multiple CPU cores - coding for multiple cores can place a demand on a single-core machine. Try to code efficiently for the machine you'll be running on.

Tuesday Apr 16, 2013

Series On Embedded Development (Part 5) - Efficiency

In this 5th installment of Embedded Development, I'm going to talk about efficiency. Efficiency has to do with, well, being efficient. It has to do with not being wasteful...not doing things which don't need to be done. It also has to do with doing things more efficiently...doing things you wouldn't normally do to have more efficient code.

A good example of this is moving fields to helper classes. If you have a class which contains fields which aren't used often, consider moving them to a helper class which contains sparsely-used fields. You will save memory and CPU cycles when the fields are not used. The memory and CPU will only be incurred when the fields are used. This is something you wouldn't normally do. I'm not talking about fields shared by multiple classes, which you do put into shared classes. This falls under the category of making your Java classes efficient (read smaller, using less memory, and less CPU in the typical case).

Related to moving fields to helper classes is grouping like-used fields together in shared classes. If you put too few fields in too many classes, you'll end up burning CPU and memory instantiating too many fields. Put fields which are likely to be used by the same functionality in shared classes. This is especially useful when the fields are static.

Simply eliminate extra fields. This one should be obvious, but if you've removed a reference to a field, make sure the field is still needed. A good IDE can help with this.

Use smaller buffers. This is related to the cache discussion in 'Part 4 - Tunability'. When using buffers, you should make them small and grow them as needed. Growing your buffers will incur some CPU cycles *when they grow*, but only then. Take care to ensure you don't make them too small and grow them in too small chunks. Testing and profiling will help find the sweet spot.

Use the smallest data type you can for each field. Do you really need a long or will an integer do just as well? Do you really need an integer or will a short do just as well. I rarely see the use of shorts. Most of the time I see ints used.

Keep stack frames small. This is especially important in recursive calls.

Avoid idle tasks which prevent the CPU from sleeping or going into low-power mode.

Usually once you start thinking in terms of efficiency (size/memory, less code/CPU) rather than just functionality and performance, you'll start getting creative ideas for keeping data structures smaller. Don't forget to get creative with your data structure layouts as well!

Thursday Nov 01, 2012

Series On Embedded Development (Part 2) - Build-Time Optionality

In this entry on embedded development, I'm going to discuss build-time optionality (BTO). BTO is the ability to subset your software at build-time so you only use what is needed. BTO typically pertains more to software providers rather then developers of final products. For example, software providers ship source products, frameworks or platforms which are used by developers to build other products.

If you provide a source product, you probably don't have to do anything to support BTO as the developers using your source will only use the source they need to build their product. If you provide a framework, then there are some things you can do to support BTO. Say you provide a Java framework which supports audio and video. If you provide this framework in a single JAR, then developers who only want audio are forced to ship their product with the video portion of your framework even though they aren't using it. In this case, support providing the framework in separate JARs...break the framework into an audio JAR and a video JAR and let the users of your framework decide which JARs to include in their product. Sometimes this is as simple as packaging, but if, for example, the video functionality is dependent on the audio functionality, it may require coding work to cleanly separate the two.

BTO can also work at install-time, and this is sometimes overlooked. Let's say your building a phone application which can use Near Field Communications (NFC) if it's available on the phone, but it doesn't require NFC to work. Typically you'd write one app for all phones (saving you time)...both those that have NFC and those that don't, and just use NFC if it's there. However, for better efficiency, you can detect at install-time if the phone supports NFC and not install the NFC portion of your app if the phone doesn't support NFC. This requires that you write the app so it can run without the optional NFC code and that you write your install app so it can detect NFC and do the right thing at install-time. Supporting install-time optionality will save persistent footprint on the phone, something your customers will appreciate, your app "neighbors" will appreciate, and that you'll appreciate when they save static footprint for you.

In the next article, I'll writing about runtime optionality.

Wednesday Oct 24, 2012

Series On Embedded Development (Part 1)

This is the first in a series of entries on developing applications for the embedded environment. Most of this information is relevant to any type of embedded development (and even for desktop and server too), not just Java. This information is based on a talk Hinkmond Wong and I gave at JavaOne 2012 entitled Reducing Dynamic Memory in Java Embedded Applications.

One thing to remember when developing embeddded applications is that memory matters. Yes, memory matters in desktop and server environments as well, but there's just plain less of it in embedded devices. So I'm going to write about saving this precious resource as well as another precious resource, CPU cycles...and a bit about power too. CPU matters too, and again, in embedded devices, there's just plain less of it. What you'll find, no surprise, is that there's a trade-off between performance and memory. To get better performance, you need to use more memory, and to save more memory, you need to need to use more CPU cycles.

I'll be discussing three Memory Reduction Categories:

- Optionality, both build-time and runtime. Optionality is about providing options so you can get rid of the stuff you don't need and include the stuff you do need.

- Tunability, which is about providing options so you can tune your application by trading performance for size, and vice-versa.

- Efficiency, which is about balancing size savings with performance.

Tuesday Sep 25, 2012

Oracle Unveils Oracle Java Embedded Suite 7.0

Today Oracle announced the Oracle Java Embedded Suite 7.0. What is the Java Embedded Suite (JES)? It's a middleware stack designed to be run on embedded devices. It's a suite which includes an application server (Glassfish for Embedded Suite), database (Java DB), and web services (Jersey Web Services Framework). Putting these services on the embedded device gives you the ability to provide a set of services at the device point. It also lets you aggregate data at the device point, which you can later sync with your enterprise systems.

Monday Sep 28, 2009

Trust your Instinct(s)

Add the recently released Samsung Instinct HD (available exclusively on Sprint and available now at Best Buy) to the growing list of JavaME consumer devices. This device is pretty special though. Why? Because it's the first device to combine the two JavaME stacks (CDC and CLDC) and to include OSGi into the mix. This device has an OSGi implementation running on top of a CDC stack, and running MIDP on top of OSGi. The application model generally used on the device is MIDP, but at some point it could allow running other OSGi applications and CDC applications as well. There's a lot of capability built into this phone.

Monday Jun 15, 2009

2009 JavaOne Presentations Online

If you missed JavaOne this year, possibly due to the economic downturn and the ever tightening of corporate belts, do not despair. The technical presentations presented at JavaOne are now available to Sun Developer Network members (this membership is free) here: 2009 JavaOne Technical Sessions. If you missed the keynotes, you can view replays of those here: 2009 JavaOne Conference. Granted, you don't get to mingle with other Java developers, but there's lots of good information in the presentations and contact information if you want to get more information on a particular presentation. It's the next best thing to being there.

Wednesday Jul 18, 2007

The NetBeans Visual Web Pack...Wow

Not long ago I needed to create some web pages which were tied to a database. Not being an expert in creating Web applications, I decided to take a stab at using NetBeans and the Visual Web Pack to create some web pages. All I have to say is Wow. I created a new Visual Web application, created a few web pages, created a database connection, added a bunch of design elements including connecting some fields to database columns, added some page navigation, and built and ran the application (NetBeans automatically deployed the application to one of the included servers), all within minutes and all graphically. While this is no customer-facing Internet-ready application, I don't think it's too far off. It amazes me how much functionality can be created so easily in such a short amount of time.

Thursday Feb 15, 2007

JavaOne Session Preview Online

The JavaOne Session Preview is now available online. What is cool about this is that Sun's Eco group has calculated these statistics in providing this document online rather then sending out a paper hard-copy:

By producing this piece virtually, the Eco group has calculated the savings Sun has made:
  • Assuming (based on last year) the document is equivalent to 2.5 pages of 0% recycled copy paper
  • Total paper saved = 4.63 tons
  • Greenhouse Gases reduced (CO2 equivalents) = 13 tons (26,297 lbs)
  • Reduction in wood use = 13 tons
  • # of trees saved (assuming 1 tree makes 16.67 reams of copy paper or 8,333.3 sheets) = 111
  • Reduction in wastewater (and associated water pollution) = 78,616 gallons \*(equivalent to 838K cans of soda)\*
  • Reduction in solid waste (stuff sent to landfills) = 5.1 tons

Regardless of how it's delivered, this is your first chance to see what's happening at this year's JavaOne.

Thursday Nov 02, 2006

NetBeans 5.5 Has Been Released

In case you haven't had a chance to look at the NetBeans website lately, NetBeans 5.5 has been released. This release includes not only an improved NetBeans product, but also the Mobility Pack for CDC (Beta 2), the Mobility Pack for CLDC, the C/C++ Toolkit Beta 3, Subversion support, the Visual Web Pack (Creator) Technology Preview , the Enterprise Pack (with UML modeling), and more. For those interested, the website has been completely re-designed as well.

Tuesday Jul 18, 2006

Splitting Windows in NetBeans

I've found from talking to many people that it isn't common knowledge that you can split a window in NetBeans. That is, displaying multiple editor windows at a time by dividing up the display. You can split windows horizontally and vertically, just like any good editor or IDE. This is very easy to do in NetBeans.

To split a window horizontally, you simply click and hold the mouse button on a tab at the top of the editor and drag it to the bottom (or top) area of the editor. As you do this, you'll see an outline of where the window will be placed. Let go of the mouse button and the window will split and display at the bottom. You can then click and drag the area between the bottom window's tab area and the top window's status bar area to resize the window.

To split the window vertically, do the same thing as above, except drag to the right (or left) side of the editor window and let go. Again, you'll see an outline letting you know where the window will be placed.

You can continue to do this and keep splitting windows as you like. Of course, with the amount of space the window takes up (tab area, toolbar area, status bar area, etc.), your real estate diminishes quickly. BTW, you can get rid of the toolbar to free up more space (right-mouse click on the area to the left of the edit window and de-select 'Show toolbar').

You can add multiple files to the split window as well. Just make your first split, then drag and drop a second tab into the middle of the target split area. The file will be added.

To get rid of a split, drag a tab from the split area back to the middle of the main area. The file will be moved to the main area. If the file is the last one in the split area, the split will disappear.

You can also view different sections of a file at the same time. Simply right-mouse click on the tab of the file and choose 'Clone Document'. You'll see another tab show up with the same name. Then use the cloned window to split the window. You now have the same document displayed side by side. You can scroll both windows independently.

Wednesday Oct 19, 2005

Quick Typing (Code Templates) in NetBeans

A good programming editor will help you get your code written faster. There are many ways editors do this. One way it to make it easier to write often written and long, hard to type code. NetBeans helps you write your code faster in several ways. In particular, NetBeans's code templates feature helps you write hard to type, lengthy code faster.

Code templates are short menmonics which can be expanded to code. For example, if you open a Java file in NetBeans, go to an empty line, and type 'sout', then hit Ctrl-Space, NetBeans will expand this to 'System.out.println("");' and place the cursor between the two double quotes. System.out.println is an often-used line of code and typing 'sout Ctrl-Space' is much easier then reaching for the () and " keys. 'fori', for a for loop, and 'En' for Enumeration are also useful. You can also create your own code templates for lengthy code you may be using in your project. This may include classes, method calls, exceptions, and comments.

To modify code templates in NetBeans 5.0, go to Tools->Options->Editor->Code Templates. There you'll see the list of code templates for each language supported in NetBeans. You can add, modify, and remove code templates to suit your needs

Wednesday Sep 28, 2005

NetBeans 5.0 Beta has been released!

NetBeans 5.0 beta is now available. The new features in this version are great, they really increase programmer productivity. This new version is also fast. I'll give you more details on it in the coming days, especially some of the new cool features. Congratulations NetBeans team!

Wednesday Aug 31, 2005

NetBeans 4.1's Text Limit Line

It is often the little things that can really make a difference. For those of you who may not have noticed (because it is very subtle), when you're editing a Java file (actually, any supported file) in NetBeans, a vertical text limit line displays in the edit window. I thought it was an artifact of a bad monitor. It's a faint pink line which shows you where your text limit is based on your editor settings. Maybe it's because I come from Emacs, but I continually look at the column number my cursor is on to make sure I don't go over this line. I hate it when you bring up an 80 column editor and you have line breaks all over the place. It makes the code more difficult to read. You can change your text limit and the color (I changed mine to a darker shade of stands out more) of the text limit line in NetBeans by going to 'Tools', 'Options'. The Options dialog displays. Navigate to the 'Editing', 'Editor Settings' and highlight the 'Java Editor' section. At the bottom of the options, you can change the line color, select if it is displayed, and change the number of characters which is your text limit.

Friday Aug 26, 2005

QuickSearch in NetBeans

It's amazing what you can learn while doing the wrong thing. I was working on my project today in NetBeans 4.1. I \*thought\* my edit window had the focus, so I started typing. Lo and behold, I see this small 'Quick Search' window popup in my Projects window (the window which really had the focus). Intrigued, I entered a filename and hit the 'Enter' key. NetBeans did a search in the Projects window and took me to the file. Cool! I don't know all of the windows in which this works, but it works in the Favorites, Projects, Versioning, Runtime, and Navigator windows.

Darryl Mocek


« July 2016