ATSBA: Advanced Technologies Supporting Business Areas Programming with Java 1 Overview and Introduction 1
1 Overview and Introduction 1 Overview and Introduction 1.1 Programming and Programming Languages 1.1.1 Programming 1.1.2 Basic Program Structures 1.1.3 Programming Languages 1.2 What is Java? 1.2.1 Origin of Java 1.2.2 Advantages of Java 1.3 Examples of Java 1.3.1 Java programs 2
1.1 Programming and Programming Languages 1 Overview and Introduction 1.1 Programming and Programming Languages 1.1.1 Programming 1.1.2 Basic Program Structures 1.1.3 Programming Languages 1.2 What is Java? 1.3 Examples of Java 3
1.1 Programming and Programming Languages An important part of software engineering is the software development. The software development can be divided in phases, according to the life cycle of the software: Requirements Phase Specification / Analysis Phase Design Phase Implementation / Programming Phase Integration and Deployment Phase Maintenance Phase Within the implementation phase the programming takes place. Here, the concepts which describe which requirements and how the software should fulfil are transcribed into a programming code. In general, this programming code is then translated into an executable computer program (machine code). 4
1.1.1 Programming Simply spoken, programming signifies the following: Write a text which a computer can interpret. By means of programming an algorithm becomes an executable program. A program is thereby a machine-readable and machine-compatible description of one or several algorithms and the necessary data. Here then, one also speaks of software. Algorithm In mathematics an algorithm is a procedure with which, on account of a system of given rules, data (input information, tasks) can be converted into other data (issue information, solutions). Complex processes of (arithmetic) machines are modelled by algorithms. [Source: www.wissen.de; date: 23.9.02] 5
1.1.1 Programming Software All programs and program modules of a computer in contrast to the hardware. Also the data which is already known to the program at the start (initialization data) belongs to the software. The software divides itself into the system software which forms the computer system together with the hardware, and the application software which formulates particular, special tasks; this disintegrates again into two groups: the standard software, programs that can be used by many users, and individual solutions which cover in each case only a completely special case. The system software serves the operability of the computer system and allows the construction of application software. [Source: www.wissen.de; date: 23.9.02] Two big different kinds of programming (also called paradigms) are distinguished: structured programming (also called modular, imperative or procedural programming) object-oriented programming 6
1.1.1 Programming: Definitions Structured programming is an approach towards the production of software which puts together single modules of a program in the form of hierarchically arranged components. In every component its functions are exclusively executed. Object-oriented programming (abbreviation OOP) is a name for a programming approach with which data and the operations to be applied on these data (algorithms) are considered as unities, so-called classes. The class is an abstract type definition which contains a data structure and the methods operating on it (operations). The concrete copies of a class are called objects. In the program sequence, the objects communicate with each other by questioning the other object on certain qualities or by asking it to explain a certain operation with a transmitted data value. How a certain operation is realised on the inside, remains concealed to the outside. [Source: www.wissen.de; date: 23.9.02] 7
1.1.2 Basic Program Structures If one converts algorithms into a computer-understandable form, the same three (or four) basic program structures appear again and again, regardless of a programming language. These structures are: Instructions Branching out or alternatives on the basis of conditions Repetitions with loops (Call of other algorithms or blocks with additional program structures) If one summarizes several of these single program structures, another basic program structure arises, that is circumscribed depending on the programming language or program type respectively as: Block (module, function, subroutine, class, object or however) 8
1.1.3 Programming Languages For the programming the most different computer languages can be used: Procedural or imperative: C, FORTRAN, Modula, Pascal, BASIC, Cobol, assembler language... Object-oriented: C ++, Java, small talk, Eiffel, Simula... Logically: Prologue... A program code (source code) is formulated according to exactly specified rules. These rules are called syntax. These rules or the syntax are exactly fixed in every programming language: Programs must keep to the syntax. Every point, every comma has its meaning; in general, even the smallest mistakes lead to a non- or misunderstanding of the program. 9
1.1.3 Programming Languages Early programming languages orientated themselves at the available operations of a computer: machine-close programming, e.g., assembler language. Modern high-level programming languages permit the abstract formulation of an algorithm. The characteristics of the hardware do no longer play a role in the programming. The advantages are that the programs are workable without change of their program text on different computers. 10
1.1.3 Programming Languages: Java Virtual Machine Some programming languages are compiled, some are interpreted, some are both, like Java. Java Program Text sjfhs =jfh 456kjhsjkhfksf fkjgwsh=fshfksfkjhsdf et45vrkjgwert5hegfkjhdg; erthjjhjdjfg 45 3424gwr v ekj:; hkjdhfdhfsf ejhkjd5v 3 2hgfkahf gs dgjkdfghkjdhfgwge jhbd345sfkjhkasdfw asdff:; hkjadhsfka ashfbf kjashfk sdf ffsf adasfa fasfa fsfd Java compiler translates Java Byte Code 010101001010101 010010100101010 010100100010101 001000000000001 111101010100100 101010100000010 011110101010100 101001010010100 100101010010010 10011 other computer platform Computer Memory Java Virtual Machine Processor CPU 11
1.2 What is Java? 1 Overview and Introduction 1.1 Programming and Programming Languages 1.2 What is Java? 1.2.1 Origin of Java 1.2.2 Advantages of Java 1.2.3 Some Misunderstandings of Java 1.3 Examples of Java 12
1.2.1 Origin of Java Sun Microsystems or JavaSoft, a subsidiary of Sun Microsystems, started to develop Java in 1990. (The name Java goes back to a coffee sort which the developers are said to have drunk in large quantities.) The motivation to develop Java lay in the fact that the most different electronic devices (e.g., video recorder, washing machine, coffeemaker, phone...) will own a processor. A special operating system and a special programming language should run on all devices. However, this could not yet be realised at the beginning of the 1990s. http://java.sun.com/ 13
1.2.1 Origin of Java Later, in 1995, Java with its heterogeneous target platforms (workstations, PCs of various manufacturers) found use in Internet applications (as the first language worldwide). Sun makes Java available for free together with its development environment JDK (Java Development Kit) for different operating systems. No matter which hardware was used for surfing on the Internet, Internet applications could be programmed for the first time with Java independent of the platform. Also then originated the first applications running in the browser, the so-called Java Applets. http://java.sun.com/ 14
1.2.2 Advantages of Java The syntax of Java is simpler than the syntax of C/C ++, but it is very similar: simple for programmers changing the programming language and programming-beginners Java code is widely platform-independent, architecture-neutral and stable: Java programs can be developed where the Java compiler runs. Java programs can run where the Java Virtual Machine runs. Java programs also run distributed decentralized through various computer architectures (distributed applications). Java programs are easily portable. Java (almost) never crashes. The basic interpreter of Java does not need a lot of storage space (approx. 40 KB): Suitable also for "small" electronic devices (Embedded systems). Java is completely object-oriented and safe: Its memory cannot be accessed arbitrarily. Java supports Multithreading: Several tasks and processes are able to run at the same time, virtually in parallel on a processor (respectively computer). 15
1.3 Examples of Java 1 Overview and Introduction 1.1 Programming and Programming Languages 1.2 What is Java? 1.3 Examples of Java 1.3.1 Java Programs 16
1.3.1 Java Programs Java applications: Eclipse (integrated development environment = IDE): http://www.eclipse.org/ Other: http://java-source.net/ e.g., data banks, web servers, mail clients, Search engines... and many, many more 17
Learning Targets To be able to explain what programming, algorithms and software signifies, describe the three basic structures in computer programs, explain the differences between compiler and interpreter as well as the way of functionality of the Java Virtual Machine, give an overview over Java. 18