Java Quick Start Lecture 1: Introduction to Java and Hello World Program, Study notes of Mobile Computing

The first lecture of a java programming course offered at the university of greenwich. It covers the basics of java, including its benefits, different editions, and the concept of bytecode. The lecture also includes a simple 'hello world' program and an explanation of packages, imports, and defining classes in java.

Typology: Study notes

2010/2011

Uploaded on 09/08/2011

rossi46
rossi46 🇬🇧

4.5

(10)

313 documents

1 / 19

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture 1
Java Quick Start – Part 1
Stelios Kapetanakis & Markus A. Wolf
Based on material from Gill Windall
1
Application Development
for Mobile Devices
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download Java Quick Start Lecture 1: Introduction to Java and Hello World Program and more Study notes Mobile Computing in PDF only on Docsity!

Lecture 1

Java Quick Start – Part 1

Stelios Kapetanakis & Markus A. Wolf

Based on material from Gill Windall

1 Application Development for Mobile Devices

Java's big benefit - Write Once, Run Anywhere Physical Machine Java Platform Java source code Myprog.java Java bytecode Myprog.class compile using Java compiler Java source code is compiled to Java bytecode Java bytecode can be executed by a Java interpreter on any machine with an implementation of the Java Platform

Java Standard Edition versions Java 1.0 - 1995 Java 1.1 - 1997 Java 1.2 - 1998 Java 1.3 - 2000 Java 1.4 - 2002 still widely used basis of the Java used in Java ME what we're covering here Java 5.0 - 2004 powerful new features not implemented for mobile devices Java 6.0 – 2006 smaller change than version 5

Java API documentation packages classes in selected package details of the selected class

Hello World application /*

  • HelloWorld.java */ package jqs; import java.util.Date; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world"); Date now = new Date(); // get the system date System.out.println("The date and time are: " + now.toString()); } }

Comments // to end of line /* */ - everything between

*** HelloWorld.java /* package jqs; import java.util.Date; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world"); Date now = new Date(); // get the system date System.out.println("The date and time are: " + now.toString()); } }

import

  • HelloWorld.java */ package jqs; import java.util.Date; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world"); Date now = new Date(); // get the system date System.out.println("The date and time are: " + now.toString()); } }
  • (^) import makes a package or a class available to the program classes from the Java API (i.e. the standard Java library)
  • (^) java.util is a "package" name and Date is a class name

defining classes in Java

  • (^) All procedural code in Java lives in a class
  • (^) Most non-trivial programs consist of many classes
  • (^) Note how the {}s act as a begin and end for the class
  • HelloWorld.java */ package jqs; import java.util.Date; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world"); Date now = new Date(); // get the system date System.out.println("The date and time are: " + now.toString()); } }

System.out.println()

  • (^) Normal way to produce output to the standard output stream for a Java application
  • (^) System is a class that is part of the Java API
  • HelloWorld.java */ package jqs; import java.util.Date; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world"); Date now = new Date(); // get the system date System.out.println("The date and time are: " + now.toString()); } }

declaring a variable

  • (^) "now" is the name the programmer has given to a variable being declared to be of type Date
  • (^) Java (unlike JavaScript) is strongly typed which means all variables must have a type
  • HelloWorld.java */ package jqs; import java.util.Date; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world"); Date now = new Date(); // get the system date System.out.println("The date and time are: " + now.toString()); } }

calling a method

  • (^) toString() is a method of class Date
  • (^) A method is like a function or procedure that belongs to an object
  • (^) now.toString() is calling the method toString() on the object now
  • HelloWorld.java */ package jqs; import java.util.Date; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world"); Date now = new Date(); // get the system date System.out.println("The date and time are: " + now.toString() ); } } :Date wed jan 5th

Sources of Further information The Java tutorial on the Sun website http://java.sun.com/docs/books/tutorial/ Java API documentation http://java.sun.com/j2se/1.4.2/docs/api/index.html

The End