1 / 103

Advanced Java Programming CSE 7345/5345/ NTU 538N

Welcome Back!!!. Advanced Java Programming CSE 7345/5345/ NTU 538N. Session 2. Office Hours: by appt 3:30pm-4:30pm SIC 353. Chantale Laurent-Rice. Welcome Back!!!. trice75447@aol.com. claurent@engr.smu.edu. Introduction. Chapter 1 Course Objectives Organization of the Book.

jara
Télécharger la présentation

Advanced Java Programming CSE 7345/5345/ NTU 538N

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Welcome Back!!! Advanced Java ProgrammingCSE 7345/5345/ NTU 538N Session 2

  2. Office Hours: by appt 3:30pm-4:30pm SIC 353 Chantale Laurent-Rice Welcome Back!!! trice75447@aol.com claurent@engr.smu.edu

  3. Introduction • Chapter 1 • Course Objectives • Organization of the Book

  4. Objectives • Upon completing this chapter, you will understand • Create, compile, and run Java programs • Primitive data types

  5. Book Chapters • Part I: Fundamentals of Programming • Chapter 1 Introduction to Java • Chapter 2 Primitive Data Types and Operations • Chapter 3 Control Statements • Chapter 4 Methods • Chapter 5 Arrays

  6. Book Chapters, cont. • Part II: Object-Oriented Programming • Chapter 6 Objects and Classes • Chapter 7 Strings • Chapter 8 Class Inheritance and Interfaces • Chapter 9 Object-Oriented Software Development

  7. Book Chapters, cont. • Part III: GUI Programming • Chapter 10 Getting Started with GUI Programming • Chapter 11 Creating User Interfaces • Chapter 12 Applets and Advanced GUI

  8. Book Chapters, cont. • Part IV: Developing Comprehensive Projects • Chapter 13 Exception Handling • Chapter 14 Internationalization • Chapter 15 Multithreading • Chapter 16 Multimedia • Chapter 17 Input and Output • Chapter 18 Networking • Chapter 19 Java Data Structures

  9. Chapter 1 • Objectives: • Get an overall perspective of what capabilities and features are encompassed by Java and its development kit. • Take a first look at Java syntax. • Getting Input from Input Dialog Boxes • Style and Documentation Guidelines

  10. What Is Java? • History • Characteristics of Java

  11. What is Java? • An Object-Oriented Programming Language developed at Sun Microsystems • A Virtual Machine (run-time environment) that can be embedded in web browsers (e.g. Netscape Navigator, Microsoft Internet Explorer and IBM WebExplorer) and operating systems. • A set of standardized Class libraries (packages), that support: • Creating graphical user interfaces • Communicating over networks • Controlling multimedia data

  12. History • James Gosling and Sun Microsystems • Oak • Java, May 20, 1995, Sun World • HotJava • The first Java-enabled Web browser • JDK Evolutions • J2SE, J2ME, and J2EE (not mentioned in the book)

  13. Java is simple Object-Oriented Distributed Interpreted Robust Secure Architecture-neutral Portable High-performance Multithreaded dynamic Characteristics of Java

  14. Java is Simple • Java is not just a language for use with the Internet. • It is a full featured Object-Oriented Programming Language (OOPL). • Java is a bit easier than the popular OOP language C++. • Java uses automatic memory allocation and garbage collection.

  15. What is Object-Oriented Programming? • Think of OOP as a set of implementation techniques that • Can be done in any programming language • Are very difficult to do in most programming languages • OOP provides great flexibility, modularity, and reusability.

  16. Java is Distributed • Distributed computing involves several computers working together on a network. • Java’s concurrency features make is unique for developing many interactive and networked applications.

  17. Java is Interpreted • Java Virtual Machine: • Java is compiled to byte-codes whose target architecture is the Java Virtual machine (JVM). • The virtual machine is embeddable within other environments, e.g. web browser and operating systems. • Utilize a byte-code verifier when reading in byte-codes. The class loader is employed for “classes” loaded over the network (enhances security)

  18. Java Virtual Machine • JVM Environment Java Source code .java Java byte-code .class java javac Java VM

  19. Java is Robust • Robust means reliable. • No programming language can ensure complete reliability. • Java puts a lot of emphasis on early checking for possible errors, because Java compilers can detect many problems that would first show up at execution time in other languages. • Java has a runtime exception-handling feature to provide programming support for robustness.

  20. Java Is Architecture-Neutral • Java is interpreted. • JIT compiler • Just-in-time compilers • This provides • Improved performance • Better match to specific hardware

  21. JIT Compiler • JIT- takes byte-codes and change it to machine code. J.I.T. Compiler JVM Running Applet or Application .class file machine code

  22. JIT Compiler • Because of the need for architecture independence, performance tuning must be performed on the client-side. • This client-side compilation is known as Just-In-Time (JIT) compilation.

  23. Portable, Dynamic, Multithreaded, and Extensible .class files • Java runtime based on architecturally-neutral byte-codes (per class). • Multithreading is a program’s capability to perform several tasks simultaneously. interpreted Java Runtime loaded classes (byte-codes) call Native .dll Native .dll

  24. Advantages • Byte-code is a compact machine language form. In Java the target machine is the Java Virtual Machine (VM). • These byte-codes are thus portable across architecture boundaries. • Applets and Applications have “class” files loaded on their behalf in order to execute.

  25. JDK Versions • JDK 1.02 (1995) • JDK 1.1 (1996) • Java 2 SDK v 1.2 (a.k.a JDK 1.2, 1998) • Java 2 SDK v 1.3 (a.k.a JDK 1.3, 2000) • Java 2 SDK v 1.4 (a.k.a JDK 1.4, 2002)

  26. JDK Editions • Java Standard Edition (J2SE) • J2SE can be used to develop client-side standalone applications or applets. • Java Enterprise Edition (J2EE) • J2EE can be used to develop server-side applications such as Java servlets and Java ServerPages. • Java Micro Edition (J2ME). • J2ME can be used to develop applications for mobile devices such as cell phones. This book uses J2SE to introduce Java programming.

  27. Java IDE Tools • Forte by Sun MicroSystems • Borland JBuilder • Microsoft Visual J++ • WebGain Café • IBM Visual Age for Java • IBM Eclipse

  28. Getting Started with Java Programming • A Simple Java Application • Compiling Programs • Executing Applications

  29. Command Line Example 1.1 //This application program prints Welcome //to Java! package chapter1; public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } Source Run

  30. Creating and Compiling Programs • On command line • javac file.java

  31. Executing Applications • On command line • java classname

  32. Command line Example javac Welcome.java java Welcome output:...

  33. Compiling and Running a Program Where are the files stored in the directory?

  34. There are three forms of comments in Java. 1- int i = 10; // i is used as a counter 2- The multiline comment /* This is a comment */  This form of comment may also extend over several lines as shown here: /* This is a longer comment that extends over five lines. */

  35. There are three forms of comments in Java. 3-This is the documentation comment.   /** This is a Java documentation comment */ The advantage of documentation comments is that tools can extract them from source files and automatically generate documentation for your programs. The JDK has a tool named javadoc that performs this function.

  36. Package • The second line in the program (package chapter1;) specifies a package name, chapter1, for the class Welcome. • Forte compiles the source code in Welcome.java, generates Welcome.class, and stores Welcome.class in the chapter1 folder.

  37. Blocks A pair of braces in a program forms a block that groups components of a program.

  38. Block Styles Use end-of-line style for braces.

  39. main Method The main method provides the control of program flow. The Java interpreter executes the application by invoking the main method. The main method looks like this: public static void main(String[] args) { // Statements; }

  40. Displaying Text in a Message Dialog Box • you can use the showMessageDialog method in the JOptionPane class. • JOptionPane is one of the many predefined classes in the Java system, which can be reused. Source Run

  41. The showMessageDialog Method JOptionPane.showMessageDialog(null, "Welcome to Java!", "Example 1.2", JOptionPane.INFORMATION_MESSAGE));

  42. A simple Java Applet import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.awt.Graphics; /* <applet code="FirstApplet" width=200 height=200> </applet> */ public class FirstApplet extends Applet { public void paint(Graphics g) { g.drawString("This is my first applet!", 20, 100); } } See word doc for output.

  43. Integral Literals • Integral literals may be expressed in decimal, octal, or hexadecimal. • The default is decimal. • To indicate octal, prefix the literal with 0 (zero) • To indicate hexadecimal, prefix the literal with 0x or 0X; • the hex digits may be upper-or lowercase.

  44. Integral Literals For example: The value twenty-eight may be expressed the following ways:                 28                034                0x1c                0x1C                0X1c                0X1C

  45. Integral Literals • By default, an integral literal is a 32-bit value. • To indicate a long (64-bit) literal, append the suffix L to the literal expression. • The suffix can be lowercase, but then it looks so much like a one that makes it confusing.

  46. Literals • Literals are explicit data values that appear in your program. • A literal is a value specified in the program source, as opposed to one determined at runtime. Literals can represent primitive or string variables, and may appear on the right side of assignments or in method calls. You cannot assign a value into a literal, so they cannot appear on the left of an assignment. For example: int x = 25;

  47. Boolean Literals • The only literals of boolean type are true and false. For example: 1. boolean isBig = true; 2. boolean isLittle = false;

  48. char Literals A char literal can be expressed by enclosing the desired character in single quotes, For example: char c = ' w ';

  49. Chapter 1 Topic Summary • Java is many things • A concurrent object-oriented programming language • A virtual machine and Web-aware run-time • A powerful and stable set of class libraries.

  50. Chapter 2Liang, Nutshell Objectives: • Introduce Programming with an Example • Identifiers, Variables, and Constants • Primitive Data Types • byte, short, int, long, float, double, char, boolean • Expressions • Operators, Precedence, Associativity, Operand Evaluation Order: ++, --, *, /, %, +=, -=, *=, /=, %=, ^, &, |, +, -, • Syntax Errors, Runtime Errors, and Logic Errors

More Related