A Concise and Practical Introduction to Programming Algorithms in Java (Undergraduate Topics in Computer Science)

A Concise and Practical Introduction to Programming Algorithms in Java (Undergraduate Topics in Computer Science)

Frank Nielsen

Language: English

Pages: 252

ISBN: 184882338X

Format: PDF / Kindle (mobi) / ePub


A Concise and Practical Introduction to Programming Algorithms in Java has two main goals. The first is for novice programmers to learn progressively the basic concepts underlying most imperative programming languages using Java. The second goal is to introduce new programmers to the very basic principles of thinking the algorithmic way and turning the algorithms into programs using the programming concepts of Java.

The book is divided into two parts and includes: The fundamental notions of variables, expressions and assignments with type checking - Conditional and loop statements - Explanation of the concepts of functions with pass-by-value arguments and recursion - Fundamental sequential and bisection search techniques - Basic iterative and recursive sorting algorithms.

Each chapter of the book concludes with a set of exercises to enable students to practice concepts covered.

RESTful Java Patterns and Best Practices

Beginning XML (5th Edition)

OCAJP Oracle Certified Associate Java SE 7 Programmer Practice Exams

Java Concepts: Early Objects (7th Edition)

Ivor Horton's Beginning Java

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

return) using the instruction System.out.print. c l a s s VerboseVolumeBox { public s t a t i c void main ( S t r i n g [ ] a r g s ) { System . out . p r i n t ( " Volume of the box ( in cubic meters ):" ) ; System . out . p r i n t l n ( 0 . 5 ∗ 1 ∗ 0 . 2 ) ; } } Compiling and running this program yields the better verbose output: Volume of the box (in cubic meters):0.1 1.3.1 Arithmetic operations and priority order The arithmetic operations used in expressions are: – The addition (+) 1.3

problem, coding the algorithm into a program, and finally, testing the program. Each chapter of the book concludes with a set of exercises that lets students practice notions covered by the chapter. The third part of the book consists of an overall exam that allows readers to evaluate their assimilation level. A solution is provided. Exercises and sections that are recommended to be skimmed through in a first reading are indicated using the mark **. Additional materials, including all Java source

Variables, assignments and type checking 15 1.6.2 Type checking for assignments and casting 1.6.2.1 Type checking. Whenever assigning a variable, the compiler javac checks that the type of the expression coincides with the type of the variable. If not, the compiler reports an error message and aborts (without generating proper bytecode). For example, consider the code below: class TypeError{ public static void main (String[ ] args) { double myFavoriteReal=3.141592; int myFavoriteNat=2.71; } }

n t ( 2 , 1 ) ; n b p o i n t++; q=new P o i n t ( 3 , 4 ) ; n b p o i n t++; Display (p) ; Display (q) ; } } 5.8 Exercises 123 Compiling and running this program, we obtain the following console output: 2 versus (!=) 3 (2,1) (3,4) 5.8 Exercises Exercise 5.1 (A class for storing supermarket product items) In a supermarket, each product is typically labeled with: – (1) a string depicting the product name, – (2) a price tag, and – (3) a date of validity that informs when the product expires.

22 6 9 17 It is a heap: 25 < 37 Figure 8.3 Adding element 25 to the heap: First, add a new node at the first immediate empty position; then eventually swap this node with its parent until the heap property is recovered These basic step operations translate into corresponding operations on the array implicitly encoding the heap as follows: Program 8.4 Adding an element to the heap s t a t i c void addHeap ( i n t element , Heap h ) { h . l a b e l [ h . s i z e ]= e l e m e n t ; h . s i z e

Download sample

Download