Iti1121 Assignments Synonyms

ITI1121. Introduction to Computing II

Object-oriented programming. Abstraction principles: information hiding and encapsulation. Linked lists, stacks, queues, binary search trees. Iterative and recursive processing of data structures. Virtual machines.

Prerequisite: ITI1120; 3 hours of lecture per week; 3 hours of lab per week; 3 credits.


Documents

Lecture Notes

The slides for the lectures and other documents have been made available on BrightSpace. A mapping between the pages of the different editions of the textbook can be found here.

Laboratories, Assigments and Examinations

The documents for the laboratories and the assignments can be found here.

Instructions for the midterm examination can be found here.

Older versions

You can find previous years slides, sample assignments and exams on professor Turcotte's site.


Questions/Discussions

We are using Piazza for class discussions. The system is meant to get you help fast and efficiently from classmates, the TAs, and myself. Documents will also be posted there.

Please create an account and enroll as soon as possible, and go to our class page.

Presentation on theme: "© Wipro Technologies Talent Transformation Java Programming v2.1Page 1 Java Programming."— Presentation transcript:

1 © Wipro Technologies Talent Transformation Java Programming v2.1Page 1 Java Programming

2 © Wipro Technologies Talent Transformation Java Programming v2.1Page 2 Contents Chapter 1 : Evolution of Java Chapter 2 : Classes and objects Chapter 3 : Packages and interfaces Chapter 4 : Exception Handling Chapter 5 : Multithreading Chapter 6 : Utility classes and interfaces Chapter 7 : Applets Chapter 8 : Event Handling Chapter 9 : I/O Streams Chapter 10 : Swing

3 © Wipro Technologies Talent Transformation Java Programming v2.1Page 3 CHAPTER 1 The Evolution of Java

4 © Wipro Technologies Talent Transformation Java Programming v2.1Page 4 Objectives At the end of this session, you will be able to: Describe the evolution of Java, and the forces that shaped it Describe the basics of a Java Program Describe data types, variables and control structures Define strong typing Define function overloading Describe the new operator Describe Garbage Collection Define references

5 © Wipro Technologies Talent Transformation Java Programming v2.1Page 5 Evolution of Java Smalltalk was the first object-oriented language Smalltalk is a pure object-oriented programming language Smalltalk had a major influence on the design of Java

6 © Wipro Technologies Talent Transformation Java Programming v2.1Page 6 Evolution of Java Java was the brainchild of: –James Gosling –Patrick Naughton –Chris Warth –Ed Frank & –Frank Sheridan Made its appearance in the fall of 1992, and was initially called Oak Was renamed Java in 1995

7 © Wipro Technologies Talent Transformation Java Programming v2.1Page 7 Evolution of Java Was originally meant to be a platform-neutral language for embedded software in devices The goal was to move away from platform and OS-specific compilers The language could be used to produce platform-neutral code

8 © Wipro Technologies Talent Transformation Java Programming v2.1Page 8 Evolution of Java The catalytic role of the World Wide Web in the evolution of Java But for the WWW, the scope of Java would have been restricted to programming devices The emergence of the WWW propelled the rise of Java because the WWW demanded portability

9 © Wipro Technologies Talent Transformation Java Programming v2.1Page 9 Evolution of Java Internet and the World Wide Web presented a heterogeneous platform of diverse CPU architectures and OS’ Need for a portable language gathered increasing pace The scope of the language therefore widened from embedded controllers to the Internet.

10 © Wipro Technologies Talent Transformation Java Programming v2.1Page 10 Java and the Internet Needs of the Internet influencing Java Java, in turn influencing the Internet by rendering it dynamic Java made objects move around on the Internet Internet typically dealt with passive and active content

11 © Wipro Technologies Talent Transformation Java Programming v2.1Page 11 Java: Enabling a Dynamic Internet Java made the Internet the host of dynamic self-executing programs Such a program is an active agent on the client computer, yet it is initiated by the server The scope of a computing platform therefore widened from a client-server network to the Internet and the WWW Thus reinforced Sun Microsystems’ claim of “ The Network is the Computer ”

12 © Wipro Technologies Talent Transformation Java Programming v2.1Page 12 The Java Architecture Bytecode is the key to both security & portability Write source code. Compile to bytecode contained in.class files Bytecode is a highly optimized set of instructions Bytecode executed by the Java Virtual Machine (JVM) The JVM is an interpreter for bytecode.

13 © Wipro Technologies Talent Transformation Java Programming v2.1Page 13 The Java Architecture Source Code Bytecode JVM Operating System Hardware

14 © Wipro Technologies Talent Transformation Java Programming v2.1Page 14 The Java Architecture – The JVM Program Class Files Class Loader Java API classes JVM

15 © Wipro Technologies Talent Transformation Java Programming v2.1Page 15 The Java Architecture – The JVM Most modern languages are designed to be compiled Compilation is a one-time exercise and executes faster Execution of compiled code over the Internet an impossibility Executable code always generated to a CPU-OS combination Interpreting a Java program into bytecode facilitates its execution in a wide variety of environments

16 © Wipro Technologies Talent Transformation Java Programming v2.1Page 16 The Java Architecture – The JVM Only the Java Virtual Machine (JVM) needs to be implemented for each platform Once the Java runtime package exists for a given system, any Java program can run on it. The JVM will differ from platform to platform, and is, platform-specific All versions of JVM interpret the same Java bytecode.

17 © Wipro Technologies Talent Transformation Java Programming v2.1Page 17 The Java Architecture – The JVM Interpreted code runs much slower compared to executable code The use of bytecode enables the Java runtime system to execute programs much faster Java facilitates on-the-fly compilation of bytecode into native code

18 © Wipro Technologies Talent Transformation Java Programming v2.1Page 18 The Java Architecture – The Adaptive Optimizer Another type of execution engine is an adaptive optimizer The virtual machine starts by interpreting bytecodes Monitors the activity of the running program Identifies the most heavily used areas of code As the program runs, the virtual machine compiles to native code Optimizes just these heavily used areas The rest of the code, which is not heavily used, remain as bytecodes which the virtual machine continues to interpret.

19 © Wipro Technologies Talent Transformation Java Programming v2.1Page 19 The Java Architecture - The Class Loader The class loader is that part of the VM that is important from: –A security standpoint –Network mobility The class loader loads a compiled Java source file (.class files represented as bytecode) into the Java Virtual Machine (JVM) The bootstrap class loader loads classes, including the classes of the Java API, in some default way from the local disk

20 © Wipro Technologies Talent Transformation Java Programming v2.1Page 20 The Java Architecture - The Java.class file The Java class file helps make Java suitable for networks mainly in the areas of: –platform independence –network mobility The class file is compiled to a target JVM, but independent of underlying host platforms The Java class file is a binary file that can run on any hardware platform and OS that hosts the Java VM

21 © Wipro Technologies Talent Transformation Java Programming v2.1Page 21 The Java API The Java API files provide a Java program with a –standard –platform-independent interface to the underlying host To the Java program, the API looks the same and behaves predictably irrespective of the underlying platform The internal design of the Java API is also geared toward platform independence

22 © Wipro Technologies Talent Transformation Java Programming v2.1Page 22 The Java Programming Language The Java language allows you to write programs that take advantage of many software technologies: –object-orientation –multithreading –structured error-handling –garbage collection –dynamic linking –dynamic extension

23 © Wipro Technologies Talent Transformation Java Programming v2.1Page 23 The Java Buzzwords Simple –Small language [ large libraries ] –Small interpreter (40 k), but large runtime libraries ( 175 k) Object-Oriented –Supports encapsulation, inheritance, abstraction, and polymorphism. Distributed –Libraries for network programming –Remote Method Invocation Architecture neutral –Java Bytecodes are interpreted by the JVM.

24 © Wipro Technologies Talent Transformation Java Programming v2.1Page 24 The Java Buzzwords Secure –Difficult to break Java security mechanisms –Java Bytecode verification –Signed Applets. Portable –Primitive data type sizes and their arithmetic behavior specified by the language –Libraries define portable interfaces Multithreaded –Threads are easy to create and use Dynamic –Finding Runtime Type Information is easy

25 © Wipro Technologies Talent Transformation Java Programming v2.1Page 25 Functions are the building blocks of a Java program main( ) is the first function to be executed, and has to return a value in Java format return_type function_name(argument list) Prototyping required but variable name not necessary Functions

26 © Wipro Technologies Talent Transformation Java Programming v2.1Page 26 A First Java Program public class Hello{ public static void main(String [] args){ System.out.println(“Hello World”); } Compilation-javac Hello.java Execution-java Hello

27 © Wipro Technologies Talent Transformation Java Programming v2.1Page 27 Hello.java javac Hello.java Hello.class Class Loader Bytecode Verifier Interpreter Hardware Runtime A First Java Program

28 © Wipro Technologies Talent Transformation Java Programming v2.1Page 28 Language Basics Keywords Variables Conditional Statements Loops Data Types Operators Coding Conventions

29 © Wipro Technologies Talent Transformation Java Programming v2.1Page 29 Data Types Integer –int 32 bits –long64 bits –short 16 bits –byte 8 bits Character –char 16 bits, UNICODE Character –String (is an object in Java) Floating Point –float 32 bits –double 64 bits Boolean –true false

30 © Wipro Technologies Talent Transformation Java Programming v2.1Page 30 Range of Values for Integers Name / Type Length Range byte int short long 8 bits 16 bits 32 bits 64 bits -2 7 to 2 7 -1 -2 15 to 2 15 -1 -2 31 to 2 31 -1 -2 63 to 2 63 -1

31 © Wipro Technologies Talent Transformation Java Programming v2.1Page 31 Floating Point - float and double Floating point literal includes either a decimal point or one of the following: –E or e (add exponential value) –F or f (float) –D or d (double) 3.14 A simple floating-point value (a double) 6.02E23 A large floating-point value 2.718F A simple float size value 123.4E+306D A large double value with redundant

32 © Wipro Technologies Talent Transformation Java Programming v2.1Page 32 Declaring Arrays Group data objects of the same type. Declare arrays of primitive or class types. –char s[];orchar [] s; –Point p[];orPoint [] p; Create space for reference. An array is an object, not memory reserved for primitive types. Use the new keyword to create an array object. –s = new char[20]; –p = new Point[100]; p[0] = new Point(); p[1] = new Point();

33 © Wipro Technologies Talent Transformation Java Programming v2.1Page 33 Array Initialization & Multidimensional Arrays Create an array with initial values String names[] = new String[3]; names [0] = “Jack”; names [1] = “Jill”; names [2] = “Tom”; MyClass array[] = {new MyClass(), new MyClass()}; Arrays of arrays : –int twoDim [] [] = new int [4] []; –twoDim [0] = new int [5]; –twoDim [1] = new int [5]; –int twoDim [] [] = new int [] [5];// illegeal

34 © Wipro Technologies Talent Transformation Java Programming v2.1Page 34 Array Bounds, Array Resizing, & Array Copying All array subscripts begin with 0: int list [] = new int [10] for (int i = 0; i< list.length; i++)System.out.println(list[i]); Can not resize an array. Can use the same reference variable to refer to an entirely new array –int elements [] = new int [5]; –elements = new int [10]; The System.arraycopy() method: –int elements [] = {1, 2, 3, 4, 5, 6}; –int hold [] = {10,9,8,7,6,5,4,3,2,1}; –System.arraycopy(elements,0,hold,0,elements.length);

35 © Wipro Technologies Talent Transformation Java Programming v2.1Page 35 String Is not a primitive data type; it is a class Has its literal enclosed in double quotes (" ") –“A stitch in time saves nine" Can be used as follows: –String greeting = "Good Morning !! \n"; –String errorMessage = "Record Not Found !";

36 © Wipro Technologies Talent Transformation Java Programming v2.1Page 36 Strong Typing Java is a strongly typed language The Java compiler enforces type checking of each assignment made in a program at compile time Code is type checked If the type checking fails, then a compile- time error is issued Strong typing facilitates two functions of the same name to coexist Distinguishes between calls to these functions based on their signatures

37 © Wipro Technologies Talent Transformation Java Programming v2.1Page 37 Function Signature & Overloading A function signature constitutes the function name, the number, order and the data type of the arguments Such functions are said to be overloaded. Calls to an overloaded function are resolved using function signatures Overloaded functions are differentiated based on their signature

38 © Wipro Technologies Talent Transformation Java Programming v2.1Page 38 The final Keyword Mechanisms of telling the compiler that a piece of data is “constant” A constant is useful for two reasons: –It can be a compile-time constant that will never change –It can be a value initialized at runtime that you don’t want changed. A variable can be declared as final Doing so prevents its contents from being modified

39 © Wipro Technologies Talent Transformation Java Programming v2.1Page 39 Final Variables Implies that you must initialize a final variable when it is declared –final float pi = 3.142857; Subsequent parts of your program can now use pi as a constant Variables declared as final do not occupy memory on a per instance basis Thus a final variable is essentially a named constant.

40 © Wipro Technologies Talent Transformation Java Programming v2.1Page 40 Object References Obtaining objects of a class is a two-step process. –First you must declare a variable of the class type –This variable does not define an object. –Instead, it is simply a variable that can refer to an object. –Or, simply an object reference. –Second, you must acquire an actual, physical copy of the object –Assign the address or reference of that object to that variable –You can do this using the new operator.

41 © Wipro Technologies Talent Transformation Java Programming v2.1Page 41 Object References The new operator –dynamically allocates memory for an object – creates the object on the heap or free store –returns a reference to it –This reference is, the address of the object allocated by new The reference is then stored in the variable Thus, in Java –all objects must be dynamically allocated – stored on the heap

42 © Wipro Technologies Talent Transformation Java Programming v2.1Page 42 Summary At the end of this session, you learnt to: Describe the evolution of Java, and the forces that shaped it Describe the basics of a Java Program Describe data types, variables and control structures Define strong typing Define function overloading Describe the new operator Describe Garbage Collection Define references

43 © Wipro Technologies Talent Transformation Java Programming v2.1Page 43 CHAPTER 2 Classes and Objects

44 © Wipro Technologies Talent Transformation Java Programming v2.1Page 44 Objectives At the end of this session, you will be able to: Define a class Describe the access modifiers, namely public and private Create objects based on classes Define constructors Describe the ‘this’ reference Define static class members

45 © Wipro Technologies Talent Transformation Java Programming v2.1Page 45 Defining a Sample point Class class point { int x_coord; int y_coord; void setx( int x) { x_coord = (x > 79 ? 79 : (x < 0 ? 0 :x)); } void sety (int y) { y_coord = (y < 24 ? 24 : (y < 0 ? 0 : y)); } int getx( ) { return x_coord; } int gety( ) { return y_coord;} }

Categories: 1

0 Replies to “Iti1121 Assignments Synonyms”

Leave a comment

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *