+ All Categories
Home > Education > Java Programming and J2ME: The Basics

Java Programming and J2ME: The Basics

Date post: 26-May-2015
Category:
Upload: tosine
View: 923 times
Download: 1 times
Share this document with a friend
Popular Tags:
29
Mobile Programming with J2ME By Oluwatosin Adesanya
Transcript
Page 1: Java Programming and J2ME: The Basics

Mobile Programming with J2MEBy Oluwatosin Adesanya

Page 2: Java Programming and J2ME: The Basics

Lesson 01:Basic Java Programming

Page 3: Java Programming and J2ME: The Basics

Java is ...

• A Pure OOP Language• A Hybrid Programming Language• First Compiled and Interpreted• Runs on a JVM (Java Virtual Machine)

Source Code

Compiled

Byte Code

Object Code

Intepreted

Page 4: Java Programming and J2ME: The Basics

Getting Started

• JDK (Java Development Kit)• Editor (Notepad) OR ...• Integrated Development Environment (Netbeans,

Eclipse, JCreator etc.)

Page 5: Java Programming and J2ME: The Basics

Setting Up Java

• Install the JDK• The JDK Sits in C:\Program Files\Java\

jdk1.6.0

• Set the PATH Environmental Variable (How?)

Page 6: Java Programming and J2ME: The Basics

Setting the PATH Environmental Variable

Open your Systems Property: choose Advanced System Settings, Click the Environmental Variable Button on the Dialog that shows Up

Page 7: Java Programming and J2ME: The Basics

Setting the PATH Environmental Variable

Scroll and Select Path , Click Edit Button

Page 8: Java Programming and J2ME: The Basics

Setting the PATH Environmental Variable

Append the current path with the path to the Java bin folder

Page 9: Java Programming and J2ME: The Basics

Running Java

• Save your Java source code as a .java file• Use the javac Command to compile your source codes

(.java files) e.g javac Result.java• A .class file is generated called a bytecode• Use java Command to run the .class file e.g java Result• Do not add .class when compiling

Source Code javac Byte Code Object

Codejava

Page 10: Java Programming and J2ME: The Basics

The Structure of a Java Program

• Java Programs are made up of classes• Classes are made up of methods• Java existing (ready-made) classes are found in the Java

Class Libraries (Also Called Java APIs)• Execution of Java programs begin at the main method

Page 11: Java Programming and J2ME: The Basics

A Simple Java Program

public class HelloWorld {public static void main(String[] args) {

System.out.println("Hello World!");}

}

Page 12: Java Programming and J2ME: The Basics

Classes and Objects

• A Class is like a factory from which Objects are churned Out.

ExampleClass Car could produce objects Volkswagen bettles, Toyota Camri, Peugeout 306

An Object is a model of the Real World and hasStates (Or Properties) andBehaviours (Or Actions)

ExampleObject Car States are Color, Speed, Size, Plate Licence No, CostBehaviours are Start, Stop, Accelerate, Fuel, Open Door, etc.

Page 13: Java Programming and J2ME: The Basics

Creating a Class

Use the class Keyword

Examplepublic class HelloWorld {

.

.

.}

Do NOT Forget!Name your java file ClassName.java

Page 14: Java Programming and J2ME: The Basics

Adding States (Properties)

• States in Java are simply variables (Otherwise called fields)

Example

public class PaySlip {int numdone;String name;

}

Observe?!Every Line of Java code ends with a semicolon (;)

int,float, double, boolean, char … are Java Primitive Types

Page 15: Java Programming and J2ME: The Basics

Adding Behaviours (Methods)

• Methods are functions that control states or fields or

variables. They change the state of an object.

Example

public class PaySlip {int numdone;String name;

public double getPay() {return 40.00 * numdone;

}}

Method getPay()

Guess What? We already have a working Java Class!

Page 16: Java Programming and J2ME: The Basics

Using Our Class PaySlip

We implement another tester class whichcontains the main method.

public class TestPaySlip {public static void main(String[] args){

PaySlip opay=new PaySlip(); System.out.println("\n"+opay.getPay());

}}

Page 17: Java Programming and J2ME: The Basics

Constructors

• Initializes the Object after memory allocation• Takes the same name as the Class• May accept parameters OR... may not• Every Class has a default constructor that accepts no

parameter• Has No Return Type• Can be Overloaded (there can be multiple Constructors)

Page 18: Java Programming and J2ME: The Basics

Constructors

public class PaySlip {int numdone;String name;

public PaySlip(int numdone, String name) {this.numdone=numdone; this.name=name;

}

public PaySlip(){name=“Nobody”;numdone=0;

}

public double getPay() {return 40.00 * numdone;

}}

Page 19: Java Programming and J2ME: The Basics

Sorry...

• Confused?• Questions?

Page 20: Java Programming and J2ME: The Basics

Lesson 02:Java 2 Micro Edition(J2ME)

Page 21: Java Programming and J2ME: The Basics

J2ME is ...

• Java for small devices• Divided into Configurations, Profiles and Optional APIs

Configurations, Profiles and Optional APIs combined together make up a stack

Configurations: Specifies a JVM. We have CDC and CLDC

CLDC (Connected Limited Device Configuration) is designed for devices with limited memory, displays, battery power and inputs.

Profiles: Layered on top of CLDC and adds APIs for specific devices. We have MIDP, PDAP and Personal Profiles

MIDP (Mobile Information Device Profile) has characteristics that makes most low end phones and PDAs fit in. J2ME is covered by MIDPs

Page 22: Java Programming and J2ME: The Basics

Anatomy of MIDP Apps

Page 23: Java Programming and J2ME: The Basics

MIDP Apps are ...

• Called MIDlets• Portable• Secured• represented by instances of

javax.microedition.midlet.MIDlet class• Distributed as JAR (Java Archive) files along with a

MANIFEST file and an Application Descriptor File (.jad file)• Reduced to small sizes before distribution by an Obfuscator

Popular J2ME Apps: Opera Mini, 2go, Go Bible

Page 24: Java Programming and J2ME: The Basics

The MIDlet Life Cycle

Page 25: Java Programming and J2ME: The Basics

Shall We Create a MIDlet?

package com.thinkit2ru;

import javax.microedition.midlet.*;

public class Metric extends MIDlet {

public void startApp() { } public void pauseApp() { } public void destroyApp(boolean unconditional) { }}

Page 26: Java Programming and J2ME: The Basics

Remember the Constructor?

package com.thinkit2ru;

import javax.microedition.midlet.*;

public class Metric extends MIDlet {

public Metric() { } public void startApp() { } public void pauseApp() { } public void destroyApp(boolean unconditional) { }}

The Contructor:Build Components Here

Page 27: Java Programming and J2ME: The Basics

You need to Know...

• Primitive data types• String Manipulation• Control Statements• Arrays and other data structures• GUI Design• Database Connectivity• Multithreading• Ethics and Conventions

Page 28: Java Programming and J2ME: The Basics

Questions Please...

Page 29: Java Programming and J2ME: The Basics

System.out.println(“Thank You”);


Recommended