Indentation & Readability. What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println(

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Classes  All code in a Java program is part of a class  A class has two purposes  Provide functions to do work for the programmer  Represent data.
IT151: Introduction to Programming
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects.
Your First Java Program: HelloWorld.java
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
BASIC JAVA. Hello World n // Hello world program public class MyFirstJavaProgram { public static void main(String args[]) { char c = 'H'; String s =
Random (1) Random class contains a method to generate random numbers of integer and double type Note: before using Random class, you should add following.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
16-Aug-15 Java Puzzlers From the book Java Puzzlers by Joshua Bloch and Neal Gafter.
Announcements Quiz 2 Grades Posted on blackboard.
Computer Programming Lab(5).
Hello AP Computer Science!. What are some of the things that you have used computers for?
2.2 Information on Program Appearance and Printing.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
Basics Programming Concepts. Basics A computer program is a set of instructions to tell a computer what to do Machine language = circuit level language.
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Chapter 2: Java Fundamentals
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
A First Look at Java Chapter 2 1/29 & 2/2 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Input/Output in Java. Output To output to the command line, we use either System.out.print () or System.out.println() or System.out.printf() Examples.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) public static void main(String[]
Anatomy.1 Anatomy of a Class & Terminology. Anatomy.2 The Plan Go over MoveTest.java from Big Java Basic coding conventions Review with GreeterTest.java.
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
JAVA Programming “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Hello Computer Science!. Below is an example of a Hello World program in JAVA. While it is only three lines of code, there are many things that are happening.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
Announcements Final Exam: TBD. Static Variables and Methods static means “in class” methods and variables static variable: one per class (not one per.
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects 1. How is a class different from an object?
CS001 Introduction to Programming Day 6 Sujana Jyothi
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
8/2/07. >>> About Me Scott Shawcroft * Junior * Computer Engineering * Third Quarter TA * Creative Commons Intern * Small-time Open Source Developer
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
Staples are our staple Building upon our solution.
Introduction to programming in java
Computer Programming Your First Java Program: HelloWorld.java.
Chapter 2 Clarifications
Chapter 1 Introduction to Computers, Programs, and Java
Exercise Java programming
using System; namespace Demo01 { class Program
USING ECLIPSE TO CREATE HELLO WORLD
Introduction to programming in java
Maha AlSaif Maryam AlQattan
Something about Java Introduction to Problem Solving and Programming 1.
TO COMPLETE THE FOLLOWING:
Tonga Institute of Higher Education
Java Intro.
Code Animation Examples
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Anatomy of a Java Program
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Scope of variables class scopeofvars {
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Methods (a.k.a functions)
Presentation transcript:

Indentation & Readability

What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); }

What does this program do? public class Hello2{public static void main(String[] args){System.out.println( “Welcome.");System.out.println();int i=12;System.out.println("i is equal to "); System.out.println(i);System.out.println("Bye."); }}

Which do you prefer (to see on an exam)? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); } public class Hello2{public static void main(String[] args){System.out.println("Welcome.") ;System.out.println();int i=12;System.out.println( "i is equal to" );System.out.println(i);System.out.println ("Bye.");}} Stream of Consciousness

Which do you prefer (to see on an exam)? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); } public class Hello2{ public static void main( String[] args) { System.out.println( "Welcome."); System.out.println();int i=12; System.out.println( "i is equal to" );System.out.println(i);System.out.println ("Bye.");} } Random Indentation

Which do you prefer (to see on an exam)? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); } public class Hello2{ public static void main( String[] args) { System.out.println( "Welcome." ); System.out.println(); int i=12; System.out.println( "i is equal to" );System.out.println(i); System.out.println("Bye." );}} Artistic / Poet

Which do you prefer (to see on an exam)? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); } public class Hello2{ public static void main( String[] args) { System.out.println( "Welcome." ); System.out.println(); int i=12; System.out.println( "i is equal to" );System.out.println(i); System.out.println("Bye." );}} Artistic / Poet

What’s the title of this poem?

Comment rules 1.Comments are required (by me)! – You may use the problem description as the basis for your comments. 2.Comments should be placed before (not after) the code they describe.

Indentation rules 1.All lines within the same block should line up on the left. 2.All lines following { should be indented +4 spaces. 3.All lines including and then following } should be unindented -4 spaces.

Indentation rules 1.All lines within the same block should line up on the left. 2.All lines following { should be indented +4 spaces. 3.All lines including and then following } should be unindented -4 spaces. public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); }

Indentation rules 1.All lines within the same block should line up on the left. 2.All lines following { should be indented +4 spaces. 3.All lines including and then following } should be unindented -4 spaces. public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); }

Indentation rules 1.All lines within the same block should line up on the left. 2.All lines following { should be indented +4 spaces. 3.All lines including and then following } should be unindented -4 spaces. public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); }

Indentation rules (one more time) Start of block lines up with end. All lines in block should be indented +4 spaces. public class Hello { }

Indentation rules (one more time) Start of block lines up with end. All lines in block should be indented +4 spaces. public class Hello { public static void main ( String[] args ) { }

Indentation rules (one more time) All lines in block should be indented +4 spaces. public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); }

Alternate placement of {…} public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); }