1 / 24

Date: 11.11.2008 Subject: Distributed Data Processing Name: Maria Br ü ckner

Date: 11.11.2008 Subject: Distributed Data Processing Name: Maria Br ü ckner. What is Java? Characteristics Flavors Java vs. JavaScript Java Applications Java Basics. Java Program Example: Hello Java! Example: Parity Calculation Garbage Collection Example: Value & Reference

verda
Télécharger la présentation

Date: 11.11.2008 Subject: Distributed Data Processing Name: Maria Br ü ckner

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. Date: 11.11.2008 Subject: Distributed Data Processing Name: Maria Brückner

  2. What is Java? Characteristics Flavors Java vs. JavaScript Java Applications Java Basics Java Program Example: Hello Java! Example: Parity Calculation Garbage Collection Example: Value & Reference Inheritance What Java hasn‘t got CONTENT

  3. Hi, I‘m duke, the Java Mascot What is Java ? • programming language developed by Sun Microsystems • first public available version of Java (Java 1.0) was released 1995 • target: a program can be written once and then runs on multiple operating systems • consists out of a Java compiler, the Java virtual machines, and the Java class libraries

  4. Characteristics of Java • „Write once, run everywhere“ • characteristics: • platform independent • OOP language • strongly-typed programming language • interpreted and compiled language • automatic memory management • single inheritance • actively developed via the Java Community Process (JCP) • watchout: Java is case-sensitive!!!

  5. Different Flavors of Java Sun is now offering 3 “editions”: • Java Standard Edition (Java SE) • for general purpose • Java Enterprise Edition (Java EE) • Java SE plus various APIs • Java Micro Edition (Java ME) • optimized run-time environment for consumer products

  6. Java vs. JavaScript Object Oriented Programming languages appeared in 1995 created by Brendam Eich at Netscape created by James Gosling of Sun Microsystem can stand on its own must be placed inside an HTML document to function large, complicated language small, simple set of commands compiled into machine language before it can run on the web directly interpreted by Web Browsers

  7. Architecture of Java Applications • Java applications are written as text files • java compiler creates platform independent code (bytecode) • bytecode can be executed by the java runtime environment • Java Virtual Machine is a program which knows how to run the bytecode on the operating system • JRE translates the bytecode into native code Java code is compiled to produce byte code run by Java Virtual Machine (JVM) to produce results

  8. Java Applications in a Nutshell • Java programs written in a text files with extension “.java” • applications are .java files with a main() method • compile a Java application • javac MyProgram.java • this will result in a file of Java byte code, MyProgram.class • run a Java application • java MyProgram • the Java virtual machine will execute the program in MyProgram.class

  9. Java Virtual Machine Java Source Class file (byte code) Compiler Java Application Java Application Windows JVM Linux JVM Linux Windows

  10. Portability • uniform run-time system • Java Virtual Machine • same interface on different processors • interpreted “assembly language” • Compiler generates instructions for JVM • no implementation dependencies • e.g. define size of types • C++ int could be 32 or 64 bits • in Java size of int is 32 bits on every machine

  11. Robust • simple language • no “pointers” - no direct memory access • strong typing - checked at compile time • run-time bounds & cast checking • exceptions • automatically jump to handler code on error • ensure programmer handles faults

  12. Java Basics • syntax & control structures • if, for, while, do {} while () – like C++ • primitive data types • int, char, short, long, float, double – like C++ • also byte, boolean • compound data types • class: e.g. to represent a person: age, name, … • strings: a normal class holding characters • arrays: a normal class holding a collection of items

  13. Java Program • consists of statements • statements are processed in a certain order and / or in parallel • control structures are used to influence the processing of statements • a statement is the smallest unit which can be processed and is ended with ;

  14. Hello Java! • a simple Java program • the virtual machine will start the main method of this class if called via java HelloWorld class HelloWorld { public static void main (String[] args) { System.out.println(„Hello Java!“); } } • the filename must be equal to the class name • the extension must be .java

  15. Example: Parity Calculation • to detect errors • add extra “parity” bit to 7 data bits • ensure that total number of ones is even • an error will make the total odd • on receipt, count the number of bits • if odd, there has been at least one error • if even, assume no error • cannot detect even number of errors

  16. Parity Calculation: overview set up using System.in // initialisation String inputData = formattedInput.readLine(); int pos = 0; int parityBit = 0; /* Calculate the parity bit */ … if (inputData.length() != 7) System.out.println("There should be 7 bits of input"); else System.out.println("Result: "+inputData+parityBit); a string object can tell you its length and return individual characters System.out is like count

  17. Parity Calculation: main body while (pos < inputData.length()){ char current = inputData.charAt(pos); pos = pos+1; // current position for user (start at 1) switch (current){ case '0': break; case '1': parityBit = 1 - parityBit; // invert parityBit break; default: System.out.println("Invalid input: "+current+" at "+(pos)); } } while, switch, =, if are the same as in C++

  18. Garbage Collection • memory management - major cause of bugs • forget to release memory - lose resources (a leak) • use memory after release - unpredictable contents • release twice – confuse the memory allocator • C++ • explicitly release allocated memory with delete • Java • run-time system scans memory • release blocks not referenced by program

  19. y x Sx Sy five two five Example: Value & Reference int x = 5; int y = 2; x = y; String Sx = new String ("five"); String Sy = new String (“two"); Sx = Sy 5 2 2 Garbage: can’t be reached from the program – could be returned to the run-time system

  20. the child is like the base with extra facilities Base class Inheritance Child Class • a class automatically has the methods and properties of its ancestor (base class) • define new class starting from the ancestor • can add data members • can add methods • can change implementation of methods • a class always inherits from 1 ancestor

  21. What Java Hasn't Got • constants • use 'final' variables - can't be changed • structures • combine related values (e.g. name, age, address) • use classes instead • pointers • however, objects use the reference model: • a field in a object can refer to another object • single byte characters • all characters are Unicode (2 byte)

  22. Summary of Java • great similarities with C++ • uses reference variables not pointers • classes • group data & functions together • inheritance • can define new classes by extension • portability through Virtual Machine • concerned with safety: garbage collection

  23. Sources • http://www.java.com • http://en.wikipedia.org/wiki/Java_(disambiguation) • http://java.sun.com/docs/books/tutorial • http://www.vogella.de/articles/JavaIntroduction • „Encyclopedia of Computer Science“ fourth edition ISBN 0-333-77879-0

  24. Thank you for attention !

More Related