Computer Programming Your First Java Program: HelloWorld.java.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
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
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Your First Java Program: HelloWorld.java
Chapter 2: Your First Program! Hello World: Let’s Program  All programs must have the extension.java  Our first program will be named: 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,
01 Introduction1June Introduction CE : Fundamental Programming Techniques.
 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.
Slide 1 of 40. Lecture A The Java Programming Language Invented 1995 by James Gosling at Sun Microsystems. Based on previous languages: C, C++, Objective-C,
Unit 2: Java Introduction to Programming 2.1 Initial Example.
Hello AP Computer Science!. What are some of the things that you have used computers for?
2.2 Information on Program Appearance and Printing.
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()
Chapter 1 CSIS-120: Java Intro. What is Programming?  A: It is what makes computer so useful.  The flexibility of a computer is amazing  Write a term.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Board Activity Find your seat on the seating chart Login – Remember your login is your first initial your last name and the last three numbers of your.
The scope of local variables. Murphy's Law The famous Murphy's Law says: Anything that can possibly go wrong, does. (Wikipedia page on Murphy's Law:
Chapter 2: Java Fundamentals
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
Introduction to programming in the Java programming language.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Getting Started.
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
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.
Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,
Java FilesOops - Mistake Java lingoSyntax
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
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.
CS 177 Recitation Week 1 – Intro to Java. Questions?
ITP 109 Week 2 Trina Gregory Introduction to Java.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Introduction to programming in java
Chapter 1 – Introduction
The eclipse IDE IDE = “Integrated Development Environment”
Dept of Computer Science University of Maryland College Park
John Woodward A Simple Program – Hello world
Chapter 1 Introduction to Computers, Programs, and Java
Chapter 3 GC 101 Java Fundamentals.
CompSci 230 Software Construction
Intro to Java.
Introduction Java Chapter 3.
C# Programming: From Problem Analysis to Program Design
Chapter 2 – Getting Started
Writing Methods.
PROGRAM STRUCTURE CSC 111.
Programming Vocabulary.
String Output ICS 111: Introduction to Computer Science I
Chapter 3 Classes and Objects
Tonga Institute of Higher Education
Fundamentals of Programming
Java Intro.
CS110D Programming Language I
elementary programming
Anatomy of a Java Program
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Review of Previous Lesson
Chapter 2: Java Fundamentals
EECE.2160 ECE Application Programming
Unit 3: Variables in Java
Computer Programming-1 CSC 111
How to Run a Java Program
Presentation transcript:

Computer Programming Your First Java Program: HelloWorld.java

HelloWorld.java // Name: your name here // Date: today’s date here // Program: HelloWorld.java public class HelloWorld { public static void main (String[] args) System.out.println ("Hello World!") }

Comments // Name: your name here // Date: today’s date here // Program: Hello World Lines 1-3 are comments. Comments begin with //. Comments are ignored by the compiler. Used to give information to the reader.

Program Declaration public class HelloWorld Line 4 is the program declaration. “public” is a key word indicating that the class file is usable by the public. “class” indicates that the file is a program. Classes are the building blocks of Java. “HelloWorld” is the name of the file. Java is case-sensitive. The file must be saved as “HelloWorld.java”.

Braces { Line 5 begins the program with an opening curly brace({). Braces enclose statements that make up a programming block. Each opening brace must have a matching closing brace.

The Main Method public static void main (String[] args) Line 6 is the main method declaration. A method contains programming statements. Every Java application must have a “main” method. (String[] args) is the parameter for the main method. Parameters will be discussed in detail later.

Braces { Line 7 begins the main method with an opening curly brace({). Braces enclose statements that make up a programming block. Each opening brace must have a matching closing brace.

The Main Method System.out.println ("Hello World!") Line 8 prints a line of text. The text that will be printed is enclosed in parentheses. The statement ends with a semicolon. “Hello World” is the text that will be displayed. Text enclosed in quotes is called a string.

Closing Braces } Line 9 and 10 close the braces that were opened on lines 5 and 7. Indenting is not necessary but helps to make the program more readable.

Running the Program When you run the program, Hello World! Should display in the output window.

Introducing Errors Programmers are always fixing errors. We will explore a few types of errors. Line 6: public static void main (String[] args). Change it to: public static vod main (String[] args). Compile and you will see the error: “cannot find symbol class vod” – therefore you need to correct the spelling. This is a compile-time error.

Ending the Lesson Play around making changes and noting the errors. Do not introduce more than one error at a time!