??sa???? st? JAV? ( - PowerPoint PPT Presentation

About This Presentation
Title:

??sa???? st? JAV? (

Description:

Title: Java Tutorial Part 2 Author: Vassilis Papataxiarhis Last modified by: Vassilis Created Date: 1/1/1601 12:00:00 AM Document presentation format – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 23
Provided by: VassilisPa6
Category:
Tags: jav | jdeveloper

less

Transcript and Presenter's Notes

Title: ??sa???? st? JAV? (


1
??sa???? st? JAV?(µ???? ?)
  • ?as???? ?apata???????
  • vpap_at_di.uoa.gr
  • ????µa ??t??e?µe??st?af?? ?????aµµat?sµ??
  • ??d?s???sa ??aµp? ?a????
  • ?µ?µa ?????f?????? ?a? ???ep??????????
  • ?????? ?a? ?ap?d?st??a?? ?a?ep?st?µ?? ??????

2
?e??ss?te?a ??µata st? Java
  • ???? ?a? ??a???se??
  • ?etat??p? ??t??e?µ????
  • ??s?d?? / ???d??
  • Ge???? S????a
  • ???a?e?a ???pt????

3
???? ?a? ??a???se??
  • ?at? t?? e?t??es? µ?a? µe??d?? µp??e? ?a
    p????????? s?????e? ap??ß?epte?.
  • Se a?t?? t?? pe??pt?se?? eµfa?????ta? ????
    (errors) ?a? e?a???se?? (exceptions)
  • ? Java ep?t??pe? a?t?µat? ?e???sµ? t?t???? ?a???
    (automated exception handling)
  • ??a a?t??e?µe?? t?? ???s?? Error d?µ?????e?ta?
    ???? s?µa?t???? ?a??? p?? de? d??ata? ?a
    a?t?µet?p?st??? sta p?a?s?a e??? p?????µµat??

pa??t? java.lang
  • ?.?. NoClassDefFoundError
  • (??a pa??de??µa st?? pe??pt?s? p?? ????? ???ste?
    ????? ?at?????? st? µetaß??t? pe??ß?????t??
    CLASSPATH)

4
??a???se?? (1/2)
  • ??a e?a??es? e??a? ?p???d?p?te ?e?????
    d?ata??sse? t?? ?µa?? e?t??es? e??? p?????µµat??
  • ? µ???d?? st?? ?p??a p???a?e?ta? t? sf??µa
    d?µ?????e? ??a exception object, t? ?p???
    pe????e? p????f???e? ??a t? sf??µa p?? p????????e
    ?a? ?a???µaste ?a t? d?a?e???st??µe runtime.
  • ?? s?st?µa e????e? t? st??ßa ???s??
  • s??a?t?se?? µe s??p? ?a ß?e? ??d??a
  • p?? ?a ???e? handle t? exception p??
  • p??????e.

5
??a???se?? (2/2)
  • ? a?a??t?s? ?e???? ap? t? s????t?s? st?? ?p??a
    p????????e t? sf??µa ?a? ?ata???e? st? main (a?
    p??? de? ß?e?e? handler)
  • ??a? handler e??a? ?at??????? ?a ???e? handle ??a
    exception a? ? t?p?? t?? exception object
    ta?????e? µe t?? t?p? e?a??es?? p?? ? handler
    µp??e? ?a d?a?e???ste?.
  • ?? ß?e?e? ?at??????? handler, t?te e?te?e?ta? ?
    ??d???? t??, d?af??et??? t? p????aµµa
    te?µat??eta?.

6
?e???sµ?? ??a???se??
  • try catch
  • ? ???s? t?? µe??d?? ? e?t??es? t?? ?p??a?
    e?d??eta? ?a p???a??se? µ?a e?a??es? t?p??ete?ta?
    e?t?? t?? µp??? e?t???? try.

try //??d??a? p?? µp??e? ?a //p???a??se?
e?a??es? catch(MyException1 mye1) //
catch(MyException2 mye2) // finally
//
  • ?? µp??? catch pe????e? e?t???? p?? ?a
    d?a?e???st??? t?? e?a??es? p?? p????????e.
  • finally µp??? e?t???? p?? a??????e? t?? catch
    µp??? ?a? pe????e? ??d??a p?? e?te?e?ta? e?te
    s?µße? e?a??es? e?te ???

7
S????e?? ??a???se??
  • NullPointerException ???sp??as? a?t??e?µ????
    null
  • IllegalArgumentException ????? t?p?? ???sµata
  • ArrayIndexOutOfBoundsException ??t?? ?????
    p??a?a
  • ArithmeticException ??a??es? µe t? 0
  • FileNotFoundException ?? a??e?? de? ß?????e st?
    d?s??

8
??e??e?t?µata ?e???sµ?? ??a???se??
  • ??a????sµ?? ??d??a ??a a?a?????s? ?a??? ap? t??
    ?a?????? ??d??a
  • ??a??t?ta d?a?e???s?? t?? e?a??es?? a????????ta?
    t? st??ßa ???s?? µe??d??
  • ???at?t?ta ?e???sµ?? µ?a? e?a??es?? µe
    d?af??et????? t??p???
  • ????? catch µp??? µp????? ?a a?af????ta? st? ?d??
    try µp???
  • ?????te?a ?? e?d???te?e? e?a???se?? st?? ??d??a
  • ???at?t?ta d?µ??????a? ???? ???se?? e?a???se??

9
?etat??p? ??t??e?µ????
  • ? µetat??p? a?t??e?µ???? (type casting) e??a?
    ???s?µ? ?ta? ?????µe ?a d?a?e???st??µe ??a
    a?t??e?µe?? ?? d?af??et???? t?? e??? t?p??
  • ?etat??p?? p??? ta p??? (upcasting)
  • ???ta ep?t?ept??
  • G????ta? µe ap?? a???es?
  • ?etat??p?? p??? ta ??t? (downcasting)
  • ?e? e??a? p??ta ep?t?ept??
  • G????ta? µe ???s? cast te?est?
  • ?p??e? ?a ???e? ?a?????? ? µeta???tt?s? (af?? t?
    cast ?s?? ep?t??peta?), a??? ?a pa?a??e? runtime
    error

10
?a??de??µa
11
??s?d?? / ???d?? (I/O)
  • ? Java ???s?µ?p??e? ???? (streams) ??a ?a
    a?apa?ast?se? p???? e?s?d?? ? p?????sµ??? e??d??
    (p.?. a??e?a st? d?s??, ???a p?????µµata).
  • ??? a???????a ap? ded?µ??a (ap?? bytes µ????
    s???eta a?t??e?µe?a).
  • ??s?d?? / ???d?? se a??e?a d?s???

12
???? ??s?d?? / ???d??
  • ???? ??s?d?? (Input Streams)
  • ??aß????? ??a teµ???? p????f???a? t? f???
  • ???? ???d?? (Output Streams)
  • G??f??? ??a teµ???? p????f???a? t? f???

13
??p?? ???? (1/2)
  • Byte Streams ?/? a??a??et?? t?p?? ded?µ????
  • Character Streams I/O ?a?a?t????
  • Buffered Streams ???s? d?µ?? buffer ??a
    ap?d?t???te?? a????ep?d?as?
  • Scanning and Formatting ??a formatted ?e?µe??

14
??p?? ???? (2/2)
  • I/O from the command line
  • Standard Stream
  • Input p???t???????
  • Output ?????
  • Console
  • Data Streams ??a primitive data types ?a? String
    d?ad???? µ??f??
  • Object Streams ??a ?p????d?p?te t?p?? a?t??e?µe?a

15
Byte Streams
  • ???? p?? d?a?e??????ta? ?aµ???? ep?p?d?? ded?µ??a
  • S????e?? ???? byte
  • FileInputStream/ FileOutputStream
  • ???? ?? ?p????p?? t?p?? ???? ßas????ta? st?? ????
    byte.

16
?/? ap? a??e?a d?s???
  • ?? ???? de? ?p?st??????? ??e? t?? ep???µ?t??
    a????ep?d??se?? µe ta a??e?a p?? ß??s???ta? st?
    d?s??
  • File ?e???sµ?? a??e??? a?e?a?t?t?? p?atf??µa?
    ?a? OS
  • Random Access File ?p?st????e? µ?-a???????a??
    p??sp??as? sta a??e?a

17
?????? ??t??es??
  • Ge????, ? ?????? e?t??es?? e??? java p?????µµat??
    a?aµ??eta? µe?a??te??? e??? ?s?d??aµ?? se ??p??a
    ???? ???ssa p????aµµat?sµ?? (??? ?µ?? ?a? ?
    ?????? a??pt???? ?)
  • ??t?a ? µeta???tt?sµ???? ??a µ?a µ??a?? ??d??a?
    e??a? e? ???e? ta??te??? ap? t?? ??d??a p??
    e?te?e?ta? ap? ??a? interpreter.
  • ?e?t??s? Just-In-Time µeta???tt?s?

18
??p??a ?e?e?ta?a S????a
  • ??? p??????e ? ???? bytecode
  • ?pe?d? ??s?ast??? ap?te?e? µ?a binary
    a?apa??stas? t?? p?????µµat?? p?????sµ??? ?a
    e?te?este? ap? t? JVM (software) ?a? ??? ap? t?
    hardware.
  • Se t? ???ssa e??a? ??aµµ??? ? Java
  • ?? pe??ss?te??? compilers (p.?. t?? Sun) ??a Java
    e??a? p???? ??aµµ???? se Java, a? ?a? a????? ??
    ß?s? ???s?µ?p??????a? ?? ???sse? C/C.
  • Se ?t? af??? t?? JVM a??µa ?a? s?µe?a
    ???s?µ?p????? C (??? ?µ?? ap???e?st???), ??????
    ??a ?????? ap?d?s??. ???µa ?a? JVMs t?? Sun!

19
C vs. Java
C JAVA
CoutltltAnswerltltanswer System.out.println("Answer answer)
cingtgtch chSystem.in.read()
void main() public static void main(String args)
int main(int argc,char argv) public static void main(String args)
const int MAX10 final int MAX10
char str String str
int scoresnew int5 int scoresnew int5
delete scores ??? ?????????? ?
20
???a?e?a ???pt????
  • Eclipse (open source)
  • NetBeans (open source)
  • JDeveloper (Oracle)
  • Visual J (Microsoft)

21
???te???µe?e? ?????
  • Exceptions, http//java.sun.com/docs/books/tutoria
    l/essential/exceptions/index.html
  • Input/Output, http//java.sun.com/docs/books/tutor
    ial/essential/io/
  • Type casting, http//www.janeg.ca/scjp/oper/cast.h
    tml

22
???t?se?? ?
Write a Comment
User Comments (0)
About PowerShow.com