java technicalities

59
. . . . . . Java Technicalities From a C/C++ Programmer’s View yen3 Dept. of Computer Science and Information Engineering, Chang Gung University April 15, 2009 Java Technicalities 1/58

Post on 18-Oct-2014

7.094 views

Category:

Technology


1 download

DESCRIPTION

淺談 Java 的技術層面。

TRANSCRIPT

Page 1: Java Technicalities

. . . . . .

Java TechnicalitiesFrom a C/C++ Programmer’s View

yen3

Dept. of Computer Science and Information Engineering, Chang Gung University

April 15, 2009

Java Technicalities 1/58

Page 2: Java Technicalities

. . . . . .

Introduction About

About AuthorI Computer Science StudentI Blog: No title, no thinking, no meaningI E-mail: yen3rc 在 gmail 答康I 隨手書寫生活

I C, C++, Java, Haskell, LATEX

Java Technicalities 2/58

Page 3: Java Technicalities

. . . . . .

Introduction Outline

IntroductionAboutIntroduction

TechnicalitiesTypeClass and ObjectGeneric in Java (igonred)Exception

Library and ProgrammingStringContainer and HashTableJava I/OJDBC — Java Database Connectivity

ConclusionConclusionReference

Java Technicalities 3/58

Page 4: Java Technicalities

. . . . . .

Introduction Outline

About SlideI 專題程式開發介紹相關簡報第二彈,陸續有其他介紹

I 感謝李春良老師專題指導,使得這一系列簡報得以誕生

I 感謝 Josh Ko (Joshsoft) 在主題與技術上的指導與協助(還有英文)XD

I The slide is made by X ELATEX and Beamer. XDI The Color Theme designed by Josh Ko uses Oxford brand colors1 .

1http://www.ox.ac.uk/staff/branding toolkit/the brand colours/index.htmlJava Technicalities 4/58

Page 5: Java Technicalities

. . . . . .

Introduction Outline

Something About Guang-Wu Chen’s Requirement

He hopes you understand the following topics.I String (all kinds of string/character processing stuff)I StringTokenizerI Hashtable (or other containers such as Vector, etc.)I JDBC related ones, including Connector, Statement, ResultSet.I I/O classes, of course.

Java Technicalities 5/58

Page 6: Java Technicalities

. . . . . .

Introduction Introduction

But ...I 想了很多天還是不知道自己要講什麼 XDI 亂講好了 XD

Josh Ko and yen3’s Talkingyen3: 要講 Java 耶, 我已經不知道要說什麼了...OrzJosh Ko: XDyen3: 不然我講怎麼用 Java 寫 Functional Programming 好了 XDJosh Ko: 不太好, Java 太 OO 了 XD

Java Technicalities 6/58

Page 7: Java Technicalities

. . . . . .

Introduction Introduction

But ...I 想了很多天還是不知道自己要講什麼 XDI 亂講好了 XD

Josh Ko and yen3’s Talkingyen3: 要講 Java 耶, 我已經不知道要說什麼了...OrzJosh Ko: XDyen3: 不然我講怎麼用 Java 寫 Functional Programming 好了 XDJosh Ko: 不太好, Java 太 OO 了 XD

Java Technicalities 6/58

Page 8: Java Technicalities

. . . . . .

Introduction Introduction

Everything is an Object.Thinking in Java 4/e

Java Technicalities 7/58

Page 9: Java Technicalities

. . . . . .

Introduction Introduction

Programming

By CompilerI Compiled Programming languageI Interpreted Programming language (Script Programming Language)

By MachineI Imperative Programming (Turing Machine)I Functional Programming (λ-calculus)

By ModelI Procedural ProgrammingI Object-Based Programming (Abstract Data Type)I Object-Oriented ProgrammingI Generic Programming

Java Technicalities 8/58

Page 10: Java Technicalities

. . . . . .

Introduction Introduction

TIOBE Programming Community Index for March 2009

Java Technicalities 9/58

Page 11: Java Technicalities

. . . . . .

Introduction Introduction

About JavaI James Gosling, 1995, Sun MicrosystemsI a pure Object-Oriented Programming LanguageI Everything is an object.I Java Virtual Machine and Just-In-Time Compiler XDI Java SE, Java EE, Java MEI The language has already been developed for over 10 years and

become a complete programming language.I So, What do we know from Java ?

Java Technicalities 10/58

Page 12: Java Technicalities

. . . . . .

Technicalities Type

Type

Java has two different types.I primitive type: int, char, double, balabalaI pointer type: class type(user-defined type)

We know that Java doesn’t have “pointers”I Java has “new”, but no “delete” keyword.I What is Garbage Collection?I What is Java’s memory management mechanism? (It’s an important

factor about Java’s program efficiency.)

Java Technicalities 11/58

Page 13: Java Technicalities

. . . . . .

Technicalities Type

String Type

I String has build-in type’s interface with pointer type’simplementation.

I String vs. StringBuffer2

I What does the language do in background?I Let’s talk about an example.

2In Java, StringBuilder provides an API compatible with StringBuffer, but with noguarantee of synchronization.

Java Technicalities 12/58

Page 14: Java Technicalities

. . . . . .

Technicalities Type

Type-Casting

I Java is strongly-typed programming language.I void* vs. java.lang.ObjectI In Java, every class inherits from java.lang.Object. It means we

can cast an object to java.lang.Object type and cast again toother arbitrary class type .

I Compiler doesn’t check the situation because it seems legal from thesyntactical perspective.

I You have to check the situation by yourself.

Java Technicalities 13/58

Page 15: Java Technicalities

. . . . . .

Technicalities Class and Object

Thinking about The Problems

I What is a “type”? A Type just like requirement.3 (in FunctionalProgramming)

I What is a “object”?I OO is claimed to be closer to human thoughts. However, is it true ?I Object vs java.lang.ObjectI Why doesn’t Java support “Operator Overloading”?

“Operator Overloading is syntax sugar. You don’t know how efficientyou cost in using.”

3Think about “Rules”Java Technicalities 14/58

Page 16: Java Technicalities

. . . . . .

Technicalities Class and Object

Class and Object

A Class has ...I data member (Data) – Record StatesI member function(Method)

A Class has three modesI public – interfaceI private – implementsI protected – for some reasons XD

We have to pay attention to two keywords, but the slide doesn’t mention.I staticI final

Java Technicalities 15/58

Page 17: Java Technicalities

. . . . . .

Technicalities Class and Object

ClassThere are several kinds of classes.

I Normal Class – There’s nothing to say. XDI Interface – Think about multiple-inheritance.I anonymous Class – Think about the relationship about function

pointer and call-back function.

Java Technicalities 16/58

Page 18: Java Technicalities

. . . . . .

Technicalities Class and Object

Back to C — Function PointerI Von Neumann’s Model says program can be saved in memory.I If we ruled the function’s interface, we can show difference

functionality by replacing functions rely on function pointer.

For Example: C’ stdlib.h — qsort() protype

void qsort(void* base, size_t n, size_t size,int (*cmp)(const void*, const void*));

/* function pointer */

Java Technicalities 17/58

Page 19: Java Technicalities

. . . . . .

Technicalities Class and Object

Back to C++ — Function Object

I The most difference between Function Object and Function Pointer isFunction Object has own states(variable).

I Implementation: Class with Operator Overloading “()”I If we implemented function object with template. It stars the Generic

Programming’s first step.

For Example: C++ — Function Object

template<typename T> class Less{public:

bool operator()(const T& x, const T& y){ return x < y;}}

Java Technicalities 18/58

Page 20: Java Technicalities

. . . . . .

Technicalities Class and Object

λ Function (Lambda Function)

I base on lambda-expressions from Functional Programming,.I no side-effect function.I an unnamed function for temporary usesI Haskell naive supportI C++’s support: Boost::lambda

For Example: C++ — Boost::lambda

std::sort(v.begin(), v.end(),std::greater<iterator_traits(v.begin())::value_type>());

std::sort(v.begin(), v.end(), *_1 > *_2);

Java Technicalities 19/58

Page 21: Java Technicalities

. . . . . .

Technicalities Class and Object

Call-Back Function — Anonymous Class with Interface

I What is “Call-Back Function”?I How does JavaScript support the Call-Back Function?I Class-Based vs Prototype-BasedI Java uses anonymous class and interface(Runnable) to support

call-back property.

For Example: Java — anonymous class with interface

Thread newTask = new Thread(new Runnable(){public void run(){ System.out.println("Hello World!"); }});

Java Technicalities 20/58

Page 22: Java Technicalities

. . . . . .

Technicalities Class and Object

Interface and Abstract ClassI interface and abstract are keywords.I Interface and abstract classes provide a more structured way to

separate interface from implementation.I In begin, we always have no idea to use them.I It’s show time to use “Refactoring”.I We can extract to super class, abstract class, or interface from the

same functionality classes.I Button-Up Design vs Top-Down Design

Java Technicalities 21/58

Page 23: Java Technicalities

. . . . . .

Technicalities Class and Object

Object-Oriented Class

I For efficient reason, C++ default member function mode isnon-virtual, but Java is not.

I Please read the relational books to get more details about Java’sClass.

I The feature is implemented by function pointer table.I Think about the relation of RTTI and function pointer table.I How to Design Class? Traditional OO Design vs eXtreme

Programming4

4We will discuss the issue next week.Java Technicalities 22/58

Page 24: Java Technicalities

. . . . . .

Technicalities Generic in Java (igonred)

Generic in JavaI Let’s ignore the topic.I We can discuss the topic if we have a basic knowledge for C++

Generic Programming.I C++’s STL is made from some Functional Programming concepts.I Java’s Generic is made by Java OO method.I In fact, Java’s Generic is still a OO paradigm.I You can play the paradigm using Haskell. It’s more interesting than

C++ and Java. XD

Java Technicalities 23/58

Page 25: Java Technicalities

. . . . . .

Technicalities Exception

Exception

I What is a “Exception”?I “GOTO Considered Harmful.”5

I Think about the relation between “goto” and “exceptions”.I We have to know program execute the exception block means low

efficiency.I But we couldn’t ignore writing exception when using some library(ex:

I/O, Socket, Thread)

5Edsger W. Dijkstra, Turing Award 1972Java Technicalities 24/58

Page 26: Java Technicalities

. . . . . .

Library and Programming

Library

I Muti-Threading Programming – java.util.concurrent.*I GUI Programming – javax.swing.*I Socket Programming – java.net.*I Generic Container – java.util.* (just for some classes) 6

I I/O – java.io.* (It is a good OO design example.I balabalaI Don’t forget gwchen’s requirements. XD

6In C++, Generic Container is more interesting than Java.Java Technicalities 25/58

Page 27: Java Technicalities

. . . . . .

Library and Programming

How to find Java Document ?I Please have a book named “Thinking in Java 4/e”. XDI Google Keyword –

“your keywords site:http://java.sun.com/javase/6/docs/”I Eclipse code completesI Google XD

Java Technicalities 26/58

Page 28: Java Technicalities

. . . . . .

Library and Programming String

What is a String?

I What is a “char”? What is a “string” ?I What’s difference between “char array” and “string” ?I char’s size is 1 byte.I string’s element is not always using 1 byte for saving information.

Maybe using 2 bytes, or ...I Java’s String uses UTF-8 as default encoding.

Java Technicalities 27/58

Page 29: Java Technicalities

. . . . . .

Library and Programming String

String method

I charAt & indexOfI startsWith & endsWithI subStringI containsI replace & replaceAll &

replaceFirstI matchs

I isEmptyI getBytes & getCharsI toCharArrayI toLowerCase & toUpperCaseI formatI trim

Java Technicalities 28/58

Page 30: Java Technicalities

. . . . . .

Library and Programming String

java.util.StringTokenizer

I http://java.sun.com/javase/6/docs/api/java/util/StringTokenizer.htmlI It can break a string into tokens.I If you want to complexing method for separating string, you can using

“Regular Expression” and java.lang.String.split().

Java Technicalities 29/58

Page 31: Java Technicalities

. . . . . .

Library and Programming String

Example: java.util.StringTokenizer

For Example: evaluate the sum of numbers

String s="123 456 789";StringTokenizer token = new StringTokenizer(s, " ");

int sum=0;while(token.hasMoreTokens()){

sum += Integer.parseInt(token.nextToken());}System.out.println("The sum is: " + sum + "\n");

Java Technicalities 30/58

Page 32: Java Technicalities

. . . . . .

Library and Programming String

Example: java.lang.String.split()

Attention: the argument using “Regular Expression”.

For Example: evaluate the sum of numbers

String s = "123 456 789";String[] split = s.split(" ");

int sum=0;for(int i=0;i<split.length;i++){

sum += Integer.parseInt(split[i]);}System.out.println("The sum is: " + sum + "\n");

Java Technicalities 31/58

Page 33: Java Technicalities

. . . . . .

Library and Programming Container and HashTable

Java ContainerI In Java 1.0/1.1, Java uses “Object Container”, but not suggests using

for now.I Java uses “Generic Container” instead of “Object Container” in Java

1.4 and after. Why does Java do?I Please first consider “Array” unless you have enough reasons to use

Java Container.I And you can’t use primitive type in Generic Container, please use

“type wrapper class” instead of “primitive type”.

For example: type wrapper class

List<int> u = new ArrayList<int>; // wrongList<Integer> u = new ArrayList<Integer>; // right

Java Technicalities 32/58

Page 34: Java Technicalities

. . . . . .

Library and Programming Container and HashTable

Class Hierarchy Tree

I java.util.ArraysI java.util.Collection<E>

I java.util.List<E>I java.util.Queue<E>

I java.util.Deque<E>I java.util.Set<E>

I java.util.SortedSet<E>

I java.util.Map<K, V>I java.util.SortedMap<K, V>

I java.util.Dictionary<K, V>I java.util.Hashtable<K, V>

I java.util.AbstractMap<K, V>I java.util.HashMap<K, V>

I java.util.LinkedHashMap<K, V>I java.util.TreeMap<K, V>

Java Technicalities 33/58

Page 35: Java Technicalities

. . . . . .

Library and Programming Container and HashTable

Vector — java.util.List<E>

I java.util.List<E> is an interface class.I The Most frequently using List is java.util.List.ArrayListI In interface, like C++’s std::vector<typename T>

I add() vs. push back()I get() vs. operator[]I size() vs. size()

I Although “Vector<E>” can be used, but Java’s doc suggests using“List” instead of “Vector”.

Java Technicalities 34/58

Page 36: Java Technicalities

. . . . . .

Library and Programming Container and HashTable

Example: java.util.List<E>

For Example: Count words of a file (1–2)

public int fileWordCount(String filename){try{

List<String> fileList = readFile(filename);int totalWords =0;for(int i=0;i<fileList.size();i++){totalWords += fileList.get(i).split(" ").length;}return totalWords;

}catch(Exception e){

System.out.println(e);}return -1;

}

Java Technicalities 35/58

Page 37: Java Technicalities

. . . . . .

Library and Programming Container and HashTable

Example: java.util.List<E> (2–2)

For Example: Count words of a file

public ArrayList<String> readFile(String filename) throws IOException{try{

ArrayList<String> u = new ArrayList<String>();BufferedReader in = new BufferedReader(new FileReader(filename));

String readLine = null;while((readLine = in.readLine())!=null){

u.add(readLine);}in.close();if(u.isEmpty()) return null;else return u;

}catch(FileNotFoundException e){

System.out.println(e);}return null;

}

Java Technicalities 36/58

Page 38: Java Technicalities

. . . . . .

Library and Programming Container and HashTable

HashTable — java.util.HashMap<K, V>

I HashMap can support the same functionality as HashTable.I Please use java.util.HashMap<K, V> instead of

java.util.HashTable<K, V>

I K is key, V is ValueI If you want use some class as a key, please check the class override

“Object.hashCode()” and “Object.equals()”.

Java Technicalities 37/58

Page 39: Java Technicalities

. . . . . .

Library and Programming Container and HashTable

Example: HashMap

For Example: HashMap list all entries

HashMap<String, Integer> nameAge =new HashMap<String, Integer>();

nameAge.put("John", 15); nameAge.put("Mary", 17);

Set<Map.Entry<String, Integer>> set = nameAge.entrySet();Iterator<Map.Entry<String, Integer>> iter = set.iterator();while(iter.hasNext()){

Map.Entry<String, Integer> e = iter.next();System.out.println(e.getKey() + " " + e.getValue());

}

Java Technicalities 38/58

Page 40: Java Technicalities

. . . . . .

Library and Programming Java I/O

Java I/O

I What is a “Stream”?I In Unix/Unix-like, everything is a file.I Java I/O Library is a pure OO paradigm example, and C++ is too.I You can get an overview by java.io.* hierarchy tree.7 It will helps

you to understand how to write I/O codes.

7http://java.sun.com/j2se/1.4.2/docs/api/java/io/package-tree.htmlJava Technicalities 39/58

Page 41: Java Technicalities

. . . . . .

Library and Programming Java I/O

Java I/O: Two Methods

Java has “InputStream/ OutputStream”, “Reader/ Writer”I InputStream/ OutputStream read 1 byte at a time.I Reader/ Writer read a char at a time.8

I Reader/ Writer default encoding is UTF8.I Recall: Java’s String type default encoding is UTF8.I Which can be used depends on your source.

8a char can be 1 byte, 2 bytes, ...Java Technicalities 40/58

Page 42: Java Technicalities

. . . . . .

Library and Programming Java I/O

Java I/O: InputStream/ OutputStream

I InputStream/ OutputStreamI ByteArrayInputStream/ ByteArrayOutputStream

— for String.getBytes(); (1 byte string)I FileInputStream/ FileOutputStream

— for filesI Socket.getInputStream()/ Sokcet.getOutputStream()

— for SocketI Process.getInputStream()/ Process.getOutputStream()

— for Process Control

You can use the above to adapt to the followingI BufferedInputStream/ BufferedOutputStream

— Support readLine()I DataInputStream/ DataOutputStream

— Support readInt() ...Java Technicalities 41/58

Page 43: Java Technicalities

. . . . . .

Library and Programming Java I/O

Java I/O: Reader/Writer

I Reader/ WriterI StringReader/ StringWriter — for a String.I FileReader/ FileWriter — for a file.I CharArrayReader/ CharArrayWriter – for memory

You can use the above to adapt to the followingI BufferedReader/ BufferedWriter — Support readLine()I Scanner/ not support

Java Technicalities 42/58

Page 44: Java Technicalities

. . . . . .

Library and Programming Java I/O

Java I/O: Others

The Bridge between InputStream/ OutputStream and Reader/ WriterI InputStreamReader/ OutputStreamWriter

— Stream translate to Reader/Writer

For Example: Socket

BufferedReader br = new BufferedReader(new InputStreamReader(Socket.getInputStream()));

The following is not maintained.I RandomAccessFileI ObjectInputStream/ ObjectOutputStreamI Java.nio (New I/O)

Java Technicalities 43/58

Page 45: Java Technicalities

. . . . . .

Library and Programming Java I/O

Example: evaluate the sum

For Example: evaluate the sum

public int evaluateSumByScanner(String s){StringReader sr = new StringReader(s);Scanner scanner = new Scanner(sr);

int sum = 0;while(scanner.hasNext()){

sum += scanner.nextInt();}sr.close();return sum;

}

Java Technicalities 44/58

Page 46: Java Technicalities

. . . . . .

Library and Programming Java I/O

Socket Programming

I Socket Programming is the same as writing to files because weconsider socket as a file stream.

I use “Buffered I/O” (ex: class java.io.BufferedWriter, classjava.io.BufferedReader)

I We have to be care about the message’s format.(fixed format or XMLformt)

I Please don’t use “\n” as a message’s end!I Please remember “Base64” format when you send binary messages.9

I Reference: yen3’s blog – 有關 File I/O 的兩三事 (1) 不算開始的開始,(2) Binary File, (3) XML

9http://en.wikipedia.org/wiki/Base64Java Technicalities 45/58

Page 47: Java Technicalities

. . . . . .

Library and Programming Java I/O

Socket Programming

I Client – java.net.SocketI Server – java.net.ServerSocketI Usually, We use Socket Programming together with Multi-threading

Programming in Server.I Don’t forget “ThreadPool”(java.util.concurrent.Executors)

Java Technicalities 46/58

Page 48: Java Technicalities

. . . . . .

Library and Programming JDBC — Java Database Connectivity

JDBC — Java Database Connectivity

I an API for the Java programming language that defines how a clientmay access a database.

I It provides methods for querying and updating data in a database.JDBC is oriented towards relational databases.

I Reference: Wiki: Java Database ConnectivityI Reference: caterpillar: Java 學習筆記(二): 資料庫(JDBC)I How To use?

Java Technicalities 47/58

Page 49: Java Technicalities

. . . . . .

Library and Programming JDBC — Java Database Connectivity

JDBC Example: MySQL

I Please install MySQL. XDI Please download MySQL Connector/J 5.1, the offical JDBC driver,

you will get a “jar” file.

I In Eclipse, press “Add External JARs...”, choose the file youdownloaded.

I Have fun!

Java Technicalities 48/58

Page 50: Java Technicalities

. . . . . .

Library and Programming JDBC — Java Database Connectivity

JDBC Example: Java and MySQL

For Example: List a table

public void testMySQL(){String driver = "com.mysql.jdbc.Driver";String serverName = "localhost";String databaseName = "information_schema";String tableName = "TABLES";String user = "yourname";String password = "yourpassword";String url = "jdbc:mysql://"+ serverName +"/" + databaseName;

Java Technicalities 49/58

Page 51: Java Technicalities

. . . . . .

Library and Programming JDBC — Java Database Connectivity

JDBC Example: Java and MySQL

For Example: List a table

try {Class.forName(driver);

Connection conn = (Connection) DriverManager.getConnection(url, user, password);Statement stmt = (Statement) conn.createStatement();ResultSet result = stmt.executeQuery("SELECT * FROM" + " " + tableName);while (result.next()) {

int numColumns = result.getMetaData().getColumnCount();for (int i = 1; i <= numColumns; i++) {

System.out.println("COLUMN " + i + " = "+ result.getObject(i));

}}conn.close();

}catch(ClassNotFoundException e) {

System.out.println("Can not find JDBC driver");}catch (SQLException e) {

e.printStackTrace();}

}

Java Technicalities 50/58

Page 52: Java Technicalities

. . . . . .

Conclusion Conclusion

ConclusionI We go through Java from different parts, especially from C/C++.I We go through some Java Library ... There are a lot of examples.

Please review it. XDI Java is a noun-kingdom XDXD. (What do you think about when

seeing “ArrayIndexOutOfBoundsException” first time?)I Please love “Eclipse IDE” when developing Java programs. XDI Let’s expect the interesting issue next week . XD

Java Technicalities 51/58

Page 53: Java Technicalities

. . . . . .

Conclusion Conclusion

Do you have any problem ?I am glad you have listened the slides from start to now. XD

Java Technicalities 52/58

Page 54: Java Technicalities

. . . . . .

Conclusion Reference

Reference — WebsiteI Java SE Documentation –

http://java.sun.com/javase/downloads/index.jspI Eclipse.org – http://www.eclipse.orgI 良葛格的學習筆記 – http://caterpillar.onlyfun.net/Gossip/

I C++ Boost Library – http://www.boost.orgI SGI STL – http://www.sgi.com/tech/stl/I TIOBE Software: Tiobe Index –

http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

Java Technicalities 53/58

Page 55: Java Technicalities

. . . . . .

Conclusion Reference

Reference — JavaI Thinking in Java 4/e, Bruce Eckel, ISBN: 0131872486I The Java Programming Language 4/e, Ken Arnold, James Gosling,

David Holmes , ISBN: 0321349806I Effective Java 2/e, Joshua Bloch, ISBN: 0321356683I Practical Java(TM) Programming Language Guide, Peter Haggar,

ISBN: 0201616467I The Art of Java, Herbert Schildt, James Holmes, ISBN: 0072229713I Java Network Programming 3/e, Elliotte Rusty Harold, ISBN:

0596007213I Java Swing 2/e, James Elliott, Robert Eckstein, Marc Loy, David

Wood, Brian Cole, ISBN: 0596004087

Java Technicalities 54/58

Page 56: Java Technicalities

. . . . . .

Conclusion Reference

Reference — Object Oriented Analysis/ Design/ Programming

I Object-Oriented Analysis and Design with Applications 3/e, GradyBooch, Robert A. Maksimchuk, Michael W. Engel, Bobbi J. Young,ISBN: 020189551

I Design Patterns: Elements of Reusable Object-Oriented Software,Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides, ISBN:0201663612

I Refactoring: Improving the Design of Existing Code, Martin Fowler,Kent Beck, John Brant, William Opdyke, don Roberts, ISBN:0201485672

I Refactroing to Pattens, Joshua Kerievsky, ISBN: 0321213351I Agile Software Development, Principles, Patterns, and Practices,

Robert C. Martin

Java Technicalities 55/58

Page 57: Java Technicalities

. . . . . .

Conclusion Reference

Reference — C/C++ and Other

I Real World Haskell, Bryan O’Sullivan, John Goerzen, Don Stewart,ISBN: 0596514980

I The C++ Programming Language 3/e, Bjarne Stroustrup, ISBN:0201700735

I The C Programming Language 2/e, Brian W. Kernighan, Dennis M.Ritchie, ISBN: 0131193716

I C++ Primer 4/e, Stanley B. Lippman, Josée Lajoie, and Barbara E.Moo, ISBN: 0201721481

I Effective C++ 3/e: 55 Specific Ways to Improve Your Programs andDesigns, Scott Meyers, ISBN: 0321334876

I Generic Programming and the STL: Using and Extending the C++Standard Template Library, Matthew H. Austern, ISBN: 0201309564

Java Technicalities 56/58

Page 58: Java Technicalities

. . . . . .

Conclusion Reference

Appendix A: How to get a html String

For Example: How to get a html String

public String getHtmlString(String inputUrl){try{

URLConnection url = (new URL(inputUrl)).openConnection();BufferedReader br = new BufferedReader(

new InputStreamReader(url.getInputStream()));int length=-1;StringBuffer sb = new StringBuffer();char[] temp = new char[1024];while((length=br.read(temp, 0, 1024))!= -1){

sb.append(temp, 0, length);}

br.close();return sb.toString();}catch (MalformedURLException ex) {

System.err.println(inputUrl + "is not parseable URL");}catch (IOException ex) {

System.err.println(ex);}

return null;}

Java Technicalities 57/58

Page 59: Java Technicalities

. . . . . .

Conclusion Reference

Appendix B: How to write Java Program

I Please install “Java Developer Kit(JDK)” and “Java RuntimeEnvironment”

I Please set “PATH” and “CLASSPATH” in Windows.I You can download “Eclipse” as your default Java Develop IDE.I Have fun!

Java Technicalities 58/58