Lec02 - CS1101Y: Programming Methodology Java Basics...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Java Basics Lecture 2-- August 18, 2008 CS1101Y: Programming Methodology
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Outline • First Java Program • Comments • Class Name / Source Code Filename main Method Heading •B r a c e s System.out.println • Compilation and Execution • Program Template • Identifiers • Variables • Assignment Statements • Initialization Statements
Background image of page 2
Outline Numeric Data Types – int, long Numeric Data Types – float , double Constants Arithmetic Operators Expression Evaluation Increment and Decrement Operators Compound Assignment Operators Type Casting Character Type - char Escape Sequences Primitive Variables vs. Reference Variables String Basics String Methods: equals , equalsIgnoreCase , length , charAt Input - the Scanner Class
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
First Java Program /*************************************** * Hello.java * John Dean * * This program prints a hello message. ***************************************/ public class Hello { public static void main(String[] args) { System.out.println("Hello, world!"); } } // end class Hello
Background image of page 4
Comments Include comments in your programs in order to make them more readable/understandable. Block comment syntax: /* . .. */ (Note: The /* and */ can optionally span multiple lines) One line comment syntax: // … Commented text is ignored by the compiler. Style requirement: Include a prologue section at the top of every program. The prologue section consists of: line of *'s filename programmer's name blank line program description line of *'s blank line
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Class Name / Source Code Filename • All Java programs must be enclosed in a class. Think of a class as the name of the program. • The name of the Java program's file must match the name of the Java program's class (except that the filename has a .java extension added to it). • Proper style dictates that class names start with an uppercase first letter. • Since Java is case-sensitive, that means the filename should also start with an uppercase first letter. • Case-sensitive means that the Java compiler does distinguish between lowercase and uppercase letters.
Background image of page 6
main Method Heading Memorize (and always use) public class prior to your class name. For example: public class Hello Inside your class, you must include one or more methods . A method is a group of instructions that solves one task. Later on, we'll have larger programs and they'll require multiple methods because they'll solve multiple tasks. But for now, we'll work with small programs that need only one method - the main method. Memorize (and always use) this main method heading: public static void main(String[] args) When a program starts, the computer looks for the main method and begins execution with the first statement after the main method heading.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Braces • Use braces ( { } ) to group things together.
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/19/2012 for the course SOC 1101 taught by Professor A.tan during the Fall '08 term at National University of Singapore.

Page1 / 49

Lec02 - CS1101Y: Programming Methodology Java Basics...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online