Kickstart Intro to Java Part I - PowerPoint PPT Presentation

kickstart intro to java part i n.
Skip this Video
Loading SlideShow in 5 Seconds..
Kickstart Intro to Java Part I PowerPoint Presentation
Download Presentation
Kickstart Intro to Java Part I

play fullscreen
1 / 16
Download Presentation
Kickstart Intro to Java Part I
Download Presentation

Kickstart Intro to Java Part I

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Kickstart Intro to JavaPart I COMP346/5461 - Operating Systems Revision 1.6 February 9, 2004 Serguei A. Mokhov,

  2. Topics • Me, Myself, and I • Why Java 1.2.*? • Setting Up the Environment • Buzz about Java • Java vs. C++ • Basic Java Syntax • Compiling and Running Java Programs • Example(s) • Next Tutorial • References Serguei A. Mokhov,

  3. Me, Myself, and I • Name: Serguei Mokhov, for simplicity just Serguei, no “Sir”s please!!! :-) • E-mail: mokhov@cs - maybe the best way to reach me. Questions are welcome (but please allow some time to reply - I’m only one and you’re so many :-) ). • My Course web page for COMP346/546: Serguei A. Mokhov,

  4. Setting Up the Environment • Please, refer to the separate set of slides for Java version and setting up environment. Serguei A. Mokhov,

  5. Why is Java sooo co0OL??? • “Dear Serguei, you promised an Intro to Java!!” • Here it goes: Java is a quite simple, OO, distributed, interpreted, robust and secure, platform and architecture independent, multithreaded and dynamic language. • A bunch of buzzwords? No, they aren’t buzzwords, it’s just an incomplete summary of the features of the language. Serguei A. Mokhov,

  6. Java vs. C/C++ • Java’s syntax is very similar to that of C/C++; thus, it is quite easy to learn for C/C++ programmers. • However, there are some conceptual differences behind this syntactical similarity, which you should pay close attention to. Serguei A. Mokhov,

  7. Java vs. C/C++ (2) • Java • is pure OO language unlike C/C++. • has everything as an object with and exception of few primitive data types (int, float, etc.). • uses two-byte (16 bit) Unicode characters. • has well defined and sometimes mandatory to use the Exception Handling Mechanism (will be covered later). • has automatic garbage collection. Serguei A. Mokhov,

  8. Java vs. C/C++ (3) • Java DOESN’T have • Multiple inheritance (well, it somewhat does through interfaces and, but this is not a true inheritance). • Templates. Vast majority of objects inherit from the Object class or its descendants (implicitly or explicitly), so any object can be cast to the Object class. • Pointers, only references. All objects manipulated by reference by default in Java, not like in C++. So, there is no & in the syntax for function parameters. • Operator overloading • Some others… Serguei A. Mokhov,

  9. Java Program Structure • Since Java is a pure OO language even the main() function has to be defined in a class. • An instance of the class, which defines main(), will be the main thread when run. • There should be only one public class with main in a file and the file name must be the same (including capitalization and spelling) as the main class’ name plus the .java extension. • In general: one (any) public class per file. It is possible to have more than one class defined within one .java file, but only one of them should be public and the file name should correspond to that, public, class name. • When a java program compiled with no errors with javac, a JVM object code is produced and stored in .class files. One file per class. Serguei A. Mokhov,

  10. Java Program Structure (2) • main() • Declaration:public static void main(String argv[]){ … } • The argv is a list of arguments passed via command line, just like in C/C++. • There is noargc in Java for a reason we’ll see in a moment. • Note, unlike in C/C++, there’s no return value that you have to explicitly pass back using the return <int>; statement. Use System.exit(<int>); instead. Serguei A. Mokhov,

  11. Examples • Immortal Hello World Application Note, a java file must be named as public class HelloWorld { public static void main(String argv[]) { System.out.println(“Hello dear World! It’s me again!”); }} Serguei A. Mokhov,

  12. Examples (2) • Command Line Arguments public class ShowArguments { public static void main(String argv[]) { for(int i = 0; i < argv.length; i++) System.out.println(“Arg[“ + i + ”]: ” + argv[i]); }} A public property of an array object Simple string concatenation with “+” Serguei A. Mokhov,

  13. Compiling and Running a Java Application • Command line compiler: javacjavac • To run the compiled code you have to invoke JVM to interpret it:java HelloWorld(Note: no extension this time, just the name of the main class!) Serguei A. Mokhov,

  14. On-line Tutorial • Sun’s Tutorial on Java: • Material for the course: • Getting Started • Learning the Java Language • Essential Java Classes, especially Thread and Object • Collections • For your own pleasure and enjoyment: • Everything else :-) Serguei A. Mokhov,

  15. Next Tutorial • Arrays • Exception Handling • Basics of Inheritance in Java • Threads and Scheduling • More Examples • Whatever I forgot to mention above and your questions. Serguei A. Mokhov,

  16. Links and References • Official Java site: • Java in a Nutshell, Second Edition by David Flanagan, (C) 1997 O’Reily & Associates, Inc. ISBN: 1-56592-262-X • Past semester’s stuff from Paul and Tony on Dr. Aiman Hanna’s web site: • Manual pages for ssh, vim, [x]emacs, pico Serguei A. Mokhov,