Introduction to Java 2 Programming Lecture 2 Java Syntax, Robocode.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick The Programming Process rUse an editor to create a program file (source file). l contains the text of.
Advertisements

Introduction to Java 2 Programming Lecture 3 More Syntax; Working with Objects.
Introduction to Java 2 Programming Lecture 4 Writing Java Applications, Java Development Tools.
Introduction to Java 2 Programming
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Lecture 10 Methods COMP1681 / SE15 Introduction to Programming.
1 pritisajja.info Unlocking the World of Java Programming….. Priti Srinivas Sajja February, 2014 Visit pritisajja.info for detail Future Technology for.
Chapter 1: Computer Systems
CS1010 Programming Methodology
IT151: Introduction to Programming
MC697 Object-Oriented Programming Using Java. In this class, we will cover: How the class will be structured Difference between object-oriented programming.
Week 2 Recap CSE 115 – Spring Object Oriented Program System of objects that communicate with one another to solve some problem.
Getting Started with Java
Outline Java program structure Basic program elements
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Chapter 1 Introduction.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Programming Introduction to C++.
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 (
Introduction to C++ Programming Introduction to C++ l C is a programming language developed in the 1970's alongside the UNIX operating system. l C provides.
© 2006 Pearson Education Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
Java Language and SW Dev’t
CS107 Introduction to Computer Science Java Basics.
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.
© 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 –
The Java Programming Language
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.
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Style Guidelines. Why do we need style?  Good programming style helps promote the readability, clarity and comprehensibility of your code.
Java Syntax and Style JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin,
Introduction to C++ // Program description #include directives int main() { constant declarations variable declarations executable statements return.
Lecture 1 Introduction. 1-2 Your world is filled with objects. Many of these objects are controlled by computers. Computers rely on ___________ to determine.
Introduction to Java Java Translation Program Structure
Identifiers.
Copyright Curt Hill Variables What are they? Why do we need them?
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
Java Basic Syntax. Object - Objects have states and behaviors. –Example: A dog has states-color, name, breed as well as behaviors -wagging, barking, eating.
CPS120: Introduction to Computer Science Variables and Constants.
Adding and Eating Worms Mrs. C. Furman August 23, 2010.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Lecture 1 Introduction. © 2006 Pearson Addison-Wesley. All rights reserved 1-2 Your world is filled with objects. Many of these objects are controlled.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
The Essentials of a Java Program JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,
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.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Working with Java.
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
GC101 Introduction to computer and program
Chapter 3 GC 101 Java Fundamentals.
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
University of Central Florida COP 3330 Object Oriented Programming
Data types and variables
Mr. Shaikh Amjad R. Asst. Prof in Dept. of Computer Sci. Mrs. K. S
FUNDAMENTALS OF JAVA.
An Introduction to Java – Part I, language basics
Unit-1 Introduction to Java
Chapter 1: Computer Systems
elementary programming
Anatomy of a Java Program
Programming Introduction to C++.
Object Oriented Programming in java
Basic Java structural components
Presentation transcript:

Introduction to Java 2 Programming Lecture 2 Java Syntax, Robocode

Overview Java Syntax –Quick Overview Robocode –How it works –Writing Robots –Anatomy of a Robot Practical Exercises

Naming All Java syntax is case sensitive Valid Java names –Consist of letters, numbers, underscore, and dollar –Names can only start with letter or underscore –E.g. firstAttribute but not 1stAttribute Camel case convention –Java encourages long, explanatory names –Start with a lower case letter, with words capitalised –E.g. thisIsCamelCase, andSoIsThisAsWell

Classes One Java class defined in each.java file File name must match the name of the class –Otherwise there will be compilation errors –Class names start with an upper case letter Compiler will generate a.class file with same name –Contains the bytecode Classes defined using the class keyword.

Packages Group related classes together Each class in a package must have a unique name Indicate the package a class belongs to with the package keyword Recommended each class is put in a package Gain access to public classes in other packages using the import keyword –The JVM needs to know where the classes are defined before you can use them

Anatomy of a Java Source File package intro2java; import java.util.*; /** * A description of the class */ public class MyFirstClass { //public constants //attributes private boolean isSomething; private int aCounter; //methods public void doSomething() { //code goes here }

Examples (if) if (x == y) { //executes if true } if (somethingIsTrue()) { doSomething(); } else { doSomethingElse(); }

Example (for) int x=0; for (int i=1; i<=10; i++) { //code to repeat ten times x = x + i; }

Example (while) int x=0; while (x < 10) { doSomething(); x++; } //loop forever while (true) { }

Common Sources of Error Mistakes in naming –Wrong case, illegal names –class name and source file name not the same Missing semi-colon Missing curly brackets Incorrect Loop checks –Loop is too large/small, or occurs forever Testing equality –Assignment with = (single equals sign) –Comparison with == (two equals signs)

Overview Java Syntax –Quick Overview Robocode –How it works –Writing Robots –Anatomy of a Robot Practical Exercises

Anatomy of a Robot package yourname; import robocode.*; /** * Description of Robot */ public class MyRobot extends Robot { /** * Description of run method */ public void run() { //the robots behaviour }