Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Begin Java Pepper. Objectives What is a program? Learn the basics of your programming tool: BlueJ Write a first Java program and see it run Make some.
IT151: Introduction to Programming
© A+ Computer Science - public class CompSci { } All Java programs start with a class.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. OBJECTIVES FOR THIS UNIT Upon completion of this unit, you should be able to: Explain the Java virtual machine.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. GCOC – A.P. Computer Science A College Board Computer Science A Topics Covered Program Design - Read and understand.
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Your First Java Program: HelloWorld.java
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
Getting Started with C# 1 SWE 344 Internet Protocols & Client Server Programming.
© A+ Computer Science - public class CompSci { } All Java programs start with a class.
INSTRUCTOR: SHIH-SHINH HUANG Windows Programming Using Java Chapter2: Introduction to Java Applications 1.
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
CMT Programming Software Applications
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
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,
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
2.2 Information on Program Appearance and Printing.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Comments are for people Header comments supply basic information about the artifact.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
3 Major Steps for Creating/Running a Java Program You write the source code for the program and save it as a.java file. You compile the.java program using.
Chapter 2: Java Fundamentals
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) public static void main(String[]
Java basics. Task  Display the supposed forecast I think there is a world market for maybe five computers. Thomas Watson, IBM, 1943.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
Introduction to Programming
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
ECE 122 Feb. 1, Introduction to Eclipse Java Statements Declaration Assignment Method calls.
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
1 WELCOME TO CIS 1068! Instructor: Alexander Yates.
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
Introduction to Computing Concepts Note Set 12. Writing a Program from Scratch public class SampleProgram1 { public static void main (String [] args)
Lecture 4 – Scanner & Style. Console Output The console that starts a Java application is typically known as the standard output device. The standard.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
1 Review for exam 1 CS 101 Aaron Bloomfield. 2 Today’s lecture An overview of the “review” sections of chapters 1-3 Stop me if you want me to go over.
1 Data and Expressions Chapter 2 In PowerPoint, click on the speaker icon then the “play” button to hear audio narration.
© A+ Computer Science - public class CompSci { } All Java programs start with a class.
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects 1. How is a class different from an object?
Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use simple Output statements Understand the different types and uses of comments.
Simple Console Output. What we will briefly discuss System.out.println( … ) System.out.print( … ) System.out.printf( … )
CSC 110 – Intro to Computing - Programming
Chapter 2 1.What is the difference between print / println 2.What are String Literals 3.What are the Escape Characters for backslash, double quotataions,
1/16: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
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.
Lecture 4 – Scanner & Style
Computer Programming Your First Java Program: HelloWorld.java.
Chapter 1 Introduction to Computers, Programs, and Java
Chapter 2, Part I Introduction to C Programming
USING ECLIPSE TO CREATE HELLO WORLD
Intro to Java.
OUTPUT STATEMENTS GC 201.
Writing Methods.
Chapter 3 Classes and Objects
Java Intro.
Anatomy of a Java Program
See requirements for practice program on next slide.
© A+ Computer Science - Basic Java © A+ Computer Science -
Presentation transcript:

Java Syntax and Output Java Part 3

public class CompSci { } All Java programs start with a class.

public class CompSci { public static void main(String[] args) { System.out.println("Comp Sci!"); } } OUTPUT Comp Sci!

public class CompSci { //open brace public static void main(String[] args) { System.out.println("Comp Sci!"); } } //close brace Braces – You gotta have ‘em! Every class and every method must have a { and a }.

© A+ Computer Science - public class CompSci { public static void main(String[] args) { System.out.println("Comp Sci!"); } You must put a semi-colon at the end of all Java program statements ( ; ).

Never put a ; before an open { brace ;{ //illegal }; //legal

Indentation public class CompSci { public static void main(String[] args) { System.out.println("Comp Sci!"); } Indent all code 3 spaces to make it easier to read.

Java Output System.out frequently used methods NameUse print(x)print x and stay on the current line println(x)print x and move to next line down printf(s,x)print x according to s specifications

System.out.print( " compsci"); referencecommand / method OUTPUT compsci

System.out.print("compsci"); OUTPUT compscicompsci

System.out.println("compsci"); OUTPUT compsci

System.out.println("compsci"); OUTPUTcompsci

System.out.println("c\tompsci " ); \nnewline \ttab \rcarriage return \bbackspace OUTPUT c ompsci

System.out.println("com\tpsci " ); OUTPUT com psci \nnewline \ttab \rcarriage return \bbackspace

System.out.println("comp\nsci"); OUTPUT comp sci \nnewline \ttab \rcarriage return \bbackspace

\\outs \ \"outs " \’outs ’ System.out.println( " \\compsci\ " / " ); OUTPUT \compsci"/

\\outs \ \"outs " \’outs ’ System.out.println("\\'comp\'sci\'/"); OUTPUT \'comp'sci'/

© A+ Computer Science - Escape Sequences frequently used combinations NameUse \ttabs over five spaces \nmoves to front of next line \bdeletes previous character \rmoves to front of current line \\nets one backslash \ \"nets one double quote " \’nets one single quote ’

© A+ Computer Science - //single-line comments /* */block comments //this line prints stuff on the screen System.out.println("stuff");

Review: AboutMe Part1  Create an AboutMe app that displays your first name and last initial, your instructor’s name, and your school name on 3 separate lines.  Below the personal information, display a phrase that encourages your school team, such as “Go Plainsmen!”. Be sure this phrase is enclosed in quotations marks in your output.

//single-line comments /* */block comments /* this line prints stuff on the screen */ System.out.println("stuff");

© A+ Computer Science - System.out.printf("%s","compsci\n"); OUTPUT compsci

format()

© A+ Computer Science -

Review: AboutMe Part2  Modify your app to include your timetable with start and end times for each class.  Include code to properly align the data into 2 columns with the courses left aligned and the times right aligned.  Use the format() method for this.