Вы находитесь на странице: 1из 15

9/10/2013

Introduction
Norsaremah Salleh, PhD.

Introduction to Java Program development

9/10/2013

Java is an object-oriented programming language. Developed in the early 1990s by James Gosling at Sun Microsystems. Later, the company was bought by Oracle in Jan. 2010 Initially started as a programming language for embedded devices, now being used to develop almost every kind of apps. Java platforms: Java Standard Edition (SE), Java Enterprise Edition (EE), Java Micro Edition (ME), and Java Card Technology. Each platform provides Java standard class library that support graphics, database connection, and other features.
3

JDK 1.0 (1996): 212 classes, 8 packages JDK 1.1 (1997): 504 classes, 23 packages J2SE 1.2 (1998) known as Java 2: 1520 classes and 59 packages. Introduces Swing, 2D API J2SE 1.3(2000) known as Java 2, Release 1.3, 1840 classes, 76 packages J2SE 1.4 (2002): 2991 classes in 135 packages J2SE 5.0 (2004): 3562 classes in 166 packages Java SE 6 (2006) Java SE 7 (2011): Java Platform, Standard Edition 7

9/10/2013

Java is a general purpose programming language. Java is the Internet programming language. Java enables users to develop and deploy applications on the Internet for servers, desktop computers, and small hand-held devices.

Object-oriented Java is an object-oriented programming (OOP) language because it main goals are to create objects that can interact with other objects to solve a problem It differs from procedural programming that stresses on sequence of coding steps
6

9/10/2013

Class name

Method name Method parameters

public class MyName{

public static void main(String[] args){


Program comment

//display my name System.out.println("My name is Harun."); } }


String argument Method call System output object
7

The main method is a special method that the JVM recognizes as the starting point for every Java program Syntax: public static void main (String args[]) public and static are the two required modifiers It does not return any values, so use void It accepts zero or more objects of type String. This allows you to type in values on the command line to be used in the program

9/10/2013

Comments Package Reserved words Modifiers Statements Blocks Classes Methods The main method These terms will be explored in detail throughout the course A Java application always contains a method called main

Comments in a program are called inline documentation They should be included to explain the purpose of the program and describe processing steps They do not affect how a program works Java comments can take three forms
// this comment runs to the end of the line /* this comment runs to the terminating symbol, even across line breaks */
10

*/

/** this is a javadoc comment

9/10/2013

Identifiers are the words a programmer uses in a program


can be made up of letters, digits, the underscore character ( _ ), and the dollar sign ($) cannot begin with a digit

Java is case sensitive - Total, total, and TOTAL are different identifiers Use a meaningful identifier. By convention, programmers use different case styles for different types of identifiers, such as
title case for class names - Lincoln upper case for constants - MAXIMUM
11

Spaces, blank lines, and tabs are called white space. White space is used to separate words and symbols in a program. Extra white space is ignored. A valid Java program can be formatted many ways. Programs should be formatted to enhance readability, using consistent indentation.
12

9/10/2013

abstract assert boolean break byte case catch char class *const continue default do double

else enum extends false final finally float for *goto if implements import instanceof int

interface long native new null package private protected public return short static strictfp super

switch synchronized this throw throws transient true try void volatile while

13

//********************************************************* // Lincoln2.java Java Foundations // // Demonstrates a poorly formatted, though valid, program. //********************************************************* public class Lincoln2{public static void main(String[]args){ System.out.println("A quote by Abraham Lincoln:"); System.out.println("Whatever you are, be a good one.");}}

14

9/10/2013

The mechanics of developing a program include several activities


writing the program in a specific programming language (such as Java) translating the program into a form that the computer can execute investigating and fixing various types of errors that can occur

15

There are four programming language levels


machine language assembly language high-level language fourth-generation language

Each type of CPU has its own specific machine language The other levels were created to make it easier for a human being to read and write programs

16

9/10/2013

Each type of CPU executes only a particular machine language A program must be translated into machine language before it can be executed A compiler is a software tool which translates source code into a specific target language Often, that target language is the machine language for a particular CPU type The Java approach is somewhat different

17

18

9/10/2013

The Java compiler translates Java source code into a special representation called bytecode Java bytecode is not the machine language for any traditional CPU Another software tool, called an interpreter, translates bytecode into machine language and executes it Therefore the Java compiler is not tied to any particular machine Java is considered to be architecture-neutral

19

Edit, Compile, Load, Execute


The sequence below illustrates the process in the context of the Java programming language

notepad Sample.java

java Sample javac Sample.java


20

10

9/10/2013

Source code
Stored in a file with .java extension Usually placed in a folder that holds all of the files related to one program (e.g. /src)

Class file
Java class file is produced by Java compiler (.class file) If a source file has more than one class, each class is compiled into a separate class file.

21

Small

Generate typically small executable code, require less memory for its runtime Some complexities have been removed to make the language simpler (e.g. pointers) Code consists of fully encapsulated classes Compiling & running java program involves both compilation & interpretation processes. Java interpreter converts each bytecode instruction into the machine language code.

Simple

Object-Oriented

Compiled and Interpreted

www.cs.armstrong.edu/liang/intro6e/JavaCharacteristics.pdf
22

11

9/10/2013

Platform Independent

Java bytecode is portable across different JVMs and thus across different platforms that supports the JVM. JVM recognizes intentional and unintentional errors before the code is executed, doesnt have direct access to the operating system resources.
Java provides simpler semantics in creating threads. Management of shared resources is made simpler.

Robust and Secure

Multithreaded

Editor
Any text editor will suffice (notepad++, TextPad, drJava) A Java-aware editor will provide formatting and shortcuts, and suggestions appropriate to the language (jEdit) An integrated development environment (IDE) will automatically connect the editor with project management and compilation, execution, and debugging tools (jGRASP, Eclipse, Netbeans, Ant etc)

24

12

9/10/2013

Compiler
Oracle provides free and commercial compilers
Java J2SE (Java 2 Platform, standard edition)

Other vendors bundle compilers with their IDE


Eclipse Netbeans Borland JBuilder Symantec VisualCafe IBM WebSphere Studio Metrowerks CodeWarrior

25

Java Virtual Machine (JVM)


JVM is a virtual machine that can execute java bytecode included with Java Software Development Kit JDK Over 5.5 billion devices nowadays are JVM-enabled devices.

Java Runtime Environment (JRE)


A JVM is distributed along with Java Class Library, a set of standard class libraries that implement the Java application programming interface (API). Java APIs, bundled together with the JVM, form the Java Runtime Environment (JRE).

26

13

9/10/2013

Get your JDK 7 & install Get your editor (drJava or Eclipse) & install Configure your editor Test your editor by writing a simple Java program, compile & run it.

27

To download JDK http://www.oracle.com/technetwork/java/javase/d ownloads/java-se-jdk-7-download-432154.html Notepad++ http://notepad-plus-plus.org/download/v5.9.8.html TextPad http://www.textpad.com/download/index.html Eclipse


http://www.eclipse.org/downloads/download.php?file=/t echnology/epp/downloads/release/indigo/R/eclipsemodeling-indigo-win32-x86_64.zip
28

14

9/10/2013

Write a simple Java program to display a welcoming text on a console. Rewrite the program to display the message using a dialog box. (Hint: use JOptionPane class from javax.swing package)

29

15

Вам также может понравиться