Basic Java Syntax CSE301 University of Sunderland Harry R Erwin, PhD.

Slides:



Advertisements
Similar presentations
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.
Advertisements

CERTIFICATION OBJECTIVES Use Class Members Develop Wrapper Code & Autoboxing Code Determine the Effects of Passing Variables into Methods Recognize when.
Constants and Data Types Constants Data Types Reading for this class: L&L,
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Review… Yong Choi BPA CSUB. Access Modifier public class HelloWorldApp –More detailes of Java key (reserved) wordJava key (reserved) word –The keyword,
Outline Java program structure Basic program elements
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Java Data Types  Everything is an Object  Except Primitive Data Types  For efficiency  Platform independent  Portable  “slow”  Objects are often.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.3 The Class String.
JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
Introduction to Java University of Sunderland CSE301 Harry R. Erwin, PhD.
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.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
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
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.
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.
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.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
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.
Fall 2015CISC124 - Prof. McLeod1 CISC124 Have you filled out the lab section survey? (As of last night 54 left to fill out the survey.) TA names have been.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
Introduction to Java COM379 (Part-Time) University of Sunderland Harry R Erwin, PhD.
Copyright Curt Hill Variables What are they? Why do we need them?
JAVA COURSE 1 Computer Engineering Association. Compile your first program Public class Hello{ public class Hello(){ System.out.println(“Hello”); } puclic.
Java 5 Part 2 CSE301 University of Sunderland Harry Erwin, PhD.
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,
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Classes, Interfaces and Packages
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
A data type in a programming language is a set of data with values having predefined characteristics.data The language usually specifies:  the range.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
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.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
JAVA MULTIPLE CHOICE QUESTION.
Working with Java.
Java Primer 1: Types, Classes and Operators
Multiple variables can be created in one declaration
University of Central Florida COP 3330 Object Oriented Programming
null, true, and false are also reserved.
Java Programming Language
Introduction to Java Programming
An overview of Java, Data types and variables
The Building Blocks Classes: Java class library, over 1,800 classes:
Chapter 1: Computer Systems
Units with – James tedder
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Programs and Classes A program is made up from classes
Focus of the Course Object-Oriented Software Development
Java Programming Review 1
Java Programming Language
Java Basics Data Types in Java.
Chap 2. Identifiers, Keywords, and Types
Presentation transcript:

Basic Java Syntax CSE301 University of Sunderland Harry R Erwin, PhD

Key Resources to Help You Learn Java You need to own and read Flanagan, Java in a Nutshell, 5th edition. My lectures are not enough to teach you Java. You need access to Flanagan’s other Nutshell books. You need an up-to-date Java 1.5 (or newer) compiler and run-time environment. You need access to eclipse You need to explore the Sun tutorials

Unicode Java is written in the Unicode character set. Unicode characters are stored in 16 bits (some Far Eastern languages require 21) and can represent almost all written languages. –A –å –π Java programs can be written in ASCII or Latin-1 characters, which most text editors support. Unicode can be used anywhere in a Java program.

Comments Single-line comments: //………….. Multi-line comments: /*…..*/ Doc comments: –Begin with /**…. –Provide embedded documentation –End with */ –Worth investigating further, because they allow you to write self-documenting codefiles. This is an easy way to meet some of the project requirements. –Extended in Java 5 (discussed in two weeks)

Scope of Names The ‘scope’ of a declaration is the region of the program within which the entity can be referred to using a simple name. Types must be imported or declared to be in scope. Members have class or interface scope. Method parameters have method scope. Local variables have block scope. When a name is hidden by another name, you must provide the full name. Sometimes (method parameters, for example) there is no full name you can use.

Identifiers Begin with a letter, underscore (_), or currency symbol (€$¥£). Contain any number of letters, numbers, underscores, and currency symbols. Avoid the currency symbols as compilers use them. Remember Unicode. The following are legal identifiers: –π –Ö

Primitive Data Types –boolean –char –short –byte –int –long –float –double Have machine-independent formats and default values. Know them! I usually ask a question on them in the TCT or exam.

String Contains Unicode text Constant—unlike C and C++ strings. A class, not a primitive type Literals consist of anything between a pair of double quotes. To include a double quote in a string, use \” Supports operator overloading (+, +=). This is the only place in Java where operator overloading takes place.

Type Conversions Integer to floating point are automatic. char to/from integer and floating point Widening conversions (e.g., short to long) are safe. Narrowing conversions are dangerous. You need to understand why. I usually ask a question on this in the TCT or exam.

Classes and Arrays Reference types. Created using the new operator –new type(args); // an object –new type[dim]; // 1-D array –new type[dim1][dim2] etc; //larger arrays A class or array object is null (does not exist) until it is initialized. Interfaces are reference types, too. Discussed in the next lecture.

Operators Generally as in C or C++. See the earlier lecture. Typecasting is handled by (type)var;, not type(var);!

Statements Generally as in C/C++. See the earlier lecture. Additional: –synchronized (threads) –throw (an exception) –try/catch/finally (to handle exceptions) –All the new Java 5 stuff (discussed in two weeks).

Methods Correspond to functions in C or C++, but are always associated with a class. Defined by their signature: –Name –Arguments –Return type (differs from C++, may be void) –Checked exceptions thrown –Method modifiers: public, static, abstract, final, native, private, protected, synchronized.

Method Modifiers public—can be called from anywhere static—defined at the class, not instance level abstract—must be defined by a subclass to be called final—no changes allowed native—calls native code private—hidden from other classes protected—visible in same package and subclasses synchronized—supports multithreading

Summary Java is not C or C++ Everything is either a primitive type or a reference type. Primitive types have default values, while reference types do not exist until they are initialized. Java smells like C and C++, but a language that smells may not be to your liking… 8)