Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.

Slides:



Advertisements
Similar presentations
Computer Programming Lab(7).
Advertisements

Exceptions & exception handling Use sparingly. Things you can do with exceptions: 1. Define a new exception class. 2. Create an exception instance. 3.
IT151: Introduction to Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Your First Java Program: HelloWorld.java
Today’s topics: I/O (Input/Output). Scribbler Inputs & Outputs  What are the Scribbler’s inputs and outputs?  reset button  motors/wheel  light sensor.
Chapter 2 Console Input and Output Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
18 File handling1June File handling CE : Fundamental Programming Techniques.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Console Input Using the Scanner Class Starting with version 5.0, Java includes a class for doing.
COMP 110 Introduction to Programming Mr. Joshua Stough September 10, 2007.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Introduction to Java Java SE 8 for Programmers Paul Deitel Harvey Deitel Deitel Developer Series 2014.
Chapter 2 Section 2.2 Console Input Using The Scanner CLASS Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska.
Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.
Laboratory Study October, The very first example, traditional "Hello World!" program: public class first { public static void main (String[ ]
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington GUI and the UI API COMP.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington While loops and the UI API.
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()
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Chapter 2 Console Input and Output Slides prepared by Rose Williams, Binghamton University Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
Console Input & Output CSS 161: Fundamentals of Computing Joe McCarthy 1.
Sahar Mosleh California State University San MarcosPage 1 System.out.println for console output System.out is an object that is part of the Java language.
Slides prepared by Rose Williams, Binghamton University Chapter 2 Console Input and Output.
Input & Output In Java. Input & Output It is very complicated for a computer to show how information is processed. Although a computer is very good at.
Program Flow Program Flow follows the exact sequence of listed program statements, unless directed otherwise by a Java control structure.
Comments in Java. When you create a New Project in NetBeans, you'll notice that some text is greyed out, with lots of slashes and asterisks:
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.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
CS 106 Introduction to Computer Science I 01 / 31 / 2007 Instructor: Michael Eckmann.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
CMSC 202 Java Console I/O. July 25, Introduction Displaying text to the user and allowing the user to enter text are fundamental operations performed.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Unix Environment Input Output 2  List Content (ls) ◦ ls (list current directory) ◦ ls –all (include hidden files/folders)  Make directory (mkdir) ◦
Introduction to Java Primitive Types Operators Basic input and output.
CHAPTER 5 GC 101 Input & Output 1. INTERACTIVE PROGRAMS  We have written programs that print console output, but it is also possible to read input from.
Introduction to Computing Concepts Note Set 12. Writing a Program from Scratch public class SampleProgram1 { public static void main (String [] args)
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Dale Roberts Introduction to Java - Input, Program Control and Instantiation Dale Roberts, Lecturer Computer Science, IUPUI
Chapter 2 Console Input and Output Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Slides prepared by Rose Williams, Binghamton University Console Input and Output.
Copyright © Curt Hill Simple I/O Input and Output using the System and Scanner Objects.
Interactive Programs Programs that get input from the user 1 In PowerPoint, click on the speaker icon then click the "Play" button to hear the narration.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 6_1 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
1 Text File Input and Output. Objectives You will be able to Write text files from your Java programs. Read text files in your Java programs. 2.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
An Introduction to the Java Language App Design Flat Rock Community Schools Introductory Java Programming.
Input/Output.
Chapter 2 More on Math More on Input
Yanal Alahmad Java Workshop Yanal Alahmad
Maha AlSaif Maryam AlQattan
INPUT STATEMENTS GC 201.
Writing Methods.
Introduction to Classes and Methods
A+ Computer Science INPUT.
CS110D Programming Language I
The keyboard is the standard input device.
Output Manipulation.
F II 2. Simple Java Programs Objectives
Presentation transcript:

Martin T. Press

 Main Method and Class Name  Printing To Screen  Scanner

The Return Type : always void (means returns nothing) The parameters Of the method: The Main Method Away takes a list of type String The main method is the starting point of execution of the Java program. Without a main Method a Class is not runnable by itself. A Java project must have at least one class with a main. Most of the first few labs will have one class. Remember always include public static at the beginning of the method. If this is left out the complier will not recognize it as the “main”.

File Name Sum.java The Public Key word tells the complier that all classes can see it ! I Class Name Sum Every.java file written must have a class name. It must be the same name as the.java file. Failure to name it the same as the file name will cause a compile error.

The System.out.print() and System.out.println() will be the only visual output for the first few labs. It displays text that is inside the ( ). The + operator when used with strings pushes them together. Such that “Hello ”+5 is the same as the String “Hello 5”. This is useful when printing!

Scanner Is the object that allows programs to get Input data from the user on the command line. The two methods we will use in this lab are nextDouble() and nextInt() This is the import statement which tells the complier where the Scanner object is located in the java library. You must always include this when scanner is used. This is a constructor for the Scanner (creates the object). It always takes System.in as a parameter for reading the command line. myScanner.nextDouble() Returns the next double entered by the user(Waits till user hits enter).

This is the output from the previous example of code. Notice that even if an integer is entered the output is still a double for the double. Try it the other way around what happens?

Looks like an error occurred. Last time it worked because of type casting. A good rule of thumb is if the scanner is expecting a type to always input the same type.