Introduction to Java A lab course by Dr. Junaid Ahmed Zubairi SUNY Fredonia.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

Lesson One: The Beginning Chapter 2: Processing Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from built-in help reference.
CPSC150 Fall 2008 Dr. L. Lambert. CPSC150 Overview Syllabus Use Textbook, ask questions, extra thorough, I will post sections covered All information.
1 Fall 2008ACS-1903 Chapter 1 Topics Java History Java Programs Why Program? Computer Systems: Hardware and Software Programming Languages What Is a Program.
Java Applets A lab course by Dr. Junaid Ahmed Zubairi SUNY Fredonia.
Excerpts from Introduction to Java Programming, 4E Author: Y. Daniel Liang (Copyright by Prentice Hall)
Introduction to Java Programming, 4E
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
Introduction to Java Lab CS110A – Lab Section 004 Instructor: Duo Wei.
School of Computing Science CMT1000 © Ed Currie Middlesex University Lecture 3: 1 CMT1000: Introduction to Programming Ed Currie Lecture 3: Program structure.
Using Java without BlueJ Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling BlueJ projects A BlueJ.
Begin Java having used Alice Pepper - Some slides from Alice in Action with Java.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Lab 1 Instructor: Jolanta Soltis.
Lesson One: The Beginning
Honors 101, Fall 2006 Please do not sit in back of room! Lots of info on web page Join the mailing list Download Eclipse and start using it Read the text.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
PHY281Introduction to JavaSlide 1 Introduction to Java In this section we will learn how how to use Java and write our first Java Applet:  The Java Development.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Agenda What is Computer Programming? The Programming Process
Warm-Up: Monday, March 3 List all devices you can think of that can be used to input information into the computer.
Introduction to Java Programming with JBuilder 4
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
S.W. Ma/CIM/LWL41211/2 Prog. IIA Page 1 HKIVE (Lee Wai Lee Campus) Department of CIM Course : Year 2 Module : Programming IIA Textbook : Introduction.
CS110/CS119 Introduction to Computing (Java)
From BlueJ to NetBeans SWC 2.semester.
The NetBeans IDE CSIS 3701: Advanced Object Oriented Programming.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
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.
UCSC All rights reserved. No part of this material may be reproduced and sold. 1 IT1202-Fundamentals Of Programming (Using JAVA) Interacting with.
Java Programming, Second Edition Chapter Five Input and Selection.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Chapter 1: Introduction to Programs, and Java 1. Objectives To review programs (§ ). To understand the relationship between Java and the World Wide.
POS 406 Java Technology And Beginning Java Code
Programming Concept Chapter I Introduction to Java Programming.
Introduction to Java Programming with Forte Y. Daniel Liang.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
The Joy of Programming (also known as) Introduction to Object-Oriented Programming.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
JCreator Tonga Institute of Higher Education. Programming with the command line and notepad is difficult. DOS disadvantages  User Interface (UI) is not.
Chapter 2: Java Fundamentals
Agenda For Feb PowerPoint Presentation (Introduction to Java Methods) 2.Finish Unit 2 exercises on page 13 (due by the end of the class today). 4.
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.
CS 106 Introduction to Computer Science I 01 / 31 / 2007 Instructor: Michael Eckmann.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
1 COMP 241: Object-Oriented Programming with Java Fall 2004 Lecture 1 September 27, 2004 Serdar Taşıran.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
Java Methods Methods contain a group of instructions that together perform a single task. For example if I want to perform the task of “making a pizza”,
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Application Architecture Using Java Hong Li. Introduction Developed by a team led by James Gosling at Sun Microsystem. Originally called Oak, designed.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
Introduction to Java Programming. 2 Chapter 1 Introduction to Java and Forte F What Is Java? F Getting Started With Java Programming –Create, Compile.
introductory lecture on java programming
CSCI 115 Computer Programming Overview. Computer Software System Software –Operating systems –Utility programs –Language compilers Application Software.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Introduction to Java Programming, 4E Y. Daniel Liang.
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
CS210 Intermediate Computing with Data Structures (Java)
2.5 Another Java Application: Adding Integers
Java programming lecture one
How to Run a Java Program
Introduction to Java Brief history of Java Sample Java Program
Developing Java Applications with NetBeans
Developing Java Applications with NetBeans
Presentation transcript:

Introduction to Java A lab course by Dr. Junaid Ahmed Zubairi SUNY Fredonia

Introduction to Java  Java Applications and Applets  Java Development kit  JCreator  Console Programs in Java  Applet Development  Graphics

Java Applications and Applets  In Java, you can develop applications and applets  Applications can be executed by themselves  Applets are executed in a controlled environment, usually within web browsers  Let us see the example of an applet embedded in a web page

Some Applets  Hilo Game:  0/fall2003/Applets/HiLo/Hi.html 0/fall2003/Applets/HiLo/Hi.html  Hangman Game:  dex.html dex.html

Applet Mechanism  Java applets are programs that are stored with a web page  When a user requests that web page, the applet embedded with it is sent from the server to the user’s computer  Then the applet is executed in a “sandbox” preventing it from corrupting the user’s computer

JDK (Java Development Kit)  JDK or SDK packages are released by Sun Microsystems  A recent version Java2 SDK v is available through the URL:  it225/csit225.html it225/csit225.html  On this web page, you can also find the JCreator v 3.

JCreator  JCreator is a nice free package available through the web  We are using its older version (2.5) on lab machines. However, I have made version 3.0 available on my homepage  JCreator is an IDE (Integrated Development Environment) for developing Java applications and applets

On Your Home Machine  Download and install Java 2 SDK v1.4.3  (Optional) Download and install Java Documentation  Download and install JCreator version 3  Now you are all set to start using Java  If Java compiler does not run, Use Configure  Options and check JDK profile

Console Programs in Java  You can start by typing a simple program that will work through the console window  Open JCreator, Choose File  New  File and choose “Java File”. Give it the name “myfirst.java”  Type the following program into the editor window, then save, compile and run the program

First Program  Public class myfirst {  Public static void main(String[] args)  {  System.out.println(“Hi!! Nice Coffee”);  }

Java Rules!!  Each source file can contain only one public class  The name of the public class must match the name of the file in which it is stored  Each Java application must have a method named main()  main() starts running first so make sure that you put the initial code in it

Exercises  Try replacing the single statement in the first program by the following statements one by one and note the output:  System.out.println(3+4);  System.out.print(3+4);  System.out.println(3+4);  System.out.println("\"Hi!! Nice Coffee\"");

Opening A Little Window  Now is the time to open a small colorful window in our application  We would like to read the name of the user and generate a greeting for the user  Reading from the keyboard in Java requires adding an import line on top of the program  “import javax.swing.JOptionPane”  Java is case sensitive!!

Using Input Window  Please add the following line to capture and store the keyboard input into a string variable  String username = JOptionPane.showInputDialog("What is your name?");  You can display the stored name by the following line:  System.out.print(username);  Please complete the program by adding a greeting

Showing the Results in a Window  In order to get rid of the black and white console completely, we learn how to show the results in a colored window  We use another method from the goodies bag!!  This method is named showMessageDialog  It takes four parameters

Showing Results  Leave the first parameter as null  After comma, write the text string that you want to be displayed  The third parameter is the title of the window  The fourth one defines the type of message. You may choose EROR_MESSAGE to show errors and INFORMATION_MESSAGE to display normal results

Showing Results  Try this line  JOptionPane.showMessageDialog(null,"Go od Morning "+username,"Greeting Window",JOptionPane.INFORMATION_ MESSAGE);

Exercises  Change the output window to error message type window  Swap the greeting to occur after the name  Add “How are you” to the greeting. Strings can be added to other strings with + sign  Change the title to your own  Give a demo

Reading Numbers from the Keyboard  Numbers cannot be directly read from the keyboard because the methods used by us read everything as text  If the user has typed a number, we have to extract it from the string  Assume the user has entered a number in the string username  Type the following to extract and store the number into variable “age”  int age = Integer.parseInt(username);

Programming Exercise  Use the comparison statements to display the appropriate message  For example, use the following statement to display the message that the user can drive  if (age>=16)  JOptionPane.ShowMessageDialog(null, “You can drive”,”Info”,JOptionPane.INFORMATIO N_MESSAGE);

Programming Exercise  Add a statement that displays the fact that the user’s age is less than 16 and thus the user cannot drive  Add another pair of statements showing the decision if the user can or cannot vote, given the voting age is 18