Java Computer Industry Lab. 1 Programming Java Java Basics Incheon Paik.

Slides:



Advertisements
Similar presentations
A Programmer's Introduction to Java - from a S/370 user (c) IDMS/SQL News
Advertisements

Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
1 Fall 2008ACS-1903 Chapter 1 Topics Java History Java Programs Why Program? Computer Systems: Hardware and Software Programming Languages What Is a Program.
Principles of Object-Oriented Software Development The language Java.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
Slide 1 of 40. Lecture A The Java Programming Language Invented 1995 by James Gosling at Sun Microsystems. Based on previous languages: C, C++, Objective-C,
Chapter 2 - Java Programming Fundamentals1 Chapter 2 Java Programming Fundamentals.
Introduction to Java.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
01 Introduction to Java Technology. 2 Contents History of Java What is Java? Java Platforms Java Virtual Machine (JVM) Java Development Kit (JDK) Benefits.
CMSC 202 Computer Science II for Majors Fall 2009 Introduction.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps.
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
Introduction to Java Programming CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University.
Introduction to Java Programming CS 21a: Introduction to Computing I First Semester,
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction to Java Tavaris J. Thomas Ph.D. BNAI ZION SCIENTISTS DIVISION JOB ORIENTATION & TERMINOLOGY CLASSES Fall 2012.
CMSC 202 Computer Science II for Majors Object-Oriented Programming.
DAT602 Database Application Development Lecture 5 JAVA Review.
Java Lecture 16: Dolores Zage. WWW n Was a method for distributing passive information n added forms and image maps n interaction was only a new way to.
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
POS 406 Java Technology And Beginning Java Code
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
CS591x A very brief introduction to Java. Java Developed by Sun Microsystems was intended a language for embedded applications became a general purpose.
Java Programming Presented by Daniel Rosenthal Friday, November 30 th, 2007.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
JAVA PROGRAMMING BASICS CHAPTER 2. History of Java Begin with project Green in 1991 founded by Patrick Noughton, Mike Sheridan and James Gosling who worked.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
1 Programming Java Java Basics. 2 Java Program Java Application Program Application Program written in general programming language Applet Program running.
23-October-2002cse JavaIntro © 2002 University of Washington1 Intro to Java CSE 413, Autumn 2002 Programming Languages
Programming in java Lecture-2 Java Introduction. Platform Computing platform include hardware and software framework, this combination allows software.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and web applications Very rich GUI libraries Portability (machine independence) A real Object.
Java -- A very Hot Object- Oriented Language Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of.
Your name CSCI/CMPE 3326 Object-Oriented Programming in Java Dongchul Kim Department of Computer Science University of Texas – Pan American 1.Applet.
1 The JAVA Language Object Oriented Technology Mithani Binjan M.
introductory lecture on java programming
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Applet An applet is a Java program that runs in a Web browser. An applet can be.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Know Your Java. Java is special Java source code Byte code/ native code Object code on windows Object code on Dos Object code on Lynux.
WEEK 2 1 Software Concepts -- Introduction Now we can begin to examine the basic ideas behind writing programs Chapter 2 focuses on: history.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 15: Java Basics Fundamentals of Web Programming.
Features of JAVA PLATFORM INDEPENDENT LANGUAGE JAVA RUNTIME ENVIRONMENT (JRE) JAVA VIRTUAL MACHINE (JVM) JAVA APP BYTE CODE JAVA RUNTIME ENVIRONMENT.
Object Oriented Programming Lecture 2: BallWorld.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Introduction CMSC 202 Fall Instructors Mr. Ryan Bergeron – Lecture Section 01 Tues/Thu 1:00 – 2:15 am, Sondheim 111 – Lecture Section 04 Tues/Thu.
Object Oriented Programming in
Java™ 2 Platform Getting Started.
JAVA MULTIPLE CHOICE QUESTION.
Intro to ETEC Java.
Chapter No. : 1 Introduction to Java.
Introduction to.
Internet and Java Foundations, Programming and Practice
Principles of Computer Programming (using Java) Chapter 2, Part 1
(Computer fundamental Lab)
Chap 1. Getting Started Objectives
Chap 4. Programming Fundamentals
A Brief History January 1996: first official release JDK 1.0
Review of Java Fundamentals
Outcome of the Lecture Upon completion of this lecture you will be able to understand Fundamentals and Characteristics of Java Language Basic Terminology.
Presentation transcript:

Java Computer Industry Lab. 1 Programming Java Java Basics Incheon Paik

Java Computer Industry Lab. 2 Contents Contents Background The Java Virtual Machine Applications & Applets Classes & Objects The 3 Principles of Object Oriented Programming Start up Java Variables & Assignments Strings & Characters Arithmetic Operators & Expressions Type Conversion Comments Arrays Keywords

Java Computer Industry Lab. 3 Background / History Sun Microsystems Inc. James Gosling 1990, “Green Project” 1991, Develop the Language for Household Products => To General Developing Language Java James Gosling, Arthur Van Hoff, Andy Bechtolsheim Coffee Materials in Indonesia Write once, Run everywhere Spread Rapidly through WWW and Internet

Java Computer Industry Lab. 4 Byte Code and Java Virtual Machine Existing Development Environment Source Code Compiler(Pentium) Compiler(PowerPC) Compiler(SPARC) Binary File Pentium PowerPC SPARC Binary File Binary File %cc Hello.c –o Hello % Hello Binary Code Run

Java Computer Industry Lab. 5 Bytecodes and the Java Virtual Machine Java Development Environment Java Compiler (Pentium) Java Compiler (PowerPC) Java Compiler (SPARC) Java Interpreter Pentium PowerPC SPARC Java Interpreter Java Interpreter Java Code Java ByteCode (Independent on Platform) %javac Hello.java Hello.class created % java Hello Byte Code Run JVM

Java Computer Industry Lab. 6 Java Program Java Application Program Application Program written in general programming language Applet Program running in Web Browser Environment Can be viewed by appletviewer or Web browser with JVM

Java Computer Industry Lab. 7 Classes and Objects Object Memory Space to Define State and Operation Instance of Class Class Template of Creating Object

Java Computer Industry Lab. 8 The 3 Principles of Object Oriented Programming Encapsulation Control Access the data and method in program code Inheritance Inherit the data and methods of parent class Polymorphism Shape Ellipse Rectangle Triangle getArea() Shape Obj = new Ellipse(); Obj.getArea(); Which Area?

Java Computer Industry Lab. 9 The Java Class Libraries java.applet : Applet related java.awt : Abstract Window Toolkit java.awt.event : Event process from awt component java.awt.image : Image processing java.beans : JavaBeans Component java.io : File or Network I/O Support java.lang : Java Language Support java.net : Network related functions java.util : Utility function

Java Computer Industry Lab. 10 Java 2 SDK Java 2 Software Development Kit (Java 2 SDK) Java Application or Applet Development and Running Environment Java 2 Runtime Environment (JRE) Java Running Environment Java 2 Standard Edition Java 2 Micro Edition Java 2 Enterprise Edition

Java Computer Industry Lab. 11 Start a Java Application “Hello.java” class Hello { public static void main(String args[]) { System.out.println(“Hello World”); } % javac Hello.java % java Hello Compile Run “hello.c” void main() { printf(“Hello World\n”); } % cc hello.c – o hello % hello Hello World Result Java C Class Name Main method Main Function

Java Computer Industry Lab. 12 Variables and Assignments Variables Types char 16bits Unicode character data boolean Boolean Variable byte 8 bits signed integer short 16 bits signed integer int 32 bits signed integer long 64 bits signed integer float 32 bits signed floating point number double 64 bits signed floating point number

Java Computer Industry Lab. 13 Variables and Assignments int num = 100; long m = L double type : e e-5 float type : 1.5e-3f; Variable Declaration type varName; Value assignments varName = value; float x, y, x;

Java Computer Industry Lab. 14 Strings and Characters String : sequence of character String s = “Enter an integer value: ” ; Char c = ‘A’; Concatenation Operator ‘+’ String s = “Lincoln said: ” + “\” Four score and seven years ago\”” ; Result : Lincoln said: “Four score and seven years ago” Unicode

Java Computer Industry Lab. 15 Arithmetic Operators Operators + - * / % += -= *= /= %= / 2  2 Why isn’t it 2.5 ? 5 % 2  1 4 / 2  2 4 % 2  0 count * num + 88 / val – 19 % count j += 6;  j = j + 6;

Java Computer Industry Lab. 16 Type Conversions in Expression char ch; int i; float f; double outcome; ch = ‘0’; i = 10; f = 10.2f; outcome = ch * i / f; double float int float long int Yes No Yes No YesNo double

Java Computer Industry Lab. 17 Type Conversions in Assignment Widening Conversion byte b = 127; int i; i = b; Narrowing Conversion byte b; int i = 258; b = (byte) i; Wrong Conversion byte b; int i = 127; b = i; Right Conversion (But data may be lost) byte b; int i = 127; b = (byte) i; Type Casting

Java Computer Industry Lab. 18 Comments Single Line Comment int i = 10 ; // i is counter Multiple Line Comment /* Some comments */ Documentation Comment /** Documentation Comment */ Using “javadoc” Tool, make document

Java Computer Industry Lab. 19 Arrays ( One Dimensional) type VarName[] Definition of One Dimensional Array int ia[]; varName = new type[size] Assign Range to One Dimensional Array ia = new int[10]; type varName[] = new type[size] Declaration of One Dimensional Array with Range int ia[] = new int[10];

Java Computer Industry Lab. 20 Arrays ( One Dimensional) varName.length Number of elements in Array Type varName[] = {e0, …, en}; Initialization of One Dimensional Array int j[] = {0, 1, 2, 3, 4, 5}; int k[]; K = j; Example 1.15

Java Computer Industry Lab. 21 Arrays ( Multi-Dimensional) type VarName[][]; Definition of Two Dimensional Array float fa[][]; varName = new type[size1][size2]; Assign Range to Two Dimensional Array fa = new float[2][3]; type varName[][] = new type[size1][size2]; Declaration of Two Dimensional Array with Range float fa[] = new float[2][3];

Java Computer Industry Lab. 22 Arrays ( Two Dimensional) varName.length Number of elements in Multi-Dimensional Array Type varName[][] = {{e00, …, e0n}, {e10, …,e1y}, {e20, …, e2z}}; Initialization of Multi-Dimensional Array Example 1.16 varName[index].length Number of elements in Each elements of Multi-Dimensional Array Number of Raw

Java Computer Industry Lab. 23 Java Keywords 50 Java Keywords abstractdoubleintsuper booleanelseinterfaceswitch breakextendslong synchronized bytefinalnativethis casefinallynewthrow catchfloatpackagethrows charforprivatetransient* classgoto*protectedtry const*ifpublicvoid continueimplementsreturnvolatile defaultimportshortwhile doinstanceofstatic strictfp assert (New in 1.5) enum (New in 1.5) The “assert” is recognized as keyword in JDK1.4 compiler, but we could not use it. It can be used it from 1.5.

Java Computer Industry Lab. 24 Exercise Step 1 Refer to this lecture (slide #11) Step 2 (How to make & run Applet) (1) Make Applet Program import java.awt.Graphics; public class HelloWorldApplet extends java.applet.Applet { public void paint (Graphics g) { g.drawString(“Hello World!”,5,25); } } // end of Applet (2) Compile(using javac) to create HelloWorldApplet.class (3) Create HTML file (ex; HelloWorld.html) to include applet (4) Run Applet using Appletviewer or Applet enabling Web browser % appletviewer HelloWorld.html

Java Computer Industry Lab. 25 Exercise Step 3 (Type Conversion) Refer to this lecture (slides #16,17) Step 4 (Array) Refer to this lecture (slide #22)