CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014

Slides:



Advertisements
Similar presentations
I/O Basics 12 January 2014Smitha N. Pai, CSE Dept.1.
Advertisements

Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
How to Create a Java program CS115 Fall George Koutsogiannakis.
1 LECTURE#7: Console Input Overview l Introduction to Wrapper classes. l Introduction to Exceptions (Java run-time errors). l Console input using the BufferedReader.
Java Programming Working with TextPad. Using TextPad to Work with Java This text editor is designed for working with Java You can download a trial version.
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,
Java I/O – what does it include? Command line user interface –Initial arguments to main program –System.in and System.out GUI Hardware –Disk drives ->
COMP 14: I/O and Boolean Expressions May 24, 2000 Nick Vallidis.
Reading Input -- the Keyboard Class The Keyboard class is NOT part of the Java standard class library The Keyboard class is in package cs1. It provides.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Command Console Tutorial BCIS 3680 Enterprise Programming.
Writing algorithms using the for-statement. Programming example 1: find all divisors of a number We have seen a program using a while-statement to solve.
Editing Java programs with the BlueJ IDE. Working environments to develop (= write) programs There are 2 ways to develop (write) computer programs: 1.Using.
Computer Programming Lab(4).
Saravanan.G.
Example 1 :- Handling integer values public class Program1 { public static void main(String [] args) { int value1, value2, sum; value1 = Integer.parseInt(args[0]);
SOFTWARE TECHNOLOGY - I CONSTANTS VARIABLES DATA TYPES.
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.
1 Java Console I/O Introduction. 2 Java I/O You may have noticed that all the I/O that we have done has been output The reasons –Java I/O is based on.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Appendix E The EZJava.
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
Lesson 2: First Java Programs. Objectives: –Discuss why Java is an important programming language. –Explain the Java virtual machine and byte code. –Choose.
Programming Concept Chapter I Introduction to Java Programming.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014 Office hours: Thursday 1300 – 1400hrs.
1 Recitation 8. 2 Outline Goals of this recitation: 1.Learn about loading files 2.Learn about command line arguments 3.Review of Exceptions.
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.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
Mixing integer and floating point numbers in an arithmetic operation.
Illustration of a Visual Basic Program Running an Ada Program 1 by Richard Conn 11 September 1999.
Java 1.5 The New Java Mike Orsega Central Carolina CC.
5-Dec-15 Sequential Files and Streams. 2 File Handling. File Concept.
Java Programming, Second Edition Appendix A Working with Java SDK 1.4.
Lesson 4 Input. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are using. The reason it is not.
Using the while-statement to process data files. General procedure to access a data file General procedure in computer programming to read data from a.
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,
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Department of Computer Engineering Using Objects Computer Programming for International Engineers.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014 Office hours: Thursday 1300 – 1400hrs.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
Object Oriented Programming (OOP) LAB # 1 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
Exceptions. Exception  Abnormal event occurring during program execution  Examples Manipulate nonexistent files FileReader in = new FileReader("mumbers.txt“);
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
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.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
L AB #3. System.out.println(“if you have” +eggPerBasket + “egg per basket and” + numberOfBaskets +”baskets, then the total number off eggs is“+totalEggs);
The eclipse IDE IDE = “Integrated Development Environment”
Introduction to programming in java
An Introduction to Computers and Visual Basic
Text by: Lambert and Osborne
CHAPTER 5 JAVA FILE INPUT/OUTPUT
Lecture Note Set 1 Thursday 12-May-05
I/O Basics.
Computer Programming Methodology File Input
An Introduction to Computers and Visual Basic
Programming In Any Language With “Hello, World!” Examples
L3. Necessary Java Programming Techniques
L3. Necessary Java Programming Techniques
Java Intro.
An Introduction to Computers and Visual Basic
Java Programming with BlueJ Objectives
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Unit 3: Variables in Java
Exception Handling Contents
EEC 484/584 Computer Networks
Presentation transcript:

CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE

Create Folders and text files  Creating folder Navigate to the directory where the folder is to be created Click right button of the mouse Point the mouse over the “New” item of the menu Click on the “Folder” option of the sub-menu Give a name to the newly created folder Press F2 to rename the folder name

Create Folders and text files  Creating text file using “notepad” Click the “start” menu presented at the bottom-left corner of the window Point the mouse over the “All Programs” item Point the mouse over the “Accessories” item of the sub-menu Click on the “Notepad” application of the sub-menu Click on the “File” from the menu bar of the notepad Using the “Save in” drop down list, navigate to the directory/folder where the text file is to be saved or created Give a name to the newly created text file by entering a name in the “File name” box. Click “Save” to save the file By default the extension of the file is “.txt” Press F2 to rename the file name

Using command promt to access the folders  Click the “start” menu presented at the bottom-left corner of the window  Point the mouse over the “All Programs” item  Point the mouse over the “Accessories” item of the sub-menu  Click on the “Command Promt” to open the command promt  The above three steps can be done by clicking “Run…” from the start” menu and entering “cmd” in the text box.  Suppose we want to access the “Program Files” folder of the C directory.  We can do so by entering as follows: cd\ cd Program Files (going into the “Program Files” folder) dir (viewing the content of the folder)  Now, using the above procedure go to the folder that you created

First Program: Hello World  Open a notepad to write a java program that will display “Hello World” as output.  The program is as follows: class myProgram { public static void main (String args[]){ System.out.println(“Hello world.”); } }  The “bin” directory of java is located at C:\Program Files\Java\jdk1.5.0_12\bin  Save the file into the above directory by giving the file name same as the class name of the java program that we wrote  Here, the file name will be “myProgram.java”. Note that the file extension is java.  To make the file as a java file, choose “All files” from the Save as Types drop down box at the time of saving. Failure to do will make the file as a normal text file with.txt extension.

Compile and run the program  The “bin” directory of java is located at C:\Program Files\Java\jdk1.5.0_12\bin  Go to the above directory by using command promt by using the following steps: Open command promt and enter the following commands cd\ cd Program Files\Java\jdk1.5.0_12\bin  To compile the java program enter the following command javac myProgram.java  To run the java program enter the following command java myProgram

Explanation of the source code class myProgram { public static void main (String args[]){ System.out.println(“Hello world.”); } }  Java program structured as a set of classes  All Java code must be part of a “class”  All classes must have a name. Here, our class name is “myProgram”  Beginning of a class is identified by a opening brace {  Ending of a class is identified by a closing brace }  In a class there will be two things attributes (store some information) methods (perform some specific task)

Explanation of the source code class myProgram { public static void main (String args[]){ System.out.println(“Hello world.”); } }  Here we have only one method  The name of the method is “main”  “main” is a special name.  All java program contains a method with the name “main”  When any java program is run, it starts from the “main” method  Body of each method contains set of statements  Each statement is terminated by semi-solon (;)  Here we have only one statement which prints the information between the quotes.

Taking input from user  Write a java program that will ask user to enter his/her name and age. The purpose of the program is to display the user name and the square of his/her age.  Before starting writing the source code we always try to determine few things What would be the input(s) to the program? What would be the output(s) to the program? How would we calculate the output?  Here, the input is a string (for containing the name) and an integer (for containing the age).  Outputs are string (that contains the name) and integer (that contains the square of the age).  The output of age will be calculated by using the “pow” method of the “Math” class.

Source code with explanation import java.io.*; import java.util.*; class myProgram { public static void main(String[] args) throws IOException{ String name; int age; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter your name: "); name = br.readLine(); System.out.println("Your name is " + name); System.out.print("Enter your age: "); age = Integer.parseInt(br.readLine()); System.out.println(Math.pow(age,2)); } }

Source code with explanation  throws IOException: An exception that is thrown when I/O error encountered. public static void main(String[] args) throws IOException  InputStreamReader works as a bridge from byte stream to character stream  It reads bytes and decodes into characters  BufferedReader reads text from character input stream BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

Alernative sotution  Add the following codes just before the last brace } of the Keyboard.java file public static void main(String[] args){ String name; int age; Keyboard kb = new Keyboard(); System.out.print("Enter your name: "); name = kb.readString(); System.out.println("Your name is " + name); System.out.print("Enter your age: "); age = kb.readInt(); System.out.println(Math.pow(age,2)); // add [import java.util.8;] before the class definition } }

Assignment  Modify or add codes to the Keyboard.java file to do the following assignments.  Take the temperature of a day from the user in degree Celsius and convert it into degree Fahrenheit by using the formula F = 9/5 * C + 32  Given the value of r and h, find the volume of a cylinder by using the formula V = pi * r * r * h (the value of pi can be obtained by using the Math class)  Due before 8 am on September 28, 2007