1 / 38

Intorduction to Java Programming Session 2

Intorduction to Java Programming Session 2. Course : T0974-Algorithm & Object-Oriented Programming I Year : 2010. Learning Outcome. After taking this course, students should be expected to explain and discuss structure and element of java programming. Outline Materi.

Download Presentation

Intorduction to Java Programming Session 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intorduction to Java ProgrammingSession 2 Course : T0974-Algorithm & Object-Oriented Programming I Year : 2010

  2. Learning Outcome After taking this course, students should be expected to explain and discuss structure and element of java programming

  3. Outline Materi • History of Java Programming Language • Characteristics • API, JDK, JRE • Java Platform • Simple Program using Java • Anatomy of Java Programming • Escape Sequence • Unicode

  4. Java History • Developed by James Gosling from Sun Microsystem and sold to Oracle in 2009. • Agustus 1991, It was named as Oak • Januari 1995, Change to Java • Based on “Write Once, Run Anywhere (WORA)” • Can be run in web browser using Applet technology.

  5. Characteristics • Simple • Object-oriented • Distributed • Interpreted • Robust • Secure • Architecture-neutral • Portable • High-performance • Multi-threaded • Dynamic

  6. Application Program Interface (API) • Collection of classes and interfaces for developing Java based application. • Java API editions: • Java 2 Standard Edition (J2SE) • Client-Side application, applet • Java 2 Enterprise Edition (J2EE) • Servlet, JSP • Java 2 Micro Edition (J2ME) • Mobile Phone

  7. Java Development Toolkit (JDK) • Collection of separated development tools to build and test single Java programs to complex Java projects. • Java Development Tools is an IDE (Integrated Development Tool) based application intended to build Java projects quickly. • JBuilder by Borland (www.borland.com) • NetBeans Open Source by Sun (www.netbeans.org) • Eclipse Open Source by IBM (www.eclipse.org) • Code Warrior by Metrowerks (www.metrowerks.com) • TextPad Editor (www.textpad.com) • JCreator LE (www.jcreator.com) • JEdit (www.jedit.org)

  8. Java Development Toolkit (JDK) • Most commonly application programs in JDK • Compiler: javac • Compiling a source code(.java) into bytecode(.class) • Interpreter: java • Execute a bytecode (.class) as application. • Debugger: jdb • Applet Viewer : appletviewer • Documentation: javadoc • Compressor: jar

  9. Java Runtime Environment (JRE) • A Software that execute Java based application • Java Virtual Machine (JVM) is a collection of programs to execute java bytecode on any computer platform. • Java Bytecode is a collection of machine-specific instruction that be interpreted and executed by JVM. Its length is 1 byte per instruction.

  10. Java Platform

  11. Simple Program // This application program prints Welcome to Java! public class Welcome { public static void main(String[] args){ System.out.println(“Welcome to Java!”); } }

  12. Simple Program // This application program prints Welcome to Java! public class Welcome { public static void main(String[] args){ System.out.println(“Welcome to Java!”); } } Class name Filename: Welcome.java Comments Class heading, Main method signature String

  13. Simple Class • Every Java Program should have 1 public class e.g. Welcome • To execute a class, it should have a main mathod. • System.out.println is a statement to print string into console.

  14. Creating, Compiling, Executing Source code (developed by the programmer) Create/Modify Source Code public class Welcome { Public static void main(String [] args) { System.out.println(“Welcome to Java!”); } } Save on the disk Source Code Compile Source Code e.g., javac Welcome.java Bytecode (generated by the compiler for JVM to read and interpret, not for you to understand) If compilation errors Stored in the disk … Method Welcome() 0 aload_0 … Method void main(java.lang.String[]) 0 getstatic #2 … 3 ldc #3 <String “Welcome to Java!”> 5 invokevirtual #4 8 return Bytecode Run Bytecode e.g., java Welcome If runtime errors or Incorrect result Result

  15. Java Anatomy • Whitespace • Identifiers • Literal • Comments • Separators • Reserved words (keyword) • Modifiers • Statements • Blocks • Classes • Methods • The main method

  16. Whitespace • Free-Form Language • Doesn’t need Indentation rules • Can be made only 1 line of code. • Only one whitespace between token that doesn’t have operator. • Example whitespace: space, tab, newline

  17. Identifiers • Use for naming a class, method, and variable • Uppercase/Lowercase character, number, undercore, or $ sign can be used as identifiers. • Don’t be started using a number. • Case Sensitive • Example : • AvgTemp, args, count, f4, $test, this_is_ok

  18. Literals • Constant number. • Should be Real Number, Decimal number, Character, String, Boolean, depend on the type we are going to use. • e.g.: • 100 • 98.6 • ‘X’ • “This is a test”

  19. Comments • Use notations, • // --- line comment • /* … */ --paragraph comment • Helping a programmer to communicate and understand a program. • Usually as a internal program documentation • e.g: // This application program prints Welcome to Java! /* This application program prints Welcome to Java! */ /* This application program prints Welcome to Java! */

  20. Separators/Punctuations • Specific notations for spesific goals. • e.g:

  21. ReservedWords • keywords • Reserved words have a specific meaning to a compiler. • Couldn’t be used for another use in program. • e.g : • class when compiler find a word class, then a word after the class is assumed as the name of the class. • public, static, void • Java is Case-Sensitive, so public isassumed as a keyword but Public isn’t.

  22. Reserved Words * reserved for next version of Java.

  23. Modifiers • Reserved Words. • Showing properties. • Showing data properties , methods, and classes. • Modifiers : • public • static • private • final • abstract • protected

  24. Statements • Displaying its actions. • e.g. • System.out.println(“Welcome to Java!”); Statement for showing a string into console. • Every statement should be ended by semicolon.

  25. Blocks • Stated by using curly brackets ``{}” • Every class should have class block that contains data and method(s). • Every method has a method block that contains statement(s) • Block can possibility be written inside a block (nested block). public class Test { public static void main(String[] args) { System.out.println(“Welcome to Java!”); } } Method Block Class Block

  26. Classes • Core of Java Programming • Every Java Program should have 1 public class. • Inside a class should has a data and method(s) (Encapsulation).

  27. Methods • Collection of Statements that to be encapsulated. • e.q. : • System.out.println System.out  standard output object println  method dalam object The results will be appear into command prompt.

  28. MainMethod • Every Java application should have main methods. • A place to start program execution. • JVM execute an application through main method. • e.g. : public static void main(String[] args) { // statements }

  29. EscapeSequence • Special characters. • Start from backslash ( \ ) before characters.

  30. EscapeSequence Example of escape sequence.

  31. Did YouKnow? • Java Versions • 19 Februari 1997, Java 1.1 • hanya AWT • 08 Desember 1998, Java 1.2 • Codename: Playground, dikenal dengan Java 2, muncul platform J2SE, J2EE, J2ME • 08 Mei 2000, Java 1.3 • Codename: Kestrel, mengintegrasikan sound • 06 Februari 2002, Java 1.4 • Codename: Merlin, mengintegrasikan XML • 30 September 2004, Java 5.0 • Codename: Tiger, awalnya berversi 1.5 (tetapi sudah menghilangkan metode versi 1.x) • 11 Desember 2006, Java 6 • Codename: Mustang, menghilangkan metode versi x.0, mendukung Visual Basic, GUI Vista • (belum rilis) 2008, Java 7 • Codename: Dolphin, perbaikan beberapa bug pada versi sebelumnya

  32. Did You Know ? • Java Logo : • Java Mascot (Duke):

  33. AdvancedLearning • Java supports Unicode • Encoding scheme developed by Unicode Consortium. • Support translating, processing, displaying language around the world. • e.g.: • Welcome dalam mandarin  • I Love You dalam mandarin 

  34. Advanced Learning • Example of using a Unicode

  35. Advanced Learning • import java.swing.JOptionPane;  will be explained in next session. • To show message graphics box : JOptionPane.showMessageDialog (null,”…”,”…”,JOptionPane…); jenis pesan parent teks judul

  36. Advanced Learning • Execution result,

  37. Refereces • Introduction to Java Programming. 7ed. Liang. 2009. p40-48 • Java Programming Language. http://en.wikipedia.org/wiki/Java_(programming_language) • Java Software Platform. http://en.wikipedia.org/wiki/Java_(software_platform) • Java Bytecode. http://en.wikipedia.org/wiki/Java_bytecode • JDK. http://en.wikipedia.org/wiki/Java_Development_Kit • JVM. http://en.wikipedia.org/wiki/Java_Virtual_Machine • Logo Java. http://en.wikipedia.org/wiki/Image:Java_Logo.svg • Java Platform. http://en.wikipedia.org/wiki/Image:JavaPlatform.jpg • http://en.wikipedia.org/wiki/Image:Wave.svg • Java Characteristics. http://www.cs.armstrong.edu/liang/intro6e/JavaCharacteristics.pdf • History of Java. http://java.sun.com/features/1998/birthday.html • Lexical Structure. http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html

More Related