Introduction to Java Brief history of Java Sample Java Program

Slides:



Advertisements
Similar presentations
 2005 Pearson Education, Inc. All rights reserved Introduction.
Advertisements

1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to 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,
Computer Science A 1: 3/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Unit 2: Java Introduction to Programming 2.1 Initial Example.
From BlueJ to NetBeans SWC 2.semester.
Java Workshop for Teachers May 6, 2005 A Brief Look at the Java Programming Language.
COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson
COMP 110 Spring Announcements Computers in class on Friday: Lab Office Hours: Monday 12-2 New students see me after class Administrative Changes.
COMP 110: Introduction to Programming Tyler Johnson January 14, 2009 MWF 11:00AM-12:15PM Sitterson 014.
Catie Welsh January 12, 2011 MWF 1-1:50 pm Sitterson
Java Basics. Java High-level language  More readable for humans  Need to be translated to machine language for execution Compilers  CPU-independent.
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.
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Java Byte Code l The Java compiler generates Java Byte Code. (Most.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
CS591x A very brief introduction to Java. Java Developed by Sun Microsystems was intended a language for embedded applications became a general purpose.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
1 Fencepost loops “How do you build a fence?”. 2 The fencepost problem Problem: Write a class named PrintNumbers that reads in an integer called max and.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
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.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
CS 106 Introduction to Computer Science I 01 / 31 / 2007 Instructor: Michael Eckmann.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
Mini University July, 2005 A Little Taste of Java (but don’t tell your folks) (they might think there’s caffeine involved)
JAVA PROGRAMMING WITH ECLIPSE PART 1 PLEASE READ ALL THE CONTENT ON THE SLIDES. WATCH THE RECOMMENDED VIDEOS LISTED.
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.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
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.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
Simple algorithms on an array - compute sum and min.
Slides prepared by Rose Williams, Binghamton University Console Input and Output.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Lecture 4 – Scanner & Style
User Input ICS2O.
Introduction to Java Import Scanner class to use in our program
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
CSC111 Quick Revision.
Input/Output.
Exercise 1- I/O Write a Java program to input a value for mile and convert it to kilogram. 1 mile = 1.6 kg. import java.util.Scanner; public class MileToKg.
Chapter No. : 1 Introduction to Java.
Java Course Review.
Chapter 3 GC 101 Java Fundamentals.
Chapter 2 Elementary Programming
Chapter 5: Control Structures II
Introduction to Computers and Java
Lecture Note Set 1 Thursday 12-May-05
CompSci 230 Software Construction
Repetition-Counter control Loop
Data types, Expressions and assignment, Input from User
Something about Java Introduction to Problem Solving and Programming 1.
Michele Weigle - COMP 14 - Spr 04
An Introduction to Java – Part I, language basics
Java Basics.
Week 4 Lecture-2 Chapter 6 (Methods).
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
(Computer fundamental Lab)
F II 2. Simple Java Programs Objectives
Random Numbers while loop
CSS161: Fundamentals of Computing
JAVA. Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of platforms, such.
Presentation transcript:

Introduction to Java Brief history of Java Sample Java Program Compiling & Executing

Introduction to Java History Invented in 1991 - James Gosling, Sun Microsystems, Inc. Originally a language for programming home appliances. Later (1994) used for internet applications and general-purpose programming. Why the name “Java”? Supposedly came from a list of random words (wikipedia). Sun Microsystems was purchased by Oracle Corporation in 2010.

Applets vs. Java Applications Java programs intended to be downloaded via the internet and run immediately. Typically embedded in a web-page and run in a web browser. “little applications” Applications: Java programs intended to be installed on a system and then executed. Often larger, more complex applications. Applets and applications are programmed slightly differently.

A Java Application import java.util.Scanner; public class FirstProgram { public static void main(String[] args) int n1, n2; System.out.println(“Hello”); System.out.println(“Enter two integers”); Scanner keyboard = new Scanner(System.in); n1 = keyboard.nextInt(); n2 = keyboard.nextInt(); System.out.println(“The sum is”); System.out.println(n1 + n2); }

Explanation of Code ... Code at the beginning of the program (to be explained later): import java.util.Scanner; public class FirstProgram { public static void main(String[] args) Java applications all have similar code at the beginning The name of the class differs from one program to another. The name of the class is also the name of the file.

… Explanation of Code ... The following creates two variables named n1, n2 for storing two whole numbers (integer): int n1, n2; These are called “variable declarations.” In this program they are used to store the user’s response.

Explanation of Code ... Display text strings to the screen: System.out.println(“Hello”); System.out.println(“Enter two integers”); Note the “dot” delimiter: System is a class out an object println is a method that outputs something Double-quoted text inside the parentheses is referred to as an argument or parameter to the method.

… Explanation of Code ... The following creates an object called keyboard of the Scanner class: Scanner keyboard = new Scanner(System.in); System.in refers to the keyboard The Scanner class provides the program with access to keyboard input.

… Explanation of Code ... The following inputs (or “reads”) two integers typed in from the keyboard and stores them in the variables n1 and n2: n1 = keyboard.nextInt(); n2 = keyboard.nextInt();

… Explanation of Code The following prints the sum to the console (or screen): System.out.println(“The sum is:”); System.out.println(n1 + n2); By the way, every character counts!

Compiling and Running a Java Program Type the program into a file: FirstProgram.jav Make sure you get the file name correct! Compile (from the command-line, i.e., DOS): javac <file>.java Run (and link): java <file> <file> must have a main method

Extra Work – Yippee! Type-in, compile and run the previous program. Experiment with “what if” scenarios: Add some syntax errors Run the program incorrectly – input improper data Modify the program to work with 3 ints