CSC 243 - Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 4.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Programming in Java; Instructor:Alok Mehta Objects, Classes, Program Constructs1 Programming in Java Objects, Classes, Program Constructs.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
DAT602 Database Application Development Lecture 5 JAVA Review.
CSC Java Programming, Spring, 2014 Welcome to Java Programming. Tuesday, January 21, 2014.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Basic Java Syntax CSE301 University of Sunderland Harry R Erwin, PhD.
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.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
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.
Introduction to java Prepared By:-Pragnesh Patel Lect. In Computer Dept. NSIT,Jetalpur 1.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
1 Programming Java Java Basics. 2 Java Program Java Application Program Application Program written in general programming language Applet Program running.
Controlling Program Flow. Data Types and Variable Declarations Controlling Program Flow.
Java Programming Java Basics. Data Types Java has two main categories of data types: –Primitive data types Built in data types Many very similar to C++
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?
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6: Transition to Java Programming with Alice and Java First Edition.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
1 Chapter 5: Defining Classes. 2 Basics of Classes An object is a member of a class type What is a class? Fields & Methods Types of variables: –Instance:
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Java Nuts and Bolts Variables and Data Types Operators Expressions Control Flow Statements Arrays and Strings.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming - Week.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
CSC Java Programming, Fall, 2008 Week 3: Objects, Classes, Strings, Text I/O, September 11.
Java Part I By Wen Fei, HAO. Program Structure public class ClassName { public static void main(String[] args) { program statements } user defined methods.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
CSC Java Programming, Spring, 2010 Week 2: Java Data Types, Control Constructs, and their C++ counterparts.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
CSC Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 9.
CSC Java Programming, Fall, 2008 August 28, 2008, class 2 Tuesday, September 2 uses Monday’s schedule!
CompSci 100E JB1.1 Java Basics (ala Goodrich & Tamassia)  Everything is in a class  A minimal program: public class Hello { public static void main(String[]
Object Oriented Programming Lecture 2: BallWorld.
Java Programming Language Lecture27- An Introduction.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Chapter 7 User-Defined Methods.
Internet and Java Foundations, Programming and Practice
CSC Java Programming, Spring, 2010
An Introduction to Java – Part I
Introduction to Programming in Java
Starting JavaProgramming
Unit-2 Objects and Classes
null, true, and false are also reserved.
An Introduction to Java – Part I, language basics
An overview of Java, Data types and variables
Sridhar Narayan Java Basics Sridhar Narayan
Chap 2. Identifiers, Keywords, and Types
CSC Java Programming, Spring, 2012
CSC Java Programming, Spring, 2009
CSC Java Programming, Spring, 2013
Presentation transcript:

CSC Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 4

References GNU make docs. has on-line docs. class lib. /export/home/faculty/parson/JavaLang on bill.kutztown.edu Make sure that /usr/jdk/jdk1.6.0_02/bin is near the front of UNIX PATH. Follow instructions in the JavaShellSetup.pdf document (accessible via my home page at to set up and verify your Java compilation environment.JavaShellSetup.pdfhttp://faculty.kutztown.edu/parson

First example Java program CountArgString counts distinct, non- overlapping occurrences of a string in a file /export/home/faculty/parson/JavaLang/week1/lecture1 Make sure you “cp –pr ~parson/JavaLang ~/JavaLang to get JavaLang into your home directory Make sure CLASSPATH include your $HOME/JavaLang makefile drives execution of compile and test steps gmake build to compile Java files gmake test to run test cases gmake clean to clean up test output and compiled files

Summary of Java built-in types Primitive type variables are not class objects byte is 8-bit signed, -128 through 127 (page 32 in text) short is 16-bit signed, through int is 32-bit signed, long is 64-bit signed float is 32-bit type and double is 64-bit type boolean is 1-bit true or false, char is UNICODE Some class types are built into the language java.lang.String a class built into the language Wrapper classes in java.lang wrap native types as classes. Examples are Integer, Float, Long, Double.

Summary of Java control constructs boolean (true or false) is the basis for control flow /export/home/faculty/parson/JavaLang/week1/bool for, while and do-while loops, just like C++ if.. else if.. else selection, just like C++ switch statement (text p. 86) also like C++ break exits the innermost loop or switch continue goes to the top of innermost loop There are no stand-alone functions! A method always exists inside a class. A non-static method uses a class object. A static method uses only class-static data.

Java Methods A method is equivalent to a C++ member function. In Java all methods resides in classes. A static method does not require an object. int intvar = java.lang.Integer.parseInt(“2”); System.out.println(“integer: “ + intvar); Statics method use static class variables. A regular method needs an object reference. Integer intObject = new Integer(“3”); System.out.println(“integer: “ + intObject.intValue());

Java storage of class and object data Only one copy of a static data element exists for its class. Both static methods and non- static methods (object methods) can use it. static java.lang.String oneStringPerClass = new String(); There is one copy of each non-static data element in each object. Only non-static methods can use it. String oneStringPerObject = new String(“my value”);

Java access to class and object methods and data Public methods and data can be used by any code that imports the class. Protected methods and data can be used only by the defining class and derived classes. Private methods and data can be used only by the defining class. If there is no explicit access restriction, then package methods and data can be used by any class in the package.

Boolean example code /export/home/faculty/parson/JavaLang/week1/bool Make sure you have a copy of this. cp –pr ~parson/JavaLang/week1/bool ~/JavaLang/week1/bool Program verifies valid command line args. 1. Program reads command line into an array of integers, raising an Exception if any of the command line arguments is not an integer. 2. Verify that array is in ascending order using &&. 3. Verify that array is in ascending order using ||.