Docsity

Java Programming Language, Slides of Java Programming

Partial preview of the text

Download Java Programming Language and more Slides Java Programming in PDF only on Docsity!

Programming Language - JAVA

Topics to cover Basic Java, Objects, Classes, Inheritance,Interfaces, Exceptions, I/O Applets, GUI Programming, Eventhandling Multithreading, Basic Networking Packages, Libraries Some advanced topics, like collections,database, XML, etc. (If possible)

Textbook ^ No required textbook ^ Most of the information you need can be found online,especially at http://java.sun.com ^ Tutorials and code camp:http://java.sun.com/learning/tutorial/index.html ^ Java API specification:http://java.sun.com/j2se/1.4.2/docs/api/index.html^ 

Important one! Should visit often when coding

A word about learning a programminglanguage PRACTICE PRACTICE … PRACTICE …

road map today Brief intro to Java Develop and compile environment A simple example Intro to object/class Java basics Differences from C

Java is portable,  As long as

there is a JVM compiled for

that particular processor and OS Typical program, like C or C++, iscompiled for a particular processorarchitecture and OS. “Write once, run everywhere!”^ Sun’s motto for Java

Bottom line: slow but safe ^ Not suitable for high-performance computation^ 

Scientific computation, games, OS kernel Compiled to byte codes of JVM, not native machinelanguage instructions New release of Java is improving the speed a lot^ ^ Just-in-time (JIT) compiler: convert byte codes to nativemachine language on the fly ^ Very safe^ 

No pointer Automatic garbage collection Check array access bound

Getting and using java ^ J2SDK freely download from http://java.sun.com ^ “Your first cup of Java”:^ 

detailed instructions to help you run your first program  http://java.sun.com/docs/books/tutorial/getStarted/cupojava/index.html ^ All text editors support java^ 

Vi/vim, emacs, notepad, wordpad  Just save to .java file ^ Have IDEs that comparable to Visual Studio^ 

JCreator (simple)  Eclipse (more complicated)

Compile and run an application Write java class Foo containing a main()method and save in file “Foo.java”^ 

The file name

MUST

be the same as class

name Compile with: javac Foo.java Creates compiled .class file: Foo.class Run the program: java Foo^ 

Notice: use the class name directly, no .class!

About class Fundamental unit of Java program All java programs are classes Each class define a unique kind of object( a new data type) Each class defines a set of fields, methodsor other classes  public

: modifier. This class is publicly available and anyone can use it.

Things to notice Java is

case sensitive

 whitespace

doesn’t matter for compilation

File name must be the same as one of theclass names,

including capitalization

At most one public class per file If there is one public class in the file, thefilename must be the same as it Generally one class per file