Introduction to Java - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Introduction to Java

Description:

format() method. Conventions. File Names. In JCreator the file name ... print prints line and remains on same line. Example: System.out.println('Hello class' ... – PowerPoint PPT presentation

Number of Views:14
Avg rating:3.0/5.0
Slides: 9
Provided by: danlu6
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Java


1
Introduction to Java
  • Thanks to
  • Dan Lunney (SHS)

2
Java Basics
  • File names
  • The main method
  • Output to screen
  • Escape Sequence Special Characters
  • format() method
  • Conventions

3
File Names
  • In JCreator the file name and class name must be
    identical
  • Always start class names with a capital letter
  • If more than one word in file name all names are
    capitalized
  • Always begin java programs with
  • public class FileName
  • Code goes here

4
The main method
  • Executes the main section of code
  • All other methods called from here
  • Syntax for main method ispublic static void
    main(String args) code in here

5
Output to Screen
  • To print to screen we use the line
    System.out.println()
  • What ever is in the () will print
  • Text must be in marks
  • There are two options
  • println prints a line and the enters to start
    new line
  • print prints line and remains on same line
  • Example System.out.println(Hello class)
    prints Hello class on the screen

6
Escape Sequence Special Characters
  • By including special characters within the quote
    marks, java will perform special formatting
  • \n new line
  • \t tab (8 spaces)
  • \\ - backslash
  • \ double quote mark
  • Example System.out.print(Hello\t)
    System.out.print(class)prints Hello
    class

7
format() method
  • Can format the look of text
  • Example
  • System.out.format(-10s -8s, Hello,
    class)
  • Prints Hello class (5 spaces between)
  • Symbols
  • - indicates start of format
  • - indicates left align (nothing for right
    align)
  • indicates how many spaces for text
  • S indicates its a string

8
Java Conventions
  • Always use in an introductory comment with name,
    date, and project
  • All class names start with Upper case letters
  • Comments should be included before all methods to
    explain them
  • All code statements should be indented from
    method line
  • Place starting curly brace on the same line as
    classes and methods. Place the ending curly brace
    on its own line with nothing else.
Write a Comment
User Comments (0)
About PowerShow.com