PROGRAMMING CONCEPTS AND
EMBEDDED PROGRAMMING IN
C, C++ and JAVA:
Lesson-10: Embedded Programming
in Java
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 1
Design", Raj Kamal, Publs.: McGraw-Hill Education
Java programming
Starts from coding for the classes.
Members in a class
Fields like variables or struc in C.
Method the operations on the fields,
similar to function in C.
instance fields and instance methods in a
class the members, whose new instances
are also created as when the objects creates
from the class.
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 2
Design", Raj Kamal, Publs.: McGraw-Hill Education
Java programming
Class a named set of codes that has a
number of members – data fields
(variables), methods (functions), etc. so that
object can be created from it.
The operations done on the objects by
passing the messages to the objects in
object-oriented programming.
Each classa logical group with an identity,
a state and a behaviour specification.
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 3
Design", Raj Kamal, Publs.: McGraw-Hill Education
Inheritance in Java programming
Java Class inherits members when a Java
class extends from a parent class called
super class.
The inherited instance fields and methods
can be overridden by redefining them in
extended class.
Methods can be overloaded by redefining
them for different number of arguments.
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 4
Design", Raj Kamal, Publs.: McGraw-Hill Education
Interface in Java programming
Interface has only the abstract methods and
static data fields
Methods not implementation at the Interface
Java class interfacing to an Interface
implements the abstract methods specified
at the Interface
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 5
Design", Raj Kamal, Publs.: McGraw-Hill Education
Primitive data types in Java programming
Java Class uses : Byte (8-bit), shot (16-bit),
int (32-bit, long (64-bit, float, double, char
(16-bit).
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 6
Design", Raj Kamal, Publs.: McGraw-Hill Education
Reference data types
Java Class uses reference data types.
A reference can be Class type in which
there are groups of fields and methods to
operate on the fields.
A reference can be Array type in which
there are groups of objects as array
elements.
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 7
Design", Raj Kamal, Publs.: McGraw-Hill Education
Exception classes
Many inbuilt Exception classes
The occurrences of exceptional conditions
are handled when exception is thrown.
It is also possible to define exception
conditions in a program so that exceptions
are thrown from try block codes and caught
by catch exception method .
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 8
Design", Raj Kamal, Publs.: McGraw-Hill Education
Java Features
Java is completely an OOP language
Application program consists of classes
and interfaces
There is a huge class library on the
network that makes program development
quick
Java has extensibility
Java programs posses the ability to run
under restricted permissions
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 9
Design", Raj Kamal, Publs.: McGraw-Hill Education
Multiple threads in Java Program
Java has in-built support for creating
multiple threads
It obviates the need for an operating system
(OS) based scheduler for handling the tasks
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 10
Design", Raj Kamal, Publs.: McGraw-Hill Education
Java Features
Java generates the byte codes
These are executed on an installed JVM
(Java Virtual Machine) on a machine.
Virtual machine takes the Java byte codes
in the input and runs on the given platform
(processor, system and OS). [Virtual
machine (VM) in embedded systems is
stored at the ROM.] Therefore, Java codes
can host on diverse platforms.
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 11
Design", Raj Kamal, Publs.: McGraw-Hill Education
Java Platform Independence Features
Platform independence in hosting the
compiled codes permit Java for network
applications.
Platform independence gives portability
with respect to the processor and the OS
used. Java is considered as write once and
run anywhere .
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 12
Design", Raj Kamal, Publs.: McGraw-Hill Education
Java Features
Java is the language for most Web
applications and allows machines of
different types to communicate on the
Web.
Java is easier to learn by a C++
programmer.
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 13
Design", Raj Kamal, Publs.: McGraw-Hill Education
Java Features
Java does not permit pointer manipulation
instructions. So it is robust in the sense that
memory leaks and memory related errors do not
occur. A memory leak occurs, for example, when
attempting to write to the end of a bounded array.
Java does not permit dual way of object
manipulation by value and reference.
There are no struc, enum, typedef and union.
Java does not permit multiple inheritances.
Java does not permit operator overloading except
for + sign used for string concatenation
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 14
Design", Raj Kamal, Publs.: McGraw-Hill Education
Some disadvantages
• Java byte codes that are generated need
a larger memory when a method has
more than 3 or 4 local variables. An
embedded Java system may need a
minimum of 512 kB ROM and 512 kB
RAM because of the need to first install
JVM and then run the application.
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 15
Design", Raj Kamal, Publs.: McGraw-Hill Education
Ways to overcome the disadvantages
1) Use of J2ME (Java 2 Micro
Edition) or Java Card or
EmbeddedJava helps in reducing the
code size to 8 kB for the usual
applications like smart card.
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 16
Design", Raj Kamal, Publs.: McGraw-Hill Education
Summary
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 17
Design", Raj Kamal, Publs.: McGraw-Hill Education
We learnt
• Java provides all the advantages of
object oriented programming
• Declare private as many classes as
possible. It helps in optimising the
generated codes.
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 18
Design", Raj Kamal, Publs.: McGraw-Hill Education
We learnt
• Java has inherent multithreaded
features
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 19
Design", Raj Kamal, Publs.: McGraw-Hill Education
• Java provides the benefits of
extensive class libraries for
network and web applications,
modularity, robustness, secure
restricted permissions, portability
and platform independence.
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 20
Design", Raj Kamal, Publs.: McGraw-Hill Education
We learnt
• Use char, int and boolean (scalar
data types) in place of objects
(reference data types) as arguments
and use local variables as much as
feasible.
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 21
Design", Raj Kamal, Publs.: McGraw-Hill Education
We learnt J2ME provides
• secure restricted permissions
• portability
• platform independence for programming
small devices such as mobile and card
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 22
Design", Raj Kamal, Publs.: McGraw-Hill Education
End of Lesson 10 of Chapter 7
on
Embedded Programming in Java
Chapter 7 L10: "Embedded Systems- Architecture, Programming and
2015 23
Design", Raj Kamal, Publs.: McGraw-Hill Education