Presentation is loading. Please wait.

Presentation is loading. Please wait.

BA22001 Introduction to Java Instructor: Jingwu He.

Similar presentations


Presentation on theme: "BA22001 Introduction to Java Instructor: Jingwu He."— Presentation transcript:

1 BA22001 Introduction to Java Instructor: Jingwu He

2 BA22002 History of Java In 1991, Sun started development of a programming language that should be used for programming of consumer electronics, e.g. Mobile telephones, remote console,... The language was originally named Oak by James Gosling, the creator of the language. The market was not ready for this language and the project goal was changed: the language should be for the web. The browser HotJava was launched in 1995. The browser was written in Java and could execute applets (code running inside web-pages) Also in 1995 Netscape decided to make their webbrowser Java enabled.

3 BA22003 More History The first versions of the language (e.g. Java 1.02 released 1996) was not ready for industry use, they were to immature (e.g. when it comes to making user interface). In December 1996 a much more mature version Java 1.1 was release. (some browser has build in support for JDK 1.1.6 and not later versions).

4 BA22004 è Full application programming language è Additional capability as a Web programming language è OO programming language è Adopts its looks from C++ è Compiled to processor-neutral instruction set then interpreted on each supporting platform è Extremely fast adoption rate! What is Java

5 BA22005 Terminology è Package A grouping of logically related code (classes). For instance, all user-interface code is in a single package; likewise, all input/output code and all network code. è Class A collection of data and methods that operate on that data. è Method A group of statements in a class that handle a task. è Bytecodes A set of instructions that look like machine code, but are not specific to any processor. è Virtual Machine The environment in which Java runs. The JVM is responsible for executing the bytecodes and has responsibility for the fundamental capabilities of Java.

6 BA22006 Any Operating System JAVA Application (Bytecodes) JAVA Virtual Machine Any Hardware Platform Java Architecture

7 BA22007 Platform Independence Java source Java compile Java bytecode -HelloWorld.class -Platform Neutral Java source compiled into intermediary bytecode n Application runs anywhere Java VM is ported n Applet runs in any Java enabled browser test suite class HelloWorld { public static void Main (String args[]){ System.out.println("Hello World"); } javac HelloWorld.java

8 BA22008 Java Program Patterns Applications –Java programs which run stand alone Web-based Java Applications –Applets Dynamic and interactive programs that can run inside a web page displayed by a browser enabled for Java –Servlets Programs that run inside request/response oriented servers –JavaServer Pages An extension to the servlet architecture. Allow for the separation of the display of web content and the generation of that content

9 BA22009 Java 2 Platform Editions J2MEJ2EEJ2SE

10 BA220010 Java 2 Platform Editions –Java 2 Platform, Micro Edition (J2ME) Highly optimized runtime environment Targets consumer products –Pagers, cell phones –Java 2 Platform, Standard Edition (J2SE) Java 2 tools, runtimes, and APIs for developers writing, deploying, and running applets and applications Referred to as Java 2 SDK –Java 2 Platform, Enterprise Edition (J2EE) Targets enterprise-class server-side applications.

11 BA220011 Object Oriented Programming Conceptualizing a computer program as a set of separate objects that interact with each other. Objects can model real life situations –BankAccount object –Bicycle Objects contain information and the means of accessing and changing that information. Benefits –Reusability –Reliability

12 BA220012 Class A template for creating objects l A class is a blueprint, or prototype, that defines the variables and the methods common to all objects of a certain kind

13 BA220013 Working with Objects method data message anObject data encapsulation

14 BA220014 Bank Account Class name address balance interestRate ytdInterest deposit withdraw changeAddress attributes (variables) methods

15 BA220015 Instance of a class (object) name address balance interestRate ytdInterest deposit withdraw changeAddress class name address balance interestRate ytdInterest deposit withdraw changeAddress Instance of a class (object) John Smith 1234 Main St 1000.03 15.25 new

16 BA220016 Many instances of a class (objects) name address balance interestRate ytdInterest deposit withdraw changeAddress Instance of a class (object) John Smith 1234 Main St 1000.03 15.25 name address balance interestRate ytdInterest deposit withdraw changeAddress Mary Smith 2115 Pine St 7500.04 215.25 Instance of a class (object)

17 BA220017 Messages trigger methods name address balance interestRate ytdInterest deposit withdraw changeAddress Mary Smith 2115 Pine St 7500.04 215.25 Instance of a class

18 BA220018 Bicycles

19 BA220019 Bicycle Class color currentGear currentSpeed currentCadence numberOfGears brake changeGear changeCadence attributes (variables) methods

20 BA220020 An instance of a class (object)

21 BA220021 Many instances (objects)

22 BA220022 Messages

23 BA220023 How does in work in Java? Class contains: –Variables To hold values –Methods To execute logic

24 BA220024 Java Program naming conventions Classes –Start with upper case alphabetic –Must be stored in a file with the same name and a.java extension –Use meaningful names –Examples BankAccount – good Bike - good 113BankAccount – invalid bankAccount – works, but may get a warning Stuff - works, but not meaningful

25 BA220025 Java Program naming conventions methods –Start with lower case alphabetic –Use meaningful names –Capitalize words –Examples calculateInterest – good changeSpeed - good 123Calculate – invalid CalculateInterest – works, but may get a warning stuff - works, but not meaningful

26 BA220026 Java Program naming conventions variables –Start with lower case alphabetic, _ or $ –Use meaningful names –Capitalize words –Examples int areaCode – good int currentSpeed - good boolean 123 – invalid float CalculatedInterest – works, but doesn’t follow convention int stuff - works, but not meaningful

27 BA220027 class MyClass { class variables myMethod1() { method variables statement 1; statement 2; } myMethod2() { method variables statement 1; statement 2; } Java Program structure scope

28 BA220028 class BankAccount { String name; String address; float balance; float interestRate; changeAddress() { method variables statement 1; statement 2; } withdraw() { method variables statement 1; statement 2; } deposit() { method variables statement 1; statement 2; } Java Program structure BankAccount myAccount = new BankAccount();

29 BA220029 class Bike { int currentSpeed; int currentCadence; int numberOfGears; int currentGear; changeGears() { method variables statement 1; statement 2; } changeSpeed() { method variables statement 1; statement 2; } brake() { method variables statement 1; statement 2; } Java Program structure

30 BA220030 Creating Objects new operator –Creates an instance of class (object) Bike myBike = new Bike() –Allocates memory Deallocating objects –Done by Java garbage collection

31 BA220031 Working with Objects changeSpeed status speed myBike

32 BA220032 Java Programming H SDK H Java Software Development Toolkit H Available from Sun Microsystems, Inc. H SDK 1.4 is the current version H Also version 5.0 RC (Released Code) H Known as JDK in early versions H Development environments (IDE) H IBM - WebSphere Studio Application Developer H Sun - Forte H Microsoft - Visual J++ H Borland - JBuilder H Oracle - JDeveloper H And others

33 BA220033 Java Translation Enter/edit the Java program Save Source Compiler Java Bytecode Success Fail Correct errors.java file Java Java Bytecode Interpreter Machine Language Instructions CPU Execution of Machine Language Instructions Data for the Program Program Output.class file JVM Syntax errors Logic errors


Download ppt "BA22001 Introduction to Java Instructor: Jingwu He."

Similar presentations


Ads by Google