Java Introduction 密碼學與應用 海洋大學資訊工程系 丁培毅.

Slides:



Advertisements
Similar presentations
Basic Java Constructs and Data Types – Nuts and Bolts
Advertisements

Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Java Language Quick-Reference Guide B. Oracle10g: Java Programming B - 2 Console Output Java applications and applets can output simple messages to the.
COSC 2006 Data Structures I Instructor: S. Xu URL:
Java Programming 2 Dr. Priti Srinivas Sajja Introductory concepts of java programming as specified in PGDCA 203:Object Technology, S P University.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
A Brief Introduction to Java Programming the World Wide Web.
1 Introduction To Java Professor Yihjia Tsai Tamkang University.
Java Data Types  Everything is an Object  Except Primitive Data Types  For efficiency  Platform independent  Portable  “slow”  Objects are often.
Java Programming Review (Part I) Enterprise Systems Programming.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
CSC3170 Introduction to Database Systems
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Java 程序设计 Java Programming Fall, Contents for Today Java Program Structure  How to Compile a Java Program  How to Run a Java Program Environment.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
2000 Jordan Anastasiade. All rights reserved. 1 Class In this lesson you will be learning about: Class. Inheritance. Polymorphism. Nested and.
The Java Programming Language
Inheritance. Introduction Inheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications.
2: Everything is an Object You Manipulate Objects Using References Primitives Arrays in Java Scoping You Never Destroy Objects Creating New Data Types:
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Chapter 3 Object Oriented Programming in Java  Classes & Object  Bank Account Example  ADT  Inheritance  Overloading  Interfaces  Packages.
JAVA BASICS Prepared by The Smartpath Information Systems
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
Programming in Java CSCI-2220 Object Oriented Programming.
Inheritance (Part 5) Odds and ends 1. Static Methods and Inheritance  there is a significant difference between calling a static method and calling a.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Pengantar OOP Class-Java. 2 Software Development Tools Using Sun Java SDK alone Source File(s) (.java) Programmer Compiler (javac) Class File(s) (.class)
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
CMSC 341 Java Packages, Classes, Variables, Expressions, Flow Control, and Exceptions.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
1 The finalize, clone, and getClass Methods  The finalize method is invoked by the garbage collector on an object when the object becomes garbage.  The.
1 Chapter 5: Defining Classes. 2 Basics of Classes An object is a member of a class type What is a class? Fields & Methods Types of variables: –Instance:
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Chapter 3 Objects and Classes. Objects Object – a data type with structure, state, and operations to access and manipulate state - an instance of a class.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Duke CPS From C++ to Java l Java history: Oak, toaster-ovens, internet language, panacea l What it is ä O-O language, not a hybrid (cf. C++)
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Classes, Interfaces and Packages
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
 2005 Pearson Education, Inc. All rights reserved. 1 Classes and Objects: A Deeper Look.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
OOP Basics Classes & Methods (c) IDMS/SQL News
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Object Oriented Programming Lecture 2: BallWorld.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Modern Programming Tools And Techniques-I
Internet and Java Foundations, Programming and Practice
Overloading and Constructors
Interface.
Extending Classes.
Java Programming Language
The Building Blocks Classes: Java class library, over 1,800 classes:
Recitation 7 October 7, 2011.
Chapter 11 Inheritance and Polymorphism Part 1
Overloading Each method has a signature: its name together with the number and types of its parameters Methods Signatures String toString()
Presentation transcript:

Java Introduction 密碼學與應用 海洋大學資訊工程系 丁培毅

Download JDK http://www.oracle.com/technetwork/java/javase/downloads/index.html

Java Program Development IDEs Eclipse, http://www.eclipse.org/downloads/ Eclipse IDE for Java Developers, 151 MB Apache Ant, http://ant.apache.org/bindownload.cgi Apache Maven, http://maven.apache.org/docs/3.1.1/release-notes.html Or simply notepad++ and cmd.exe (javac and java) jdk7u40.bat or modify 系統內容/進階/環境變數 @echo off set path=%path%;c:\progra~1\java\jdk1.7.0_40\bin set classpath=.;c:\progra~1\Java\jdk1.7.0_40\src.zip @echo on

Java Programs Programs are built from classes Classes define data storages and behaviors of objects (class instances) data structure of an object defined by data members behavior of an object are defined by methods that manipulate the data members.

HelloWorld.java class HelloWorld { public static void main(String[] arg) { System.out.println("Hello World"); } Compiling: javac HelloWorld.java Executing: java HelloWorld

Factorial.java factorial(21) overflows a 64-bit integer (long) java.math.BigInteger supports arbitrarily long integers (java.math.BigDecimal supports arbitrarily long real numbers) import java.math.BigInteger; class BigFactorial { public static void main(String[] args) { BigInteger fact = new BigInteger("1"); for (int i=1; i<60; i++) { fact = fact.multiply(BigInteger.valueOf(i)); System.out.println(fact); }

Comments Three forms /* comment */ // comment to end of line /** documentation comment for javadoc tool */ all characters in Java programs are unicode (16 bit)

Constants examples static final int face = Suit.DIAMONDS; class Suit { static final int CLUBS = 1; static final int DIAMONDS = 2; static final int HEARTS = 3; static final int SPADES = 4; }

Control Flow & Operators control statements mostly cloned from C++ differences: boolean type requires operands of &&, || etc. to be boolean while(1) not OK…while(true) is fine + is string concatenation I/O is not like C++ arrays are not like C++

Classes and Objects Fields are data variables associated with a class or with instances of the class primitive data (int, double, …) object data ( BigInteger r ) Methods provide execution behavior and operate on the data fields Classes and Interfaces can be members of other Classes or Interfaces.

Interfaces Interfaces define the methods that may be used but do not specify instance storage. interface ConstAccount { double getBalance(); } class Account implements ConstAccount { double d_ = 0.0; void setBalance(double d) {d_ = d;} double getBalance() { return d_;}

Creating Objects Objects are primitive or user defined. Primitive objects are by value, user defined objects are references. User defined Objects are created with constructors and the “new” keyword. Point center = new Point(4.0,5.9);

Static fields static fields in a class or interface belong to the class. If there are instances of a class with static data fields then all instances share the static data fields static methods are invoked using the class name.

Garbage Collection When there are no active references to an object storage is automatically reclaimed by a garbage collector thread running in the background.

Methods and Parameters methods operate on the data fields of a class. methods have zero or more parameters and may return values or be void. a methods name, number of parameters and their type make up the signature of the method. two methods may share a name if they have different signatures.

Invoking a method a non-static method is invoked using an object of the class and the “dot” operator. Point p = new Point(3.2,3.3); p.clear(); the object on which the method is invoked is the “receiver”. The method is a “message” to the object.

“this” the keyword “this” refers to the current receiving object. public void clear() { this.x = 0.0; y = 0.0; // this is assumed }

Arrays An array is a collection of variables of the same type Card [] deck = new Card[52]; for (int i = 0; i < deck.length; i++) { deck[i] = . . .

Strings String objects are immutable objects. String myName = “W. H. Carlisle”; System.out.println( myName + “ III”); Use stringBuffer objects if you wish to manipulate the storage. there are methods that can be invoked on string objects. myName.length()

Inheritance Classes may extend other classes. variables of a subclass with the same name as those of a superclass shadow the superclass storage. a method of a subclass with the same signature as that of a superclass overrides the superclass method. objects of a subclass may be used in superclass variables.

Inheritance if a method is overridden, the keyword “super” refers to the superclass. Classes may extend only one class. If a class does not extend a class by default it extends the class Object. A class may implement many interfaces.

Exceptions The exception mechanism of Java is very similar to that of C++ try { } catch( Exception e) { } if a method throws a “checked” exception the compiler requires that a handler catch the exception or that the invoking method also indicates that it also throws the exception. a “finally” block may follow “catches” to close files, etc.

Packages packages are Java’s way to manage name spaces. Packages are implemented as directories within a file system. When package names must span systems, the common practice is to reverse the internet domain name import COM.Sun.games; import is not inclusion and is only for the compiler. Class paths are used to find the class information at run time.