Lecture Note Set 1 Thursday 12-May-05

Slides:



Advertisements
Similar presentations
ARDUINO CLUB Session 1: C & An Introduction to Linux.
Advertisements

Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
Hello, world! Dissect HelloWorld.java Compile it Run it.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
1 Course Lectures Available on line:
SOFTWARE TECHNOLOGY - I CONSTANTS VARIABLES DATA TYPES.
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()
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Console Input. So far… All the inputs for our programs have been hard-coded in the main method or inputted using the dialog boxes of BlueJ It’s time to.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
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
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
CSE 131 Computer Science 1 Module 1: (basics of Java)
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Chapter 2: Java Fundamentals
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
JAVA PROGRAMMING BASICS CHAPTER 2. History of Java Begin with project Green in 1991 founded by Patrick Noughton, Mike Sheridan and James Gosling who worked.
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.
A First Simple Program /* This is a simple Java program. Call this file "Example.java".*/ class Example { // Your program begins with a call to main().
 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.
CSC Programming I Lecture 6 September 4, 2002.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Chapter 2 Variables.
Introduction to Computing Concepts Note Set 12. Writing a Program from Scratch public class SampleProgram1 { public static void main (String [] args)
Overview of Java CSCI 392 Day One. Running C code vs Java code C Source Code C Compiler Object File (machine code) Library Files Linker Executable File.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Java Fundamentals MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh.
Introduction to programming in java
Introduction of Java Fikri Fadlillah, S.T.
Chapter 2 Variables.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Introduction to programming in java
Chapter 2 Basic Computation
Completing the Problem-Solving Process
I/O Basics.
Intro to Java.
Going from C++ to Java Jayden Navarro.
Programming Vocabulary.
Use proper case (ie Caps for the beginnings of words)
Introduction to C++ Programming
An Introduction to Java – Part I, language basics
Java Tutotrial for [NLP-AI] 2
CS 200 Primitives and Expressions
CS150 Introduction to Computer Science 1
elementary programming
Introduction to Java Brief history of Java Sample Java Program
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
C Data Types and Variable
Exception Handling Contents
Chapter 2 Variables.
F II 2. Simple Java Programs Objectives
Chapter 1 c++ structure C++ Input / Output
Introduction to java Part I By Shenglan Zhang.
Presentation transcript:

Lecture Note Set 1 Thursday 12-May-05 CIS3931 – Intro to JAVA Lecture Note Set 1 Thursday 12-May-05

A basic JAVA program // Class declaration public class Welcome1 { public static void main( String args[] ) System.out.println(“Welcome to Java”); } //end of main method } //end of class

Compiling a JAVA program Command = javac <filename.java> Compiler will potentially return with error messages Error messages = time to debug your code Debugging = Correcting syntax errors in your code No errors = runtime testing

Running a JAVA program java <filename> Example to run the class file “example.java” you would type java example Runtime testing = Making sure your program performs as expected

Variables A place to store values in memory Many different types int = integer – A whole number value (ex : 12) char = character – A single character (ex: c) String = characters (ex: hello) float = floating point number (ex : 3.14)

Variable examples (declarations) int a = 1; //assigns the value 1 to a int b = 1 + 1 //assigns the result of 1 + 1 to b int c = a + b //assigns the result of a + b to c a+ = 1; //assigns the result of a + 1 to a String cup = new String(“cup of Java”); // assigns the literal “cup ofJava” to cup

Variable Casting It is possible to cast one variable type to another Example : A character is actually just a special case of an integer … The character “A” has the integer value 65

Text Formatting Text is printed to the screen with either of the following commands System.out.println(“Insert Text Here”); System.out.print(“Insert Text Here”); System.out.print(“hello\n”); is equivalent to System.out.println(“hello”);

Text formatting Column formatting can be accomplised with the /t escape character Example : System.out.println(“a\tb\tc\td”);

Comments There are two types of comments in JAVA Single line comments //This is a single line comment Block comments /* This is a block comment*/

The JAVA API http://java.sun.com/j2se/1.5.0/docs/api/ The most useful tool when programming in JAVA Many algorithms and functions are already written for you

Using the API You have to “import” the class that contains the functions you want to use Example : Import java.io.* will allow you to use anything in the java.io class

User Input Use BufferedReaders. BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String input = br.readLine(); int num1 = Integer.parseInt(input); BufferedReader is in java.io.*