Java Programming Transparency No. 1-1 Introduction to Java Programming Cheng-Chia Chen Feburary 2013.

Slides:



Advertisements
Similar presentations
1 Copyright © 2005, Oracle. All rights reserved. Introducing the Java and Oracle Platforms.
Advertisements

L1:CSC © Dr. Basheer M. Nasef Lecture #1 By Dr. Basheer M. Nasef.
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
The Java Language. Topics of this Course  Introduction to Java  The Java Language  Object Oriented Programming in Java  Exceptions Handling  Threads.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Introduction to Java The objectives of this chapter are: To describe the key aspects of Java To describe the Java software development kit (SDK) To explain.
Object Orientated Programming
Java Programming Transparency No. 1-1 Introduction to Java Programming Cheng-Chia Chen September 2003.
Introduction to Java Kiyeol Ryu Java Programming Language.
Java Programming Transparency No. 1-1 Introduction to Java Programming Cheng-Chia Chen Feburary 2007.
Introduction to Java Programming, 4E
Java Programming Transparency No. 1-1 Introduction to Java Programming Cheng-Chia Chen Feburary 2006.
For more Lectures and Notes Visit
Introduction to Java.
Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code Verifier? JIT & JAVA API Features of Java Java Environment.
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.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
L EC. 01: J AVA FUNDAMENTALS Fall Java Programming.
01 Introduction to Java Technology. 2 Contents History of Java What is Java? Java Platforms Java Virtual Machine (JVM) Java Development Kit (JDK) Benefits.
Java program.
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.
JAVA v.s. C++ Programming Language Comparison By LI LU SAMMY CHU By LI LU SAMMY CHU.
BASIC JAVA PROGRAMMING TUTORIAL. History  James Gosling and Sun Microsystems  Oak  Java, May 20, 1995, Sun World  Hot Java –The first Java-enabled.
CSCI 224 Introduction to Java Programming. Course Objectives  Learn the Java programming language: Syntax, Idioms Patterns, Styles  Become comfortable.
Lecturer PEN PHIROM Tel : Web site: Lecturer PEN PHIROM Tel :
About the Java  Java technology is both a programming language and a platform –The Java Programming Language A high-level language that can be characterized.
Programming Fundamentals 2: Background/ F II Objectives – –give a non-technical overview of Java Semester 2, Background.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Programming Languages Machine.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Programs,
Java Introduction Lecture 1. Java Powerful, object-oriented language Free SDK and many resources at
1.  At the end of this slide, student can:  Explore tools, features, properties and interface of the Textpad.  Creating a new project.  Open and run.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
University of Houston-Clear Lake Proprietary© 1997 Evolution of Programming Languages Basic cycle of improvement –Experience software difficulties –Theory.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Programs.
POS 406 Java Technology And Beginning Java Code
Introduction to Java Programming with Forte Y. Daniel Liang.
What Is Java? According to Sun in a white paper: Java: A simple, object-oriented, network-savvy, interpreted, robust, secure, architecture-neutral, portable,
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
We will talking about story of JAVA language. By Kristsada Songpartom.
JAVA Programming “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
1. An Introduction A Programming Language A Technology Java Development Kit Java API One Language: Three Editions Standard Edition Enterprise Edition.
Java Programming Transparency No. 1-1 Introduction to Java Programming Cheng-Chia Chen September 2001.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
1 Introduction to Java. 2 * 10% Assignments/ class participation * 10% Pop Quizzes * 05% Attendance * 25% Mid Term * 50% Final Term.
การเขียนโปรแกรมภาษา จาวา Java Programming อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 1.
ITP 109 Week 2 Trina Gregory Introduction to Java.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction.
Introduction to JAVA Programming
Java Programming Transparency No. 1-1 Introduction to Java Programming Cheng-Chia Chen Feburary 2011.
Introduction to Java Programming, 4E Y. Daniel Liang.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Fundamental of Java Programming (630002) Unit – 1 Introduction to Java.
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
Introduction to Java Programming
Chapter 1 Introduction to Computers, Programs, and Java
Chapter No. : 1 Introduction to Java.
Java programming lecture one
Introduction Enosis Learning.
Introduction Enosis Learning.
Chapter 1 Introduction to Computers, Programs, and Java
(Computer fundamental Lab)
Java History, Editions, Version Features
Introducing Java.
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 Programming Transparency No. 1-1 Introduction to Java Programming Cheng-Chia Chen Feburary 2013

Java Programming Transparency No. 1-2 Course web page

Java Programming Transparency No. 1-3 Lecture 1. Introduction Cheng-Chia Chen

Java Programming Transparency No. 1-4 Contents 1.What is Java? 2.Features of Java 3.Evolution of Java 4.Develop first Java program 5.Structure of java code

Java Programming Transparency No. 1-5 What is Java? Java is  a programming language, defined in The Java language specification (v1,v2,v3, se7)The Java language specificationse7  a virtual machine, Defined in The java virtual machine (v1, v2, se7)The java virtual machine se7 Many languages Many languages can be compiled into JVM code. Java code can also be compiled into non-jvm code:  Android: java  Dalvik VMDalvik  a platform Standard edition (j2se 7.0  java se 7): Java platform, standard edition 7standard edition Enterprise edition(j2ee 5.0  java ee 5): Java platform, enterprise edition 6 (for enterprise-class service-oriented architecture (SOA) and web applications.)enterprise edition web Micro edition (j2me  java me): Java Platform, Micro edition Micro edition (for mobile&embeded devices)

Java Programming Transparency No. 1-6 Java 2 Platform editions and their target markets servers & enterprise computers Desktop & personal computers High-end consumer devices Low-end devices smartcards J2ME

Java Programming Transparency No. 1-7

Java Programming Transparency No. 1-8  Java SE 7 Platform at a Glance Java SE 7 Platform at a Glance  Java SE 6 Platform at a Glance Java SE 6 Platform at a Glance

Java Programming Transparency No. 1-9 Features of the java language: Java is  simple  object-oriented  distributed  interpreted  robust  secure  architecture-neutral  portable  high performance  multithreaded  dynamic reference

Java Programming Transparency No Java is Simple  Intentionally created to be syntactically similar to C/C++  Eliminate traditionally troublesome features of C/C++ Pointer arithmetic (no troublesome * and &) Multiple inheritance Implicit type coercions // if (1) {x = 1 ;} is not well-formed Explicit memory management Preprocessor  Eliminate features of C/C++ struct, typedef,union generic, enum ( both recovered since jdk5.0 ) (Programmer controlled) operator overloading (but preserving method overloading)  Features included as part of base language: Threads Exception handling reflection

Java Programming Transparency No Java is Object-oriented  Java is inherently object-oriented. Although many object-oriented languages began strictly as procedural languages, Java was designed from the start to be object-oriented.  Object-oriented programming (OOP) is a popular programming approach that is replacing traditional procedural programming techniques.  One of the central issues in software development is how to reuse code. Object-oriented programming provides great flexibility, modularity, clarity, and reusability through encapsulation( 封裝 ), inheritance( 繼承 ), and polymorphism( 多型 ).

Java Programming Transparency No What is object-oriented ?  Systems are built from sets of classes  Classes are instantiated at runtime to give objects  Objects communicate via messages passing (i.e., method or funcition invocation)  (In java) everything is part of a class  Supported OO Concepts: Data abstraction and Encapsulation Inheritance Polymorphism  dynamic binding - overriding  overloading  generics  Logical cluster of classes == package Non-OO features

Java Programming Transparency No Java is a Distributed language  Distributed computing involves several computers working together on a network.  Java is designed to make distributed computing easy.  Since networking capability is inherently integrated into Java, writing network programs is like sending and receiving data to and from a file.  Network programming support built into JDK class library: TCP sockets,UDP packets,IP addresses URLs,RMI (Remote Method Invocation) Web Service  Security features designed into language

Java Programming Transparency No Java is an Interpreted language  Language implementation Compiler – produce machine code Ex: Fortran, Cobol, C, C++ Interpreter – execute source or compiled instructions on a virtual machine Ex: Scheme, Haskell, Python., Java Hybrid compilation/interpretation : Java The Java Virtual Machine (JVM) java code  compile byte code (machine independent) [  just-in-time compilation native code ]  execution  We need an interpreter(JVM) to run Java programs. The bytecode is machine-independent and can be executed on any machine that has a Java interpreter, which is the Java Virtual Machine (JVM).

Java Programming Transparency No Java is Robust  characteristics of Java Strongly-typed language (cf Smalltalk and VisualBasic) Compile-time and runtime checking No pointer arithmetic Exception handling Automatic memory management  Java compilers can detect many problems that would first show up at execution time in other languages.  Java eliminated certain types of error-prone programming constructs found in other languages.  Runtime exception-handling feature provides programming support for robustness.

Java Programming Transparency No Java is secure  Designed with security in mind. Java implements several security mechanisms to protect your system against harm caused by stray programs. Allow users to download untrusted code over a network and run it in a secure environment in which it cannot do any harm.  Configurable security levels and restrictions.  subjected to intense scrutiny by security experts with [potentially serious ] bugs found and fixed. become a big news if new bugs found!! A recent security flawA recent security flaw(2012/08) (0-day flaw)2012/080-day flaw Should update (from 7~10) to se 7 update (11-15) now.  One of the best mainstream platforms with the strongest security guarantee.

Java Programming Transparency No Java is Architecture-neutral  Byte-codes are architecture neutral Write once, run anywhere With a Java Virtual Machine (JVM), you can write one program that will run on any platform.  Performance suffers somewhat by using bytecodes

Java Programming Transparency No Java is portable (source code level)  Source code : Primitive type sizes are explicit - not architecture dependent Strings and characters are (16-bit) Unicode compliant  easier for internationalization.  Byte code: run everywhere where a JVM is available  User experience : GUI libraries give a native graphic library-independent mechanism for creating quality graphical interfaces (sort of) "They gave us a library that is good for writing programs that look equally mediocre on the different systems." (Core Java, page 9)

Java Programming Transparency No High performance  Interpreting leads to quicker development cycle  Depends what you compare it to "Slightly faster than VB" - (Core Java, page 9) JITC(Just-In-Time Compiler) help greatly in this respect Sun’s Java HotSpot is Newest high performace JIT compiler.  Can use native code for mission-critical performance sections of code JNI: Java Native Interface Sacrifice portability.

Java Programming Transparency No Multithreaded  Based on well-known 20 year old Hoare monitor synchronization  Thread support built into language  Thread synchronization primitives supplied  Garbage collector runs permanently as a low priority background thread  Issue: Still hard to use right for general programmers: New package java.util.concurrency and other extensions added since jdk5 allow easier and correct use of threads.

Java Programming Transparency No Dynamic  Class linking, layout, name resolution and object references not resolved until run-time  Runtime Type Information (RTTI) available Can check the type of objects at run-time java.reflect.* package  Class class for dynamic instantiation Can create objects of types unkown until runtime. String name = getSpecies(); // get a name of a class Object p = Class.forName(name).newInstance(); If(p instanceof Hen) {…} else if(p instanceof Coq) { …} else {… }

Java Programming Transparency No An Example /** * The HelloJava class implements an application that * simply displays "Hello Java!" to the standard output. */ class HelloJava { public static void main(String[] args) { // Display "Hello Java!" System.out.println("Hello Java!"); }

Java Programming Transparency No Early history of Java  Green Project (1990) need a small PL for developing consumer device operating software Requirements: small size, robust, portable, extremely reliable,real- time performance  Oak // the resulting language Originally used C++, then realized a new language was needed Original requirements same as for current language  Java (1993) // OAK was renamed Java Intended market never eventuated (no technology/product sold) WWW starting to takeoff Language design "based on" many current OO languages (e.g., C++, Eiffel, Smalltalk, Cedar/Mesa, Objective C) 1995/5/23 Sun launched Java JDK 1.0 released early 1996/1/23 ( 211 classes / 8 pkgs)  Early History Website :

Java Programming Transparency No Evolution of the Java Language 2002 (8 packages) (23 packages) (59 packages) (76 packages) (135 packages) (166 packages) (202 packages) /7 featureChangefeatureChange Jan, 2010: sun and java were owned by oracle. java 2 Java version History

Java Programming Transparency No Develop your first Java Program 1. Required software 2. Creating Your First Application a. Create a Java Source File b. Compile the Source File c. Run the Program

Java Programming Transparency No Required Softwares To write your first program, you will need: 1. The Java Platform, Standard Edition. 2. A text editor. Ex:  NotePad,  Ultraedit,  EditPlus2

Java Programming Transparency No Creating Your First Application  The first program, HelloWorldApp, will simply display : “Hello World!".  Steps: a. Create a Java source file. > Notepad HelloWorldApp.java b. Compile the source file into a bytecode file. > javac HelloWorldApp.java c. Run the program contained in the bytecode file. >java HelloWorldApp

Java Programming Transparency No HelloJava.java /** * The HelloWorldApp class implements an application that * simply displays "Hello World!" to the standard output. */ class HelloWorldApp { public static void main(String[] args) { // Display "Hello World!" System.out.println("Hello World!"); }

Java Programming Transparency No. 1-29

Java Programming Transparency No. 1-30

Java Programming Transparency No Java Jargon

Java Programming Transparency No Java 2 SDK Installation Instructions (for WIN32) 1. Download java SDK standard edition 2. Run the Java SDK executable (*.exe). determine where to install java se. (ex: c:\java\jdk7) > set JAVA_HOME= c:\java\jdk7 3. Update the PATH variable so that you can type ‘java’ instead of ‘c:\java\jdk7\bin\java’ to invoke java tools. > path=%JAVA_HOME%\bin;%PATH% 4. Check the CLASSPATH variable Used by java tools to determine where to find your personal (nonsystem) java class files Types of java byte codes (class files):  System : java tools know where to find them.  Extensions: put in %JAVA_HOME%\jre\lib\ext  Personal: via CLASSPATH or –cp/–classpath options 5. Start using the Java SDK tools! java, javac, javadoc, jdb, javap,…

Java Programming Transparency No Create Your first Java application using Eclipse IDE  install Eclipse SDK Download Eclipse SDK (choose Classic)Eclipse SDK unzip to a dir (c://eclipse)  Start Eclipse go to c:\eclipse run eclipse.exe  choose Java perspective  create a java project ( helloWorld )  create a package chapter1 using package widard  create HelloWorld class using class wizard  run HelloWorld class  Reference: Eclipse Tutorial | One-Page Startup InstructionEclipse TutorialOne-Page Startup Instruction

Java Programming Transparency No How java code are structured ?  A java application consists of many packages Some from JRE (built-ins)+ some from 3 rd party + your own ]  A package consists of 0 or more classes 0 or more subpackages  A java source file xxx.java is called a compilation unit, which may contain multiple java class definitions and may be compiled into multiple java byte code (***.class ).

Java Programming Transparency No Package and class naming  A class or package has two names: simpleName fully qualified name = parentPackageName. simpleName packageName = parentPackageName. simpleName For package, we use only its full name.  Ex: java.lang.String javax.swing.JButton  The package/subpackage/(*.class, *.java) structure is not only logically analogous to directory/ subdirectory/ file in OS file system but in fact they are stored physically in file system in this way. Namely, if package p is located in a directory d then subpackage p.q of p would be stored in subdirecty q of d, and class p.A of p would be stored in file named A.class or A.java.

Java Programming Transparency No CLASSPATH: Where to find java class and source  How does java/javac find a class or src x.y.z.A in the package x.y.z ?  Notes: package x.y.z is a subpackage of x.y, which is a subpackage of x. we called package x, java, javax etc, top-level packages. java find the location of top-level packages from a list of directory(package roots) given by a system variable called CLASSPATH.  Ex: If CLASSPATH = d:\my\root;. Then  package x is mapped to dir d:\my\root\x or./x  package x.y is mapped to dir d:\my\root\x\y or./x/y  package x.y.z => d:\my\root\x\y\z or./x/y/z  class or src x.y.z.A => d:\my\root\x\y\z\A.class or d:\my\root\x\y\z\A.java or …