Εισαγωγη Στη Java

download Εισαγωγη Στη Java

of 105

  • date post

    13-Oct-2015
  • Category

    Documents

  • view

    8
  • download

    0

Embed Size (px)

description

Εισαγωγη Στη Java Ε.Μ.Π

Transcript of Εισαγωγη Στη Java

  • / ,

    JAVA

  • 1. 1 1.1 Java 1.2 Java 1.3 Java Applet 1.4 Internet Java 2. 5 2.1 Java 2.2 Java 2.3 Java 2.4 (Inheritance) 2.5 (overloading) 2.6 (constructors) 2.7 (Finalization) 2.8 (access specifiers) 2.9 (Modifiers) 2.10 Casting 2.11 2.12 (Polymorfism) 2.13 (Interfaces) 2.14 (Packages) 3. - - 19 3.1 Java 3.2 , literals, , 3.3 3.4 (Strings) 3.5 3.6 4. (Exceptions) 31 5. Applets Java 33 5.1 Applets 5.2 Applets Web 5.3 , X 5.3.1 Graphics 5.3.2 Fonts 5.3.3 Color 5.3.4 6. Threads 41 6.1 Threads 6.2 H Threads 6.3 Threads Applets 6.4 Threads

  • 6.5 Threads 7. Abstract Windowing Toolkit (AWT) 47 7.1 GUI 7.2 GUI 7.3 GUI (GUI Events) 7.4 Adapter 7.5 applet EQ 8. Swing (Swing GUIs) 59 8.1 Top-Level Swing Containers Components 8.2 Event Handlers 8.3 Swing Threads 8.3.1 invokeLater 9. Animation Java 69 9.1 Animation 9.2 animation loop 9.3 animation 9.4 10. / Streams 75 10.1 10.2 System 10.3 System 10.4 DataInput Stream 10.5 DataOutput Stream 11. Java 78 11.1 Uniform Resource Locator (URL) 11.1.1 URL (relative) 11.1.2 URL 11.1.3 MalformedURLException 11.1.4 URL 11.1.5 URL 11.1.6 URL 11.1.7 URLConnection 11.1.8 URLConnection 11.2 Sockets 86 11.2.1 Client Server 11.2.2 Client Server TCP sockets 11.2.3 Socket 11.2.4 ServerSocket 11.2.5 Datagrams 11.2.6 UDP Datagrams 11.2.7 DatagramSocket 11.2.8 DatagramPacket

  • Java 1

    1. Internet World-Wide Web . Java, Sun microsystems TM. Java . Java ( C++). applets (applet =

    HTML Web Browser). Interpreted . java compiler

    (bytecode) . interpreter (=) bytecode . java bytecodes , , java interpreter. java bytecode , ( Kilobytes). .

    (distributed). Java . sites.

    (secure). - , ' Java applet .

    multithreaded. Java threads. , Java runtime system (interpreter) (scheduler), threads . .

    multimedia . Java multimedia . .

    1.1 Java Java Java 2 Platform Standard Edition (J2SE), Sun microsystems. Java J2SE Java 2 5.0. javac compiler Java. command-line : javac

    . javac , . : .class.

    java interpreter Java. : java , java myClass java myClass.class.

    javaw ( Windows 95/NT) java shell .

    jdb Java debuger. javah C files stub files .

    C, .

    javap Java disassembler. javadoc documentation.

    .

  • Java 2

    appletviewer applets Java. stand-alone , , appletviewer java javaw.

    1.2 Java Java (stand-alone application). HelloWorldApp.java : /** * The HelloWorldApp class implements an application that * simply displays "Hello World!" to the standard output. */ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); //Display the string. } } Compile Java compiler: javac HelloWorldApp.java compiler HelloWorldApp.class

    Java interpreter: java HelloWorldApp "Hello World!" 1.3 Java Applet

    Java applet. HelloWorld.java : import java.applet.Applet; import java.awt.Graphics; public class HelloWorld extends Applet { public void paint(Graphics g) { g.drawString("Hello world!", 50, 25); } } Compile Java compiler: javac HelloWorld.java compiler HelloWorld.class HTML Hello.html Applet. directory HelloWorldApp.class.

  • Java 3

    A Simple Program Here is the output of my program: HTML Java-enabled browser Internet Explorer "Hello World!" browser. 1.4 Internet Java Internet Java. Java Tutorial: http://java.sun.com/docs/books/tutorial/ . . Java API : http://java.sun.com/j2se/1.5/docs/api/index.html Java. Application Programming Interface Java (Java API) Java (), . Java Platform: http://java.sun.com/j2se/1.5.0/download.jsp Java 1.1. Java. JRE (Java Runtime Environment) Web Browser . JRE Web Browser java applets.

  • Java 4

  • Java 5

    2.

    , (OOP - Object Oriented Programming), . OOP (objects) () . user interfaces ...

    User Interface - 1 User Interface - 2

    Us . 2 UI ( ). , UI 2 UI . (class) . - . - , (instances) instantiation. ' . . ( ). 2.1 JAVA

    < > ... , main() C. , , . interpreter . : JAVA.

  • Java 6

    2.2 JAVA

    . . ` C PASCAL. instance variables . structure C structures. ( ) , . C. , ( - ), - . : .(); .. mycar.startEngine(); structure C. . . OOP. . . interface . implementation hiding data abstraction. . 2.3 JAVA

    java structure C. : class { ; () { } ; () { }

  • Java 7

    ... } .. class Apple { int num_of_vitamins; // int countVitamins() { // return num_of_vitamins; } Vitamins v1, v2, v3; // Vitamin getVitamin(int num) { // return ....; } } num_of_vitamins int. java ( int, float, char ), . Vitamins v1, v2, v3 Vitamin ( ) . . . . . (debugging). class test { float add2Accum(float f) { // Add to accumulator. return (Accumulator += f); } float Accumulator = 0.0; // The accumulator. } ( primitive types) java, (statements) , . 2.4 (inheritance) . " ". (instances) . . , extends : java : class A { int a; void add(int x) { a += x;} }

  • Java 8

    class B extends A { // 'a' 'void add(int x) {...}' . int prev; void sub(int x) { prev = a; a -= x; } } a void add(int x). . . ' ( ). .. class B extends A { int square() { return a*a; } void increaseBy1() { add(1); } } . : class B extends A { a : float; // . void add(int x) { // add(int x). // overriding. a = a + ((float) x); print(a); } } , , (overriding) / / . override , . . , (), (subclass) . (superclass) . subclassing. . . . ..

    class A

    class B

    class C

    class D

  • Java 9

    superclass D. superclass C, superclass C! ( ). B, D subclasses A, C subclass . C . overriding / .... C override ' . - 1 Object compiler ( ). :

    class Object (*)

    class A

    class B

    class C

    class InputStream (*) class Socket (*)

    class mySocket class D

    (*) compiler A, B, C, D, mySocket . - 2 ( this super) - (overrides) . subclass . .. class A { void doSomething() { ...... } } class B extends A { void doSomething() { // "" (overrides) ........ // doSomething() . } } A o1; B o2; o1.doSomething(); // doSomething() . o2.doSomething(); // doSomething() .

  • Java 10

    ( C) doSomething() , , ' . java . , , - super . override, ( doSomething()), : super.doSomething(); java super this () . this : ) . class A { int a; void set(int a) { this.a = a; } } ) . . class A { void make_a_new_object() { B tmp; // create a new instance of B and store it in tmp. // Then give tmp a pointer to you. tmp.owner(this); } } 2.5 (overloading) , . class number { int a; void add(int x) { a += x; } void add(float f) { a += ((int) f); } void add(number n) { a += n.get_a(); } int get_a() { return a; } }

  • Java 11

    void add(...) (3) . (overloa