1 - Lecture 5: Java Introduction Advanced Programming...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
    Lecture 5: Java Introduction Advanced Programming  Techniques Summer 2003 Lecture slides modified from B. Char
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Java is object oriented Everything belongs to a class (no global  variables, directly). Main program is a static method in the  class that you run with the java  command.
Background image of page 2
    Java is syntactically similar to  C++ Built-in types:  int, float, double, char. Control flow:  if-then-else, for, switch. Comments:  /* . . */ but also // …. (to end of line) Exceptions:  throw …;  try {} catch{}.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Locations of Java code Writing the code . Suppose we have a  program that consists of just one class  foo   and a main procedure that uses it. Write the  main procedure as a static method in that  class .   The source code must  be in a file named  foo.java in your current working directory. Compilation.  Create the file foo.class via the  command javac foo.java
Background image of page 4
    Running java code (default) To execute the main procedure in  foo.class, give the command java foo
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Multi-file definitions If you use several classes foo1, foo2, foo3, …  create several files in the same directory  foo1.java, foo2.java, foo3.java.  Compile each  one.  The compiler will automatically look for  other classes in the same directory. Sometimes the compiler can figure out that  foo1 requires foo2, so that compiling  foo1.java will automatically cause foo2.java to  be compiled… but explicit compilation means  you can be sure that a file has been compiled  or recompiled.
Background image of page 6
    More multi-file definitions import bar; means that  bar.class  should be  consulted to find definitions of  classes/definitions mentioned in the  current file’s programming, such as the  class  bar .
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Classes assembled at  compilation, and at run time Contrast with C or C++ which tends to  collect all classes needed into a single  executable (binary) file, before  execution.
Background image of page 8
    Classpath specified on the  command line Java will look in other directories, and  Java archive files (.jar files) besides the  standard Java system directories and  your current working directory 
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Classpath command line  option for javac or java  specifies a list of directories Separated by semi-colons on Windows javac -classpath .;E:\MyPrograms\jena.jar;E:\utilities   foo1.java   (Windows) Separated by colons on Solaris java -classpath .:/home/vzaychik/jena.jar:/home/vzaychik/utilities  foo1   (Unix)
Background image of page 10
    CLASSPATH environment  variable Value is used if there is no classpath  command option. setenv CLASSPATH .:/pse/:/pse1/corejini: (on 
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/12/2008 for the course CS 265 taught by Professor ... during the Spring '07 term at Drexel.

Page1 / 46

1 - Lecture 5: Java Introduction Advanced Programming...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online