tailieunhanh - Lecture Java methods: Object-oriented programming and data structures (2nd AP edition): Chapter 5 - Maria Litvin, Gary Litvin

Chapter 5 - Java syntax and style. This is an important chapter because it explains and contrasts two related aspects of writing code in a high-level programming language: language syntax rules and good programming style. | Java Syntax and Style /** * Chapter 5 */ Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 2nd AP edition with GridWorld 5- This is an important chapter because it explains and contrasts two related aspects of writing code in a high-level programming language: language syntax rules and good programming style. Objectives: Learn to distinguish the required Java syntax from the conventional style Learn when to use comments and how to mark them Review reserved words and standard names Learn the proper style for naming classes, methods, and variables Learn to space and indent blocks of code 5- An unstated objective is to give students some appreciation for what is involved in creating working code and the required level of attention to detail. Comments Comments are notes in plain English inserted in the source code. Comments are used to: document the | Java Syntax and Style /** * Chapter 5 */ Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 2nd AP edition with GridWorld 5- This is an important chapter because it explains and contrasts two related aspects of writing code in a high-level programming language: language syntax rules and good programming style. Objectives: Learn to distinguish the required Java syntax from the conventional style Learn when to use comments and how to mark them Review reserved words and standard names Learn the proper style for naming classes, methods, and variables Learn to space and indent blocks of code 5- An unstated objective is to give students some appreciation for what is involved in creating working code and the required level of attention to detail. Comments Comments are notes in plain English inserted in the source code. Comments are used to: document the program’s purpose, author, revision history, copyright notices, etc. describe fields, constructors, and methods explain obscure or unusual places in the code temporarily “comment out” fragments of code 5- How detailed should comments be? In general, self-documenting, clear code is better than obscure, heavily commented code. Use comments to mark important sections and occasionally explain unexpected twists of logic or use, but do not comment every statement. Sometimes you need to comment out a fragment of code to try a variation or to test the remaining code separately. Formats for Comments A “block” comment is placed between /* and */ marks: A single-line comment goes from // to the end of the line: /* Exercise 5-2 for Java Methods Author: Miss Brace Date: 3/5/2015 Rev. */ weight *= ; // Convert to kilograms 5- Make sure you do not carry a // comment over to the next line. If you do, you need another // mark on that line. Placing // at the beginning of a line .