Lesson1: JAVA


Computer Fundamentals I




  INTRODUCTION TO JAVA PROGRAMMING
HARDWARE AND SOFTWARE




       INTRODUCTION TO JAVA PROGRAMMING
What is Programming Language
• High Level Language & Low Level
  Language

C++, C, FORTRAN, PASCAL
Assembly Language or Machine Language
• High Level Language Better or Low Level
  Language.


              INTRODUCTION TO JAVA PROGRAMMING
Programming languages: A Review
•   FORTRAN                      •   Ada
•   COBOL                        •   SQL
•   BASIC                        •   Lisp
•   Z80 assembler                •   Prolog
•   IBM 360 assembler            •   Eiffel
•   PL1                          •   HTML
•   SL1                          •   JavaScript
•   C                            •   Java
•   Pascal                       •   Jess
•   SNOBOL

                 INTRODUCTION TO JAVA PROGRAMMING
Discussion Points
• Different levels: high - low
• Different implementations: interpreted, compiled
• Different paradigms: procedural, declarative,
   object oriented
• Different target domains: data processing,
   scientific, database manipulation, string
   manipulation, logic, general purpose …
• Different ages: modern/ old fashioned; longevity
• Different language features/ constructs


                  INTRODUCTION TO JAVA PROGRAMMING
Common Grounds
• Handle data: variables
• Handle flow of control:
– sequence, selection, iteration
• Shared code: sub routines
• Data structures: arrays
• File handling


               INTRODUCTION TO JAVA PROGRAMMING
Interpreting and Compiling




NOTE : JAVA do both, Interpreting and Compiling
                        INTRODUCTION TO JAVA PROGRAMMING
How JAVA Works




Portability can be Achieved this Way




                  INTRODUCTION TO JAVA PROGRAMMING
Why JAVA
• Simple and clean
• Object oriented
• Portable/ platform independent
• Robust
• Secure
• Multi-threaded
• Dynamic
• ++

               INTRODUCTION TO JAVA PROGRAMMING
Program
• A program is a sequence of instructions that specifies
  how to perform a computation.
BASIC Operations in Program:
• Input
• Output
• Mathematical Operations
• Testing
• Repetition
  “Programming can also be described as the process of
  breaking a large, complex task up into smaller and smaller
  subtasks until eventually the subtasks are simple enough to
  be performed with one of these basic operations.”


                     INTRODUCTION TO JAVA PROGRAMMING
Debugging
• Bugs and Errors
• Types of Errors
               Compile Time Errors
               Run Time Errors
               Logic and Semantic Error
• Experimental Debugging


              INTRODUCTION TO JAVA PROGRAMMING
A First Program
• Print “Hello World” to the console
/*
* HelloWorld.java
*
* Created on 19 Sep 2010, 17:56
*/
        class HelloWorld {
               public static void main (String args[]) {
               System.out.println("Hello World!");
                                                       }
                           }

                      INTRODUCTION TO JAVA PROGRAMMING
First Steps...
• A Java application is made up of a
   collection of classes
• Normally, one (& only one) of these classes
   should have a method called main
• Console output can be achieved using:
               System.out.print(“a string”);
               or
               Err     or
                       println
                                    or a
                                    variable

                     INTRODUCTION TO JAVA PROGRAMMING
Compiling First Program
• The file name of this program is:
            HelloWorld.java
• To compile the program, type:
            javac HelloWorld.java
• To run the program, type:
            java HelloWorld
• Output should be:
            Hello World!

                INTRODUCTION TO JAVA PROGRAMMING
The JAVA Virtual Machine
• Java is compiled into an intermediate form
  (bytecode)
• These are the .class files produced by javac
• The bytecode is interpreted at runtime by
  the Java Virtual Machine
• Java compiled on one machine (type) can be
  executed on another (type)

                INTRODUCTION TO JAVA PROGRAMMING
Standard Java Tools (Java 2 SDK)
• javac - the compiler
• java - the launcher for Java apps
• javadoc - API documentation generator
• appletviewer - run & debug applets without
   a browser
• jar - manage Java Archive (JAR) files
• jdb - Java debugger
• javap - class file dis assembler
• ++

               INTRODUCTION TO JAVA PROGRAMMING
JDK Kits and Editors
• J2SE Available on Sun Website
• Editors: Stick with javac, java & your
  chosen editor (PFE, notepad, JCreator, …)
• Java Keywords: 48 reserved Keyword in
  Java Language.
List can be checked at
  http://java.sun.com/docs/books/jls/second_e
  dition/html/lexical.doc.html

               INTRODUCTION TO JAVA PROGRAMMING

Lesson1 intro

  • 1.
    Lesson1: JAVA Computer FundamentalsI INTRODUCTION TO JAVA PROGRAMMING
  • 2.
    HARDWARE AND SOFTWARE INTRODUCTION TO JAVA PROGRAMMING
  • 3.
    What is ProgrammingLanguage • High Level Language & Low Level Language C++, C, FORTRAN, PASCAL Assembly Language or Machine Language • High Level Language Better or Low Level Language. INTRODUCTION TO JAVA PROGRAMMING
  • 4.
    Programming languages: AReview • FORTRAN • Ada • COBOL • SQL • BASIC • Lisp • Z80 assembler • Prolog • IBM 360 assembler • Eiffel • PL1 • HTML • SL1 • JavaScript • C • Java • Pascal • Jess • SNOBOL INTRODUCTION TO JAVA PROGRAMMING
  • 5.
    Discussion Points • Differentlevels: high - low • Different implementations: interpreted, compiled • Different paradigms: procedural, declarative, object oriented • Different target domains: data processing, scientific, database manipulation, string manipulation, logic, general purpose … • Different ages: modern/ old fashioned; longevity • Different language features/ constructs INTRODUCTION TO JAVA PROGRAMMING
  • 6.
    Common Grounds • Handledata: variables • Handle flow of control: – sequence, selection, iteration • Shared code: sub routines • Data structures: arrays • File handling INTRODUCTION TO JAVA PROGRAMMING
  • 7.
    Interpreting and Compiling NOTE: JAVA do both, Interpreting and Compiling INTRODUCTION TO JAVA PROGRAMMING
  • 8.
    How JAVA Works Portabilitycan be Achieved this Way INTRODUCTION TO JAVA PROGRAMMING
  • 9.
    Why JAVA • Simpleand clean • Object oriented • Portable/ platform independent • Robust • Secure • Multi-threaded • Dynamic • ++ INTRODUCTION TO JAVA PROGRAMMING
  • 10.
    Program • A programis a sequence of instructions that specifies how to perform a computation. BASIC Operations in Program: • Input • Output • Mathematical Operations • Testing • Repetition “Programming can also be described as the process of breaking a large, complex task up into smaller and smaller subtasks until eventually the subtasks are simple enough to be performed with one of these basic operations.” INTRODUCTION TO JAVA PROGRAMMING
  • 11.
    Debugging • Bugs andErrors • Types of Errors Compile Time Errors Run Time Errors Logic and Semantic Error • Experimental Debugging INTRODUCTION TO JAVA PROGRAMMING
  • 12.
    A First Program •Print “Hello World” to the console /* * HelloWorld.java * * Created on 19 Sep 2010, 17:56 */ class HelloWorld { public static void main (String args[]) { System.out.println("Hello World!"); } } INTRODUCTION TO JAVA PROGRAMMING
  • 13.
    First Steps... • AJava application is made up of a collection of classes • Normally, one (& only one) of these classes should have a method called main • Console output can be achieved using: System.out.print(“a string”); or Err or println or a variable INTRODUCTION TO JAVA PROGRAMMING
  • 14.
    Compiling First Program •The file name of this program is: HelloWorld.java • To compile the program, type: javac HelloWorld.java • To run the program, type: java HelloWorld • Output should be: Hello World! INTRODUCTION TO JAVA PROGRAMMING
  • 15.
    The JAVA VirtualMachine • Java is compiled into an intermediate form (bytecode) • These are the .class files produced by javac • The bytecode is interpreted at runtime by the Java Virtual Machine • Java compiled on one machine (type) can be executed on another (type) INTRODUCTION TO JAVA PROGRAMMING
  • 16.
    Standard Java Tools(Java 2 SDK) • javac - the compiler • java - the launcher for Java apps • javadoc - API documentation generator • appletviewer - run & debug applets without a browser • jar - manage Java Archive (JAR) files • jdb - Java debugger • javap - class file dis assembler • ++ INTRODUCTION TO JAVA PROGRAMMING
  • 17.
    JDK Kits andEditors • J2SE Available on Sun Website • Editors: Stick with javac, java & your chosen editor (PFE, notepad, JCreator, …) • Java Keywords: 48 reserved Keyword in Java Language. List can be checked at http://java.sun.com/docs/books/jls/second_e dition/html/lexical.doc.html INTRODUCTION TO JAVA PROGRAMMING