Your First Java Program: HelloWorld.java

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

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.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
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.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
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,
C# Programming: From Problem Analysis to Program Design1 2 Your First C# Program.
Chapter 2: Java Fundamentals Java Program Structure.
Unit 2: Java Introduction to Programming 2.1 Initial Example.
Introduction to Python Dr. Bernard Chen Ph.D. University of Central Arkansas July 9 th 2012
Hello AP Computer Science!. What are some of the things that you have used computers for?
2.2 Information on Program Appearance and Printing.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
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.
CS 106 Introduction to Computer Science I 01 / 25 / 2010 Instructor: Michael Eckmann.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
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.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
The Java Programming Language
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter 1 – Introduction ( ปรับปรุง )
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
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
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:
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.
First Programs CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
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.
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
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
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
© 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.
11 ITI 1120 Lab # 2 Contributors: G. Arbez, M. Eid, D. Inkpen, A. Williams, D. Amyot.
CS 177 Recitation Week 1 – Intro to Java. Questions?
ITP 109 Week 2 Trina Gregory Introduction to Java.
1/16: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
1 Structure of Simple C++ Program Chapter 1 09/09/13.
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.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Introduction to programming in java
Computer Programming Your First Java Program: HelloWorld.java.
The eclipse IDE IDE = “Integrated Development Environment”
John Woodward A Simple Program – Hello world
CompSci 230 Software Construction
Intro to Java.
Writing Methods.
Tonga Institute of Higher Education
Fundamentals of Programming
Java Intro.
How to Run a Java Program
Presentation transcript:

Your First Java Program: HelloWorld.java Computer Programming Your First Java Program: HelloWorld.java Copyright © Texas Education Agency, 2013 Trade & Industrial Education

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!"); } © UNT in partnership with TEA IT: Beginning Computer Programming- First Java Program Trade & Industrial Education

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 Copyright © Texas Education Agency, 2013 IT: Beginning Computer Programming- First Java Program Trade & Industrial Education

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”. Copyright © Texas Education Agency, 2013 IT: Beginning Computer Programming- First Java Program Trade & Industrial Education

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. Copyright © Texas Education Agency, 2013 IT: Beginning Computer Programming- First Java Program Trade & Industrial Education

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. Copyright © Texas Education Agency, 2013 IT: Beginning Computer Programming- First Java Program Trade & Industrial Education

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. Copyright © Texas Education Agency, 2013 IT: Beginning Computer Programming- First Java Program Trade & Industrial Education

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. Copyright © Texas Education Agency, 2013 IT: Beginning Computer Programming- First Java Program Trade & Industrial Education

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. Copyright © Texas Education Agency, 2013 IT: Beginning Computer Programming- First Java Program Trade & Industrial Education

Running the Program When you run the program, Hello World! Should display in the output window. Copyright © Texas Education Agency, 2013 IT: Beginning Computer Programming- First Java Program Trade & Industrial Education

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. Copyright © Texas Education Agency, 2013 IT: Beginning Computer Programming- First Java Program Trade & Industrial Education

Ending the Lesson Play around making changes and noting the errors. Do not introduce more than one error at a time! Copyright © Texas Education Agency, 2013 IT: Beginning Computer Programming- First Java Program Trade & Industrial Education