Introduction to programming in java. Input and output to screen with Java program Structure of Java programs Statements Conditional statements.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Basic Java Constructs and Data Types – Nuts and Bolts
Foundations of Programming and Problem Solving Introduction.
Lecture 10 Flow of Control: Loops (Part 2) COMP1681 / SE15 Introduction to Programming.
An Introduction to Programming By :- Vishal Hirani B.Tech II year (CSE)
Introduction to Programming G51PRG University of Nottingham Revision 1
Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
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
 2005 Pearson Education, Inc. All rights reserved Introduction.
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
Chapter 1: Introduction
How do we make our Welcome.java program do something? The java in our Welcome.java file won’t do anything by itself. We need to tell the computer to execute.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
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.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
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,
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
“Introduction to Programming With Java”
Hello AP Computer Science!. What are some of the things that you have used computers for?
Chapter 2 How to Compile and Execute a Simple Program.
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.
Welcome to the Lecture Series on “Introduction to Programming With Java”
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 Computers and Java Chapter 1.3. A Sip of Java: Outline History of the Java Language Applets A First Java Program Compiling a Java Program.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
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.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.
8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
CSc 201 Introduction to Java George Wells Room 007, Hamilton Building
CPRG 215 Introduction to Object-Oriented Programming with Java Module 1-Introduction to Java Topic 1.3 Write Your First Java Program Produced by Harvey.
1 Data and Expressions Chapter 2 In PowerPoint, click on the speaker icon then the “play” button to hear audio narration.
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/16: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
CS 106 Introduction to Computer Science I 01 / 24 / 2007 Instructor: Michael Eckmann.
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 Programming (CS 201) Lecture 01 - Introduction.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Introduction to programming in java
Computer Programming Your First Java Program: HelloWorld.java.
Programming what is C++
Object-Oriented Programming Using Java
Introduction to Programming (CS 201)
CSE 190D, Winter 2013 Building Java Programs Chapter 1
Lecture Note Set 1 Thursday 12-May-05
Intro to Java.
Chapter 2 – Getting Started
Hands-on Introduction to JAVA
Chapter 3 Classes and Objects
Introduction to Algorithm Design
Fundamentals of Programming
Java Tutotrial for [NLP-AI] 2
Java Intro.
CSE 142, Spring 2012 Building Java Programs Chapter 1
CSE 142, Winter 2014 Building Java Programs Chapter 1
Computer Programming-1 CSC 111
Instructor: Alexander Stoytchev
Zorah Fung University of Washington, Winter 2016
Presentation transcript:

Introduction to programming in java

Input and output to screen with Java program Structure of Java programs Statements Conditional statements Loop constructs Arrays, character and string handling Functions Syllabus

Structure of Java programs Input and output to screen with Java program Statements (what is a statement) Lecture Outcomes

Books & References Introduction to Java and Object Oriented Programming (Volume 1) 1.Chapter 2. After todays Lecture you should be able to complete all exercises In Section 2.10, page Chapter 3 If you are confident with all the material in Chapter 2, then start Reading Chapter 3. 3.Extra More practise exercises are on page:

Structure of Java programs Compiling and running the program Printing messages to the screen Contents for Todays Lecture

Some Basics Definition of a program? A sequence of instructions that a computer can interpret and execute. Why dont we just use natural languages such as English? A computer is not intelligent enough to understand natural languages.

class class-name { public static void main(String args[]) { statement1; statement2; … } Structure of Java Programs class-name.java

8 A statement written in Java println(Hello World!"); String hello = Hello World!"; println(hello); every statement is terminated with a ;

First.java Public class First { public static void main(String args[]) { System.out.println(Hello World); } Example Program statement

10 Creating and Compiling Programs On command line – javac file.java

11 Executing Applications On command line – java classname

12 Example javac Welcome.java java Welcome output:...

Compile and run java command line Compile javac file-name.java Run java filename Compile javac HelloWorld.java Runjava HelloWorld Example: HelloWorld.java

Compiling: is the process of translating source code written in a particular programming language into computer-readable machine code that can be executed. $ javac First.java This command will produce a file First.class, which is used for running the program with the command java. Running: is the process of executing program on a computer. $ java First Compiling & Running the Program

second.java class second { public static void main(String args[]) { System.out.println(Hello World); } Example Program Compile javac second.java Run java second

HelloWorld.java class HelloWorld{ public static void main(String args[]) { System.out.println(Hello World); } Example Program Compile javac HelloWorld.java Runjava HelloWorld

1.HelloWorld java 2.Welcome.java 3.Myname.java 4.MyDate ofBirth.java Compile Run a few example using Command line

1.System.out.println(Hello World); – outputs the string Hello World followed by a new line on the screen. 2.System.out.print(Hello World); - outputs the string Hello World on the screen. This string is not followed by a new line. 3.Some Escape Sequence – \n – stands for new line character \t – stands for tab character About Printing on the Screen

19 Java print() and println() Text can be printed on the screen using print() or println(). Using println() puts a new line at the end of the text. print("7*3"); println("="); println(7*3); This code prints: 7*3= 21

Example Welcome.java public class Welcome { public static void main(String args[]) { System.out.print("Welcome "); System.out.println("to"); System.out.println(java!"); } Welcome to java! Output

Example Welcome3.java ( includes \n and \t) public class Welcome { public static void main(String args[]) { System.out.print("Welcome \n "); System.out.print("to \t"); System.out.println(java!"); } Welcome to java! Output

Some common errors in the initial phase of learning programming: - Mismatch of parentheses - Missing ; at the end of statement - Case sensitivity Writing programs on your own is the best way to learn how to program. Some Tips About Programming

23 Comments in java There are two ways of commenting code. Comments starting with // and terminated by end of line // Lahcen Ouarbya // 1 October 2012 // Hello World Comments enclosed in /* */ /* Lahcen Ouarbya 1 October 2012 Hello World */ good to make several lines of comments stand out in your program

24 Concatenating output with + print("I like programming in "); println("Java"); This code prints: I like programming in Java print("I like programming in + Java ); This code prints: I like programming in Java println( square root of 4 = " 2 + " or " -2); This code prints: square root of 4 = 2 or -2

Example Concatenate.java public class Concatenate { public static void main(String args[]) { System.out.print("I like programming in "); System.out.println(java"); System.out.println("I like programming in + java); System.out.println( square root of 4 = " or + -2); } { } I like programming in java square root of 4 = 2 or -2 Output

Example Welcome.java public class Welcome { public static void main(String args[]) { System.out.print("Welcome "); System.out.print("to "); System.out.println("Java!"); System.out.println(Welcome + "to + " Java!"); } Welcome to java! Output

1.Write a program which prints the following information about at least 5 persons: `Full Name ` -Address ` Telephone Number use print and println and see the difference. 2.Write a program that prints the time table of 5 and time table of 9. (you will need to use concatenation.) Some Assignments

End Using Command line Arguments public class TestMain { public static void main(String args[]) {... } java TestMain arg0 arg1 arg2 … argn }

Processing Command-Line Parameters The main method, get the arguments from args[0], args[1],..., args[n] arg0, arg1,..., argn }

Example Argument.java public class Welcome { public static void main(String args[]) { System.out.print("Hi, "); System.out.print(args[0] + " " ); System.out.println(". How are you?"); } Hi, Lahcen. How are you? Java Argument Lahcen

Example Argument1.java public class Argument1 { public static void main(String args[]) { System.out.print("Hi, "); System.out.print(args[0] + " " ); System.out.print(args[1] + " " ); System.out.println(". How are you?"); } Hi, java programs. How are you? Java Argument java programs

Example Argument2.java public class Argument2 { public static void main(String args[]) { System.out.print("Hi, + args[0] + args[1] + (". How are you?"); } Hi, java programs. How are you? Java Argument java programs

summary HelloWorld.java Compile and run java programms. print/println \n new line \t tab Concatenation Use of Arguments.

More practice exercises. Introduction to Java and Object Oriented Programming (Volume 1) 1.Chapter 2. After todays Lecture you should be able to complete all exercises In Section 2.10, page Chapter 3 If you are confident with all the material in Chapter 2, then start Reading Chapter 3. 3.Extra More practise exercises are on page: