Successfully reported this slideshow.
Mobile Programming with J2ME               By Oluwatosin Adesanya
Lesson 01:Basic Java Programming
Java is ...     •   A Pure OOP Language     •   A Hybrid Programming Language     •   First Compiled and Interpreted     •...
Getting Started• JDK (Java Development Kit)• Editor (Notepad) OR ...• Integrated Development Environment (Netbeans, Eclips...
Setting Up Java• Install the JDK• The JDK Sits in C:Program FilesJavajdk1.6.0• Set the PATH Environmental Variable (How?)
Setting the PATH Environmental VariableOpen your Systems Property: choose Advanced System Settings, Clickthe Environmental...
Setting the PATH Environmental VariableScroll and Select Path , Click Edit Button
Setting the PATH Environmental VariableAppend the current path with the path to the Java bin folder
Running Java• Save your Java source code as a .java file• Use the javac Command to compile your source codes (.java files)...
The Structure of a Java Program• Java Programs are made up of classes• Classes are made up of methods• Java existing (read...
A Simple Java Programpublic class HelloWorld {  public static void main(String[] args) {      System.out.println("Hello Wo...
Classes and Objects• A Class is like a factory from which Objects are churned Out.   Example   Class Car could produce obj...
Creating a ClassUse the class KeywordExamplepublic class HelloWorld {          .          .          .    }Do NOT Forget!N...
Adding States (Properties)• States in Java are simply variables (Otherwise called fields)   Example   public class PaySlip...
Adding Behaviours (Methods)•   Methods are functions that control states or fields or variables. They    change the state ...
Using Our Class PaySlipWe implement another tester class whichcontains the main method.public class TestPaySlip {      pub...
Constructors•   Initializes the Object after memory allocation•   Takes the same name as the Class•   May accept parameter...
Constructorspublic class PaySlip {   int numdone;   String name;    public PaySlip(int numdone, String name) {        this...
Sorry...• Confused?• Questions?
Lesson 02:Java 2 Micro Edition(J2ME)
J2ME is ...•   Java for small devices•   Divided into Configurations, Profiles and Optional APIs    Configurations, Profil...
Anatomy of MIDP Apps
MIDP Apps are ...• Called MIDlets• Portable• Secured• represented by instances of  javax.microedition.midlet.MIDlet class•...
The MIDlet Life Cycle
Shall We Create a MIDlet?package com.thinkit2ru;import javax.microedition.midlet.*;public class Metric extends MIDlet {   ...
Remember the Constructor?package com.thinkit2ru;import javax.microedition.midlet.*;public class Metric extends MIDlet {   ...
You need to Know...•   Primitive data types•   String Manipulation•   Control Statements•   Arrays and other data structur...
Questions Please...
System.out.println(“Thank You”);
Upcoming SlideShare
Loading in …5
×

Java Programming and J2ME: The Basics

1,417 views

Published on

Published in: Education
  • Be the first to comment

Java Programming and J2ME: The Basics

  1. 1. Mobile Programming with J2ME By Oluwatosin Adesanya
  2. 2. Lesson 01:Basic Java Programming
  3. 3. Java is ... • A Pure OOP Language • A Hybrid Programming Language • First Compiled and Interpreted • Runs on a JVM (Java Virtual Machine) Byte CodeSource Object Code Code
  4. 4. Getting Started• JDK (Java Development Kit)• Editor (Notepad) OR ...• Integrated Development Environment (Netbeans, Eclipse, JCreator etc.)
  5. 5. Setting Up Java• Install the JDK• The JDK Sits in C:Program FilesJavajdk1.6.0• Set the PATH Environmental Variable (How?)
  6. 6. Setting the PATH Environmental VariableOpen your Systems Property: choose Advanced System Settings, Clickthe Environmental Variable Button on the Dialog that shows Up
  7. 7. Setting the PATH Environmental VariableScroll and Select Path , Click Edit Button
  8. 8. Setting the PATH Environmental VariableAppend the current path with the path to the Java bin folder
  9. 9. 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 Object javac Byte Code java Code Code
  10. 10. 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
  11. 11. A Simple Java Programpublic class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); }}
  12. 12. Classes and Objects• A Class is like a factory from which Objects are churned Out. Example Class Car could produce objects Volkswagen bettles, Toyota Camri, Peugeout 306 An Object is a model of the Real World and has States (Or Properties) and Behaviours (Or Actions) Example Object Car States are Color, Speed, Size, Plate Licence No, Cost Behaviours are Start, Stop, Accelerate, Fuel, Open Door, etc.
  13. 13. Creating a ClassUse the class KeywordExamplepublic class HelloWorld { . . . }Do NOT Forget!Name your java file ClassName.java
  14. 14. 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
  15. 15. 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!
  16. 16. Using Our Class PaySlipWe 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()); }}
  17. 17. 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)
  18. 18. Constructorspublic 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; }}
  19. 19. Sorry...• Confused?• Questions?
  20. 20. Lesson 02:Java 2 Micro Edition(J2ME)
  21. 21. 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
  22. 22. Anatomy of MIDP Apps
  23. 23. 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
  24. 24. The MIDlet Life Cycle
  25. 25. 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) { }}
  26. 26. Remember the Constructor?package com.thinkit2ru;import javax.microedition.midlet.*;public class Metric extends MIDlet { public Metric() { The Contructor: } Build Components Here public void startApp() { } public void pauseApp() { } public void destroyApp(boolean unconditional) { }}
  27. 27. You need to Know...• Primitive data types• String Manipulation• Control Statements• Arrays and other data structures• GUI Design• Database Connectivity• Multithreading• Ethics and Conventions
  28. 28. Questions Please...
  29. 29. System.out.println(“Thank You”);

×