background preloader

Java - Cours de Tim

Facebook Twitter

Javanotes 7.0. Javanotes 7.0 Table of Contents. Javanotes 7.0 Preface. Introduction to Programming Using Java Version 7.0, August 2014 Introduction to Programming Using Java is a free introductory computer programming textbook that uses Java as the language of instruction.

Javanotes 7.0 Preface

It is suitable for use in an introductory programming course and for people who are trying to learn programming on their own. There are no prerequisites beyond a general familiarity with the ideas of computers and programs. There is enough material for a full year of college-level programming. Chapters 1 through 7 can be used as a textbook in a one-semester college-level course or in a year-long high school course. The Seventh Edition of the book covers "Java 7. " The home web site for this book is The page at that address contains links for downloading a copy of the web site and for downloading PDF versions of the book. Overview: The Mental Landscape. Chapter 1 When you begin a journey, it's a good idea to have a mental map of the terrain you'll be passing through.

Overview: The Mental Landscape

The same is true for an intellectual journey, such as learning to write computer programs. In this case, you'll need to know the basics of what computers are and how they work. The Fetch and Execute Cycle: Machine Language. Section 1.1 A computer is a complex system consisting of many different components.

The Fetch and Execute Cycle: Machine Language

But at the heart -- or the brain, if you want -- of the computer is a single component that does the actual computing. This is the Central Processing Unit, or CPU. Asynchronous Events: Polling Loops and Interrupts. Section 1.2 The CPU spends almost all of its time fetching instructions from memory and executing them.

Asynchronous Events: Polling Loops and Interrupts

However, the CPU and main memory are only two out of many components in a real computer system. A complete system contains other devices such as: The Java Virtual Machine. Section 1.3 Machine language consists of very simple instructions that can be executed directly by the CPU of a computer.

The Java Virtual Machine

Almost all programs, though, are written in high-level programming languages such as Java, Fortran, or C++. A program written in a high-level language cannot be run directly on any computer. First, it has to be translated into machine language. Fundamental Building Blocks of Programs. Section 1.4 There are two basic aspects of programming: data and instructions.

Fundamental Building Blocks of Programs

To work with data, you need to understand variables and types; to work with instructions, you need to understand control structures and subroutines. You'll spend a large part of the course becoming familiar with these concepts. A variable is just a memory location (or several consecutive locations treated as a unit) that has been given a name so that it can be easily referred to and used in a program. Objects and Object-oriented Programming. Section 1.5 Programs must be designed.

Objects and Object-oriented Programming

No one can just sit down at the computer and compose a program of any complexity. The discipline called software engineering is concerned with the construction of correct, working, well-written programs. The Modern User Interface. Section 1.6 When computers were first introduced, ordinary people -- including most programmers -- couldn't get near them.

The Modern User Interface

They were locked up in rooms with white-coated attendants who would take your programs and data, feed them to the computer, and return the computer's response some time later. When timesharing -- where the computer switches its attention rapidly from one person to another -- was invented in the 1960s, it became possible for several people to interact directly with the computer at the same time. On a timesharing system, users sit at "terminals" where they type commands to the computer, and the computer types back its response. Early personal computers also used typed commands and responses, except that there was only one person involved at a time. Javanotes 7.0, Section 1.7. Section 1.7 Computers can be connected together on networks.

Javanotes 7.0, Section 1.7

A computer on a network can communicate with other computers on the same network by exchanging data and files or by sending and receiving messages. Computers on a network can even work together on a large computation. Today, millions of computers throughout the world are connected to a single huge network called the Internet. New computers are being connected to the Internet every day, both by wireless communication and by physical connection using technologies such as DSL, cable modems, and Ethernet. <== Parties faites Parties à faire ==> Javanotes 7.0, Quiz on Chapter 1. Programming in the Small I: Names and Things. Chapter 2 On a basic level (the level of machine language), a computer can perform only very simple operations.

Programming in the Small I: Names and Things

A computer performs complex tasks by stringing together large numbers of such operations. Such tasks must be "scripted" in complete and perfect detail by programs. Creating complex programs will never be really easy, but the difficulty can be handled to some extent by giving the program a clear overall structure. The design of the overall structure of a program is what I call "programming in the large. " Programming in the small, which is sometimes called coding, would then refer to filling in the details of that design. The Basic Java Application. Section 2.1 A program is a sequence of instructions that a computer can execute to perform some task. A simple enough idea, but for the computer to make any use of the instructions, they must be written in a form that the computer can use.

This means that programs have to be written in programming languages. Programming languages differ from ordinary human languages in being completely unambiguous and very strict about what is and is not allowed in a program. The rules that determine what is allowed are called the syntax of the language. Variables and the Primitive Types. Section 2.2 Names are fundamental to programming. In programs, names are used to refer to many different sorts of things. In order to use those things, a programmer must understand the rules for giving names to them and the rules for using the names to work with them. That is, the programmer must understand the syntax and the semantics of names. According to the syntax rules of Java, the most basic names are identifiers. N n rate x15 quite_a_long_name HelloWorld No spaces are allowed in identifiers; HelloWorld is a legal identifier, but "Hello World" is not.

<== Parties faites Parties à faire ==> Strings, Classes, Objects, and Subroutines. Section 2.3 The previous section introduced the eight primitive data types and the type String. There is a fundamental difference between the primitive types and String: Values of type String are objects. While we will not study objects in detail until Chapter 5, it will be useful for you to know a little about them and about a closely related topic: classes.

This is not just because strings are useful but because objects and classes are essential to understanding another important programming concept, subroutines. Javanotes 7.0, Section 2.4. Section 2.4 We have seen that it is very easy to display text to the user with the functions System.out.print and System.out.println. But there is more to say on the topic of outputting text. Furthermore, most programs use data that is input to the program at run time, so you need to know how to do input as well as output. This section explains how to get data from the user, and it covers output in more detail than we have seen so far. It also has a section on using files for input and output. Javanotes 7.0, Section 2.5. Section 2.5 This section takes a closer look at expressions.

Recall that an expression is a piece of program code that represents or computes a value. An expression can be a literal, a variable, a function call, or several of these things combined with operators such as + and >. The value of an expression can be assigned to a variable, used as a parameter in a subroutine call, or combined with other values into a more complicated expression. (The value can even, in some cases, be ignored, if that's what you want to do; this is more common than you might think.) The basic building blocks of expressions are literals (such as 674, 3.14, true, and 'X'), variables, and function calls.

The Math class also contains a couple of mathematical constants that are useful in mathematical expressions: Math.PI represents π (the ratio of the circumference of a circle to its diameter), and Math.E represents e (the base of the natural logarithms). Programming Environments. Javanotes 7.0, Exercises for Chapter 2. This page contains several exercises for Chapter 2 in Introduction to Programming Using Java. For each exercise, a link to a possible solution is provided. Each solution includes a discussion of how a programmer might approach the problem and interesting points raised by the problem or its solution, as well as complete source code of the solution. Javanotes 7.0, Quiz on Chapter 2. <== Parties faites Parties à faire ==> Programming in the Small II: Control. Chapter 3. Blocks, Loops, and Branches. Javanotes 7.0, Section 3.2. The while and do..while Statements. Javanotes 7.0, Section 3.4. Javanotes 7.0, Section 3.5. Javanotes 7.0, Section 3.6. Introduction to Exceptions and try..catch.

Javanotes 7.0, Section 3.8. Introduction to GUI Programming. Javanotes 7.0, Exercises for Chapter 3. Javanotes 7.0, Quiz on Chapter 3. Programming in the Large I: Subroutines. Programming in the Large II: Objects and Classes. Introduction to GUI Programming. Javanotes 7.0, Chapter 7. Javanotes 7.0, Section 7.1. Correctness, Robustness, Efficiency. Linked Data Structures and Recursion. Generic Programming and Collection Classes. Advanced Input/Output: Streams, Files, and Networking.

Threads and Multiprocessing. Advanced GUI Programming. Javanotes Source Code. Javanotes Glossary. Javanotes Version 7. Les meilleurs cours et tutoriels pour apprendre JAVA. Ref 01 : Tutoriel pour bien débuter en Java. Penser en Java 2nde édition.