IT151: Introduction to Programming

Slides:



Advertisements
Similar presentations
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Advertisements

Lecture 2 Introduction to C Programming
University of Palestine software engineering department Introduction to data structures Introduction to java application instructor: Tasneem Darwish.
Chapter 1 Introduction to JAVA. Why Learn JAVA? Java is one of the fastest growing programming language in the world. Java is one of the fastest growing.
 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.
INSTRUCTOR: SHIH-SHINH HUANG Windows Programming Using Java Chapter2: Introduction to Java Applications 1.
Chapter 1: Introduction
Chapter 2 - Introduction to Java Applications
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
CMT Programming Software Applications
 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.
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
Java Applications & Program Design
 2005 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
1 2 2 Introduction to Java Applications Introduction Java application programming –Display messages –Obtain information from the user –Arithmetic.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
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()
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Chapter 2: Java Fundamentals
Week 1 Algorithmization and Programming Languages.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE 1 st semester H 1 King Saud University College of Applied studies and Community Service Csc 1101 By:
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
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.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Java™ How to Program, 10/e Late Objects Version © Copyright by Pearson Education, Inc. All Rights Reserved.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
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.
11 ITI 1120 Lab # 2 Contributors: G. Arbez, M. Eid, D. Inkpen, A. Williams, D. Amyot.
CSC 110 – Intro to Computing - Programming
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
Computer Programming Your First Java Program: HelloWorld.java.
Introduction to Java Applications
Chapter 6 JavaScript: Introduction to Scripting
CSC201: Computer Programming
Chapter 1 Introduction to Computers, Programs, and Java
Yanal Alahmad Java Workshop Yanal Alahmad
Chapter 2, Part I Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
Chapter 2 Introduction to Java Applications
Chapter 2 Introduction to Java Applications
Data types and variables
Fundamentals of Java Programs, Input/Output, Variables, and Arithmetic
MSIS 655 Advanced Business Applications Programming
Anatomy of a Java Program
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Introduction to Java Applications
Java How to Program, 11/e Questions?
Computer Programming-1 CSC 111
Presentation transcript:

IT151: Introduction to Programming Introduction to Java Applications

// Text-printing program // Created by: Siua Fonua // Date: 14 Feb 2006 public class Welcome { // main method begins execution of Java Applications public static void main (String args[ ]) System.out.println(“Welcome to IT151”); System.out.println(“Enjoy programming with Java”); } // end main method } // end class Welcome

Line 1 – Line 3 Comments Begins with // Comments are used to improve the program’s readability Java compiler ignores all comments To ways of indicating a comment // end-of-line comment /* … */ multiple-line comments

Line 4, 12 White space Includes Makes the program easier to read Blank lines Space characters Tab characters Makes the program easier to read Ignored by the compiler

Line 5 Class declaration Every program in Java consists of at least one class The keyword class is used to declare a class, followed by the name of the class The name of the class is called it’s identifier NOTE: YOU MUST DECLARE EVERYTHING IN JAVA

Reserved Words Also known as keywords These words are reserved for use by Java Examples include: class Public, and more to come Don’t use any of the Java keywords for your own use. IT WILL CONFUSE THE COMPILER

Class Names Rules for naming your class Convention Contains only Letters Digits Underscore ( _ ) Dollar sign ( $ ) Does not contain spaces Does not begin with a digit Convention All class names begin with a capital letter Capitalise the first letter of each word they include

Java is case-sensitive That is: Uppercase and lowercase letters are distinct Examples: TIHE is different from Tihe or tihe Not using the correct letters for an identifier causes a compilation error

Public classes Every class you declared public: Must be saved in its own file Class name must be the same as the filename Must be ended with the .java extension Failing to follow these rules, result in errors Sometimes your class will not be compiled by the compiler

Line 6, 14 Left brace, { Right brace, } Begins the body of the class Right brace, } Ends the body of the class It is a syntax error if braces do not occur in matching pairs

Line 8 The starting point of every Java applications Your program must have this line, exactly as it is shown here! Otherwise, your program will not be compiled by the compiler

Methods A block of code in the program that performs a specific task Methods are able to perform a task and returns information when they complete execution Some methods will not return any information when they complete execution All methods will have Return type Method name List of parameters (inside a pair of parentheses)

void methods When the keyword void appears in front of the method name, it indicates that this method will NOT return anything when it completes execution We’ll discuss later, the methods that will return information after execution

Line 9, 13 Left brace, { Right brace, } Begins the body of the method Right brace, } The end of the method’s body Whatever is between these braces, will be the actions to be performed by the method

Line 10 Instructs the computer to perform an action That is:- To print a string of characters contained between the double quotation marks White-space characters in strings are not ignored by the compiler

Standard output System.out is called the standard output object Allows Java to display sets of characters in the window from which Java executes

System.out.println This method displays a line of text in the command window Needs an argument, which is a string of characters Outputs its argument to the command window After completion, it positions the output cursor in the next line

Line 11 What does this line do?

Statement The entire line 10, is called a statement Each statement MUST end with a semicolon A method is typically composed by one or more statements that performs the method’s task NOTE: omitting the semicolon at the end of a statement, is a syntax errorh

// Text-printing program // Created by: Siua Fonua // Date: 14 Feb 2006 public class Welcome { // main method begins execution of Java Applications public static void main (String args[ ]) System.out.print(“Welcome to IT151”); System.out.println(“Enjoy programming with Java”); } // end main method } // end class Welcome

// Text-printing program // Created by: Siua Fonua // Date: 14 Feb 2006 public class Welcome { // main method begins execution of Java Applications public static void main (String args[ ]) System.out.println(“Welcome\n to\n IT151”); System.out.println(“Enjoy programming with Java”); } // end main method } // end class Welcome

Escape characters The backslash (\) is called an escape character in Java \n \t \r \\ \”