CS 225 Java Review. Java Applications A java application consists of one or more classes –Each class is in a separate file –Use the main class to start.

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

MOD III. Input / Output Streams Byte streams Programs use byte streams to perform input and output of 8-bit bytes. This Stream handles the 8-bit.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 12 File Input and Output.
Expressions ► An expression can be a single variable, or can include a series of variables. If an expression includes multiple variables they are combined.
COMP 14 Introduction to Programming Miguel A. Otaduy May 17, 2004.
Lecture 3 Java Basics Lecture3.ppt.
Java Review Rem Collier. A Statement I have been asked to do these Lectures at YOUR request. They are to help YOU with any Java question that you have.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 12 File Input and Output.
1 Text File I/O Overview l I/O streams l Opening a text file for reading l Reading a text file l Closing a stream l Reading numbers from a text file l.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
Programming in Java; Instructor:Alok Mehta Objects, Classes, Program Constructs1 Programming in Java Objects, Classes, Program Constructs.
Review Java.
CS116 OBJECT ORIENTED PROGRAMMING II LECTURE 1 Part II GEORGE KOUTSOGIANNAKIS Copyright: 2015 Illinois Institute of Technology- George Koutsogiannakis.
MSc IT Programming Methodology (2). MODULE TEAM Dr Aaron Kans Dr Sin Wee Lee.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
1 Course Lectures Available on line:
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
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.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Classes and Methods Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2014.
Java ProgrammingtMyn1 Java Programming Timo Mynttinen Mikkeli University of Applied Sciences.
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.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
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.
CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Final Review Lecture 14.
CS61B L02 Using Objects (1)Garcia / Yelick Fall 2003 © UCB Kathy Yelick Handout for today: These lecture notes Computer Science 61B Lecture 2 – Using Objects.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
File IO Basics By Dan Fleck Coming up: Data Streams.
1 Programming Java Java Basics. 2 Java Program Java Application Program Application Program written in general programming language Applet Program running.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Copyright Curt Hill Variables What are they? Why do we need them?
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Java methods Methods break down large problems into smaller ones Your program may call the same method many times saves writing and maintaining same code.
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.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
I/O Basics Java does provide strong, flexible support for I/O related to files and networks. Java’s console based interaction is limited since in real.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
A High Flying Overview CS139 – Fall 2006 How far we have come.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Java Input / Output l a modular approach to input/output: - different stream objects are connected/wrapped to handle I/O l a data stream object: a flow.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology_ George Koutsogiannakis.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Basic Introduction to C#
Elementary Programming
Yanal Alahmad Java Workshop Yanal Alahmad
CS116 OBJECT ORIENTED PROGRAMMING II LECTURE 1 Part II
I/O Basics.
Java Programming: From Problem Analysis to Program Design, 4e
CS139 – Fall 2010 How far we have come
JAVA IO.
Computers & Programming Languages
Chapter 2: Basic Elements of Java
Sridhar Narayan Java Basics Sridhar Narayan
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Presentation transcript:

CS 225 Java Review

Java Applications A java application consists of one or more classes –Each class is in a separate file –Use the main class to start the application

main class Every application needs a main class (or driver) which contains a main method public class Driver { public static void main( String [] args) { }

Classes A class is a template for creating objects A class contains –Data declarations for representing the properties or attributes of an object created from the class –Method definitions for defining the behavior or operations of an object created from the class

Structure of a Java Class /** javadoc comment describing class */ public class ClassName { // Data declarations private DataType dataName; // method definitions /** javadoc comment describing method */ public returnType methodName( ) { }

Objects Objects are created (instantiated) from a class ClassName objectName = new ClassName(); There can be any number of objects created from a single class –Each object has its own data –A method has access to the data of the object is was called for

Java Statements Declarations Assignment Method calls Control Statements –if, switch –while, do, for

Declarations Use a declaration to create one or more variables varName1, varName2; Variables instance variables belong to an object static variables belong to a class local variables are declared inside a method

Data Types Primitive Types –integer types: byte, short, int, long –real types: float, double –character type: char –boolean has values true and false Reference Types –used for objects, arrays –declaration creates only the reference varaible –objects must be instantiated separately

Operators Arithmetic (numeric types only) : + - * / % Relational (numeric and char) : = > Relational (any type) : == != Logical (boolean): && || ! Assignment: = = et. al

Control Statements Sequence (block)- done in order { } Selection - select between different sequences if switch Repetition - do a sequence multiple times while do-while for

Methods Method definition public returnType methodName ( ) { } Method call objectName.methodName( )

Static Members Data and methods can be declared static –call static methods using the name of the class public static int objectCount –static methods need don't have access to object data –all objects share static data

Java API Java comes with an extensive collection of classes that are already written –Look at the documentation for these classes online Use a class from the Java library by importing it import java.packageName.ClassName;

Math class A collection of static methods and constants Math.PI Math.sqrt( double x) : double Math.sin( double x) : double Math.pow( double num, double power) : double … and many more

System Class Data and methods needed to interact with the OS System.in : InputStream for keyboard input System.out : PrintStream for console output System.exit( int exitCode) : stops the program

Handling Text String and StringBuffer can b used for text data –String is immutable StringTokenizer can be used to separate text into smaller pieces

Stream Classes for I/O Input –InputStream -> InputStreamReader - > BufferedReader (or Scanner ) –FileReader -> BufferedReader Output –OutputStream -> OutputStreamWriter -> PrintWriter –FileWriter -> PrintWriter

Arrays An array is an indexed collection of objects of the same type –arrays are objects To create an array: –declare it: dataType [] arrayName; –instantiate it: arrayName = new dataType[size] –assign or instantiate each element Get a particular element by index: arrayName[index]