Introduction to programming in java

Slides:



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

An Introduction to Programming By :- Vishal Hirani B.Tech II year (CSE)
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
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. GCOC – A.P. Computer Science A College Board Computer Science A Topics Covered Program Design - Read and understand.
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.
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.
CHAPTER 1 INTRODUCTION GOALS  To understand the activity of programming  To learn about the architecture of computers  To learn about machine code and.
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,
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Unit 2: Java Introduction to Programming 2.1 Initial Example.
“Introduction to Programming With Java”
Hello AP Computer Science!. What are some of the things that you have used computers for?
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.
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
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
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.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
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.
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.
Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
ECE 122 Feb. 1, Introduction to Eclipse Java Statements Declaration Assignment Method calls.
Getting Started.
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,
CSc 201 Introduction to Java George Wells Room 007, Hamilton Building
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To learn about the architecture of computers To learn about machine code.
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.
CS 177 Recitation Week 1 – Intro to Java. Questions?
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.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Introduction to java (class and object). Programming languages: –Easier to understand than CPU instructions –Needs to be translated for the CPU to understand.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Computer Programming Your First Java Program: HelloWorld.java.
John Woodward A Simple Program – Hello world
Object-Oriented Programming Using Java
GC101 Introduction to computer and program
Chapter 3 GC 101 Java Fundamentals.
CSE 190D, Winter 2013 Building Java Programs Chapter 1
Lecture Note Set 1 Thursday 12-May-05
Intro to Java.
Hands-on Introduction to JAVA
Tonga Institute of Higher Education
Java Intro.
CS110D Programming Language I
Anatomy of a Java Program
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
CSE 142, Spring 2012 Building Java Programs Chapter 1
CSE 142, Winter 2014 Building Java Programs Chapter 1
Zorah Fung University of Washington, Winter 2016
How to Run a Java Program
Presentation transcript:

Introduction to programming in java

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

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

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

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

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

Creating and Compiling Programs On command line javac First.java

Executing Applications On command line java classname

Example javac First.java java First output:...

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

Compiling & Running the Program 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

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

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

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

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 Tips About Programming 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.

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

Concatenating output with + print("I like programming in "); println("Java"); This code prints: I like programming in Java print("I like programming in “ + “Java” );

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 = “+ 2 + " 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

Exercise  Write a program which prints your name and Student ID. Write a program that prints the multiplication table of 5.

summary HelloWorld.java Compile and run java programs. print/println “\n” new line “\t” tab Concatenation

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