Java.

Slides:



Advertisements
Similar presentations
Java.
Advertisements

Chapter 1: Computer Systems
Programming with Java. Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the.
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
1 Kursusform  13 uger med: Undervisning i klassen 1,5-2 timer Opgave ”regning” i databar (løsninger på hjemmeside) En midtvejsopgave der afleveres og.
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
The Java Programming Language
CMT Programming Software Applications
Outline Java program structure Basic program elements
Chapter 1 Introduction. © 2004 Pearson Addison-Wesley. All rights reserved1-2 Outline Computer Processing Hardware Components Networks The Java Programming.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Chapter 1 Introduction.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Java: Chapter 1 Computer Systems Computer Programming II Aug
Chapter 1 Introduction.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
Chapter 1 Programming Languages. Application Development: Top 10 Programming Languages to Keep You Employed 1. Java 2. C# 3. C++ 4. JavaScript 5. Visual.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley John Lewis, Peter DePasquale, and Joseph Chase Chapter 1: Introduction.
© 2006 Pearson Education Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
Java: Chapter 1 Computer Systems Computer Programming II.
Java Language and SW Dev’t
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
Introduction. Objectives An overview of object-oriented concepts. Programming and programming languages An introduction to Java 1-2.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 2: Java Fundamentals
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Chapter 1: Introduction Java Programming Language How the Java Virtual Machine Works (compiling, etc…) Update by: Dan Fleck Coming up: The Java Programming.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Lecture 2 Software Concepts Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
1 Problem Solving b The purpose of writing a program is to solve a problem b The general steps in problem solving are: Understand the problemUnderstand.
White Space Spaces, blank lines, and tabs are collectively called white space and are used to separate words and symbols in a program Extra white space.
Intro to Programming  Chapter 1 Part 2  Problem Solving.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Working with Java.
University of Central Florida COP 3330 Object Oriented Programming
1.3 Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: Understand the problem Dissect the.
Unit 41 – Programing in Java
Starting JavaProgramming
null, true, and false are also reserved.
Introduction to Java Programming
An overview of Java, Data types and variables
Chapter 1: Computer Systems
Units with – James tedder
Units with – James tedder
Java Software Solutions Foundations of Program Design 9th Edition
Focus of the Course Object-Oriented Software Development
Instructor: Alexander Stoytchev
Chap 2. Identifiers, Keywords, and Types
Computer Programming-1 CSC 111
Instructor: Alexander Stoytchev
Presentation transcript:

Java

Java A programming language specifies the words and symbols that we can use to write a program Syntax: A programming language employs a set of rules that dictate how the words and symbols can be put together to form valid program statements The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since Java is an object-oriented programming language

Java In the Java programming language, all source code is first written in plain text files ending with the .java extension. – We will use DrJava text editor for our IDE. Those source files are then compiled into .class files by the javac compiler. – It will compile to run on any machine. It is said to be neutral. A .class file contains bytecodes — the machine language of the Java Virtual Machine (Java VM). The source code must be compiled to bytecode.

Java Virtual Machine Because the Java VM is available on many different operating systems, the same .class files are capable of running on Microsoft Windows, the Solaris TM Operating System (Solaris OS), Linux, or Mac OS. This makes Java platform neutral.

How to type the Java source code Through an editor or IDE (Integrated Development Environment.) Editor will generally highlight the Java syntax, indent for you, balance your parentheses and braces, and let you compile from within the editor. IDEs have visual Java development tools, tight integration with the compiler or application server, and may include tools for debugging, refactoring, version control, and so forth. We will use Dr. Java as our IDE.

What is DrJava? DrJava is a free integrated development environment for doing Java programming From Rice University It is written in Java It has several window panes in it For creating programs (definitions pane) For trying out Java code (interactions pane) Listing of open files (files pane) The pane that shows the code (on the right) is called the definitions pane. The pane that allows you to type Java expressions and see the result is called the interactions pane.

Dr. Java Files Pane – List the open files in Dr. Java Definitions pane – This is where you write your classes. Simply a text editor. You compile all current files open in the files pane b y clicking on the compile all Interactions Pane – You can type commands and it will execute but not save.

Java Program Structure In the Java programming language: A program is made up of one or more classes Every program typed is in a class. Class – blueprint for creating objects that have properties and methods.

The Java Application Programming Interface (API ) The API is a large collection of ready-made software components that provide many useful capabilities. It is grouped into libraries of related classes and interfaces; these libraries are known as packages.

What Is a Package? A package is a namespace that organizes a set of related classes and interfaces. What is a class: A class is a generic template for a set of objects with similar features. All the GUI tools we will use are in a class called javax.swing. The Java platform provides an enormous class library (a set of packages) suitable for use in your own applications. This library is known as the "Application Programming Interface", http://java.sun.com/javase/6/docs/api/index.html

Java Program Structure // comments about the class All classes begin and end with a curly brace public class MyProgram { } class header class body Comments can be placed almost anywhere

Java Program Structure // comments about the class public class MyProgram { } // comments about the method public static void main (String[] args) { } method header method body All methods begin and end with a curly brace

Main method public static void main(String[]args) { // program statements to print and execute }

Saving a File You must save the java file with the same name as the class name. It will save it with a .java extension. The command to execute a compiled Java application in run.

Comments Comments in a program are called inline documentation They should be included to explain the purpose of the program and describe processing steps They do not affect how a program works Java comments can take three forms: // this is a single line comment /* this is a multi-line comment that will * take more than one line **/ /** this is a javadoc comment. Used by Programs for documentation. */

Identifiers Identifiers are the words a programmer uses in a program. Can be reserved words Java has created or variables the programmer creates. Rules for identifiers: An identifier can be made up of letters, digits, the underscore character ( _ ), and the dollar sign Identifiers cannot begin with a digit Java is case sensitive - Total, total, and TOTAL are different identifiers By convention, Java programmers use different case styles for different types of identifiers, such as title case for class names - Lincoln upper case for constants - MAXIMUM

Reserved Words The Java reserved words: these are words Java has pre-defined for a special purpose. You cannot create a variable, class name or method name with these words. abstract assert boolean break byte case catch char class const continue default do double else enum extends false final finally float for goto if implements import instanceof int interface long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while

White Space Spaces, blank lines, and tabs are called white space White space is used to separate words and symbols in a program Extra white space is ignored A valid Java program can be formatted in many ways Programs should be formatted to enhance readability, using consistent indentation

There are 8 Primitive data types in Java. Data type tells the kind of information that will be stored in memory. TYPE What it hold RANGE byte Whole number 8 bits -128 to 127 short 16 bits -32768 to 32767 int whole numbers 32 bits -2 billion to 2 billion long 64 bits -big to +big float Fractional number 32 bits -big to +big double fractional number 64 bits -1.7E+308 to 1.7E+308 char ‘A’ One character 16-bit boolean True or false value Holds two values: {true, false}

Object Turtle Object 1 Turtle Object 2 Objects are made from the class they belong to. You can create several objects from a class – like a cookie cutter. Turtle: Class JOptionPane jp = new JOptionPane(); Class Variable name New object created

Objects Objects - instance of a class. Objects have attribute or state A state is a property or something the object knows about itself. Turtle - size, color, name, age

Objects Objects have methods / Behavior / Actions Things it knows how to do. Turtle - turn, turnRight, turnLeft, forward

Argument / Parameter Parameter is extra information required to the object or method. Turtle tom(130, earth); They always appear in parenthesis. Parameter – the information inside is called arguments It is required so the Turtle will know where he is in the world and what world to be in.

Variables – stores value in a memory location Programming uses variables. You need to learn this! Declare is to tell what type of data the variable will hold and its name int number; double money; boolean done; You cannot use a variable until you declare the type Initialize is to assign the variable a value using the = sign int number = 37; double money = 28.42; boolean done = true;

Statements Statements in Java are commands. All statements end in a semicolon

Constants Constants are variables that once assigned cannot change. They are identified by using the final and capitalizing the variable name. final int SALARY;

Assignment Operator The = sign is the assignment operator for variables. int num = 2; boolean done = true; double average = 4.5;

Arithmetic Statements 45 /2 45 and 2 are called operand. er Operators are: +, - , * , / , % Addition, substraction, multiplication, and modulus (remainder operator).

System Class Basic print statement in Java System.out.println(“This will print”); System is a class. out is the object created from the System class println is the method from the System class that allows it to print. class object method A period separates classes, objects and methods.

Print and Println Methods //******************************************************************** // Countdown.java Author: Lewis/Loftus/Cocking // // Demonstrates the difference between print and println. public class Countdown { //----------------------------------------------------------------- // Prints two lines of output representing a rocket countdown. public static void main (String[] args) System.out.print ("Three... "); System.out.print ("Two... "); System.out.print ("One... "); System.out.print ("Zero... "); System.out.println ("Liftoff!"); // appears on first output line System.out.println ("Houston, we have a problem."); } What will this program output look like Three…Two…One…Zero…Liftoff! Houston, we have a problem.

String Literals The part inside the “ double quotes “ is called a String Literal. Concatenation: Add one String to another using the + sign. “ “ makes a space System.out.println(“This is a String” + “ “ + “and this is another one.”);

Control Structures There are 3 basic control structures in Java Sequential Flow - Everything in order Conditional or selection: if statements that make a decision Iteration: Loop or a repeated instruction