Click here to load reader

Intorduction to Java Programming Session 2

  • View

  • Download

Embed Size (px)


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. - PowerPoint PPT Presentation

Text of Intorduction to Java Programming Session 2

  • Intorduction to Java ProgrammingSession 2Course: T0974-Algorithm & Object-Oriented Programming IYear: 2010

  • Bina Nusantara University*Learning OutcomeAfter taking this course, students should be expected to explain and discuss structure and element of java programming

  • Bina NusantaraOutline MateriHistory of Java Programming LanguageCharacteristicsAPI, JDK, JREJava PlatformSimple Program using JavaAnatomy of Java ProgrammingEscape SequenceUnicode

  • Bina NusantaraJava HistoryDeveloped by James Gosling from Sun Microsystem and sold to Oracle in 2009.Agustus 1991, It was named as OakJanuari 1995, Change to JavaBased on Write Once, Run Anywhere (WORA)Can be run in web browser using Applet technology.

  • Bina NusantaraCharacteristicsSimpleObject-orientedDistributedInterpretedRobustSecureArchitecture-neutralPortableHigh-performanceMulti-threadedDynamic

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

  • Bina NusantaraJava 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 ( Open Source by Sun ( Open Source by IBM ( Warrior by Metrowerks ( Editor ( LE ( (

  • Bina NusantaraJava Development Toolkit (JDK)Most commonly application programs in JDKCompiler: javacCompiling a source code(.java) into bytecode(.class)Interpreter: javaExecute a bytecode (.class) as application.Debugger: jdbApplet Viewer : appletviewerDocumentation: javadocCompressor: jar

  • Bina NusantaraJava 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.

  • Bina NusantaraJava Platform

  • Bina NusantaraSimple Program// This application program prints Welcome to Java!

    public class Welcome {public static void main(String [] args) {System.out.println(Welcome to Java!);}}

  • Bina NusantaraSimple Program// This application program prints Welcome to Java!

    public class Welcome {public static void main(String [] args) {System.out.println(Welcome to Java!);}}CommentsClass nameFilename: Welcome.javaClass heading,Main method signatureString

  • Bina NusantaraSimple ClassEvery Java Program should have 1 public class e.g. WelcomeTo execute a class, it should have a main mathod.System.out.println is a statement to print string into console.

  • Bina NusantaraCreating, Compiling, Executing Source CodeCreate/Modify Source CodeCompile Source Codee.g., javac Welcome.javaBytecodeRun Bytecodee.g., java WelcomeResultIf compilation errorsIf runtimeerrors orIncorrectresultpublic class Welcome { Public static void main(String [] args) { System.out.println(Welcome to Java!); }}Save on the diskSource code (developed by the programmer)Method Welcome() 0 aload_0

    Method void main(java.lang.String[]) 0 getstatic #2 3 ldc #3 5 invokevirtual #4 8 returnBytecode (generated by the compiler for JVM to read and interpret, not for you to understand)Stored in the disk

  • Bina NusantaraJava AnatomyWhitespaceIdentifiersLiteralCommentsSeparatorsReserved words (keyword)ModifiersStatementsBlocksClassesMethodsThe main method

  • Bina NusantaraWhitespaceFree-Form LanguageDoesnt need Indentation rulesCan be made only 1 line of code. Only one whitespace between token that doesnt have operator.Example whitespace: space, tab, newline

  • Bina NusantaraIdentifiersUse for naming a class, method, and variableUppercase/Lowercase character, number, undercore, or $ sign can be used as identifiers.Dont be started using a number.Case SensitiveExample :AvgTemp, args, count, f4, $test, this_is_ok

  • Bina NusantaraLiteralsConstant number.Should be Real Number, Decimal number, Character, String, Boolean, depend on the type we are going to use.e.g.:10098.6XThis is a test

  • Bina NusantaraCommentsUse notations,// --- line comment/* */ --paragraph commentHelping a programmer to communicate and understand a program.Usually as a internal program documentatione.g:// This application program prints Welcome to Java!/* This application program prints Welcome to Java! *//* This application program prints Welcome to Java! */

  • Bina Nusantara Separators/PunctuationsSpecific notations for spesific goals.e.g:

    SymbolsNameFunctions( )Parenthesis (-es plural)List of parameters in methods{ }Curly BracketsAs a block or Array Initialization.[ ]BracketsArray declaration.;SemicolonClosing statement,CommaSeparator for variable or for statement..PeriodPackage name and subpackage separator. Separating Variables or Methods with object/class.

  • Bina NusantaraReserved WordskeywordsReserved words have a specific meaning to a compiler.Couldnt be used for another use in program.e.g :classwhen compiler find a word class, then a word after the class is assumed as the name of the class.public, static, voidJava is Case-Sensitive, so public is assumed as a keyword but Public isnt.

  • Bina NusantaraReserved Words* reserved for next version of Java.

    abstractdefaultgoto *packagethisassertdoifprivatethrowbooleandoubleimplementsprotectedthrowsbreakelseimportpublictransientbyteenuminstanceofreturntruecaseextendsintshorttrycatchfalseinterfacestaticvoidcharfinallongstrictfpvolatileclassfinallynativesuperwhileconst *floatnewswitchcontinuefornullsynchronized

  • Bina NusantaraModifiersReserved Words.Showing properties.Showing data properties , methods, and classes.Modifiers :publicstaticprivatefinalabstractprotected

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

  • Bina NusantaraBlocksStated 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!); } }MethodBlockClassBlock

  • Bina NusantaraClassesCore of Java ProgrammingEvery Java Program should have 1 public class.Inside a class should has a data and method(s) (Encapsulation).

  • Bina NusantaraMethodsCollection of Statements that to be encapsulated.e.q. :System.out.printlnSystem.out standard output objectprintln method dalam objectThe results will be appear into command prompt.

  • Bina NusantaraMain MethodEvery 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}

  • Bina NusantaraEscape SequenceSpecial characters.Start from backslash ( \ ) before characters.

    Character Escape SequenceName\bBackspace\tTab\nLinefeed\fFormfeed\rCarriage Return\\Backslash\Single Quote\Double Quote\dddOctal (0 s/d 377)\uddddHeksadesimal (dd= 0 s/d FF atau ff)

  • Bina NusantaraEscape SequenceExample of escape sequence.

  • Bina NusantaraDid You Know?Java Versions19 Februari 1997, Java 1.1hanya AWT08 Desember 1998, Java 1.2Codename: Playground, dikenal dengan Java 2, muncul platform J2SE, J2EE, J2ME08 Mei 2000, Java 1.3Codename: Kestrel, mengintegrasikan sound06 Februari 2002, Java 1.4Codename: Merlin, mengintegrasikan XML30 September 2004, Java 5.0Codename: Tiger, awalnya berversi 1.5 (tetapi sudah menghilangkan metode versi 1.x)11 Desember 2006, Java 6Codename: Mustang, menghilangkan metode versi x.0, mendukung Visual Basic, GUI Vista(belum rilis) 2008, Java 7Codename: Dolphin, perbaikan beberapa bug pada versi sebelumnya

  • Bina NusantaraDid You Know ?Java Logo :

    Java Mascot (Duke):

  • Bina NusantaraAdvanced LearningJava supports UnicodeEncoding scheme developed by Unicode Consortium.Support translating, processing, displaying language around the world. e.g.:Welcome dalam mandarin I Love You dalam mandarin

  • Bina NusantaraAdvanced LearningExample of using a Unicode

  • Bina NusantaraAdvanced Learningimport java.swing.JOptionPane; will be explained in next session.To show message graphics box :JOptionPane.showMessageDialog(null,,,JOptionPane);parentteksjuduljenis pesan

  • Bina NusantaraAdvanced LearningExecution result,

  • Bina NusantaraReferecesIntroduction to Java Programming. 7ed. Liang. 2009. p40-48Java Programming Language. Java Software Platform. Bytecode. Java. Platform. Characteristics. of Java.

Search related