Java Programming Tutorial 1
|
|
- Monica Norris
- 6 years ago
- Views:
Transcription
1 Java Programming Tutorial 1
2 Every programming language has two defining characteristics: Syntax Semantics
3 Programming Writing code with good style also provides the following benefits: It improves the readability, consistency, and homogeneity of the code, which makes it easier to understand and maintain. It makes the code easier to trace and debug, because it's clear and consistent. It allows you to continue more easily where you or another programmer stopped, particularly after a long period of time. It increases the benefit of code walkthroughs, because the participants can focus more on what the code is doing.
4 General Guidelines: Writing Java with good style is not hard, but it does require attention to detail. Here are some general guidelines to follow: Make the code clear and easy to read. Make the code consistent. Use obvious identifier names. Logically organize your files and classes. Have only one class per file (not including inner classes). Use a maximum line width of characters. Use whitespace and/or other separators judiciously. Use spaces instead of tabs for indentation.
5 The Java language supports three kinds of comments: /* text */ The compiler ignores everything from /* to */. /** documentation */ This indicates a documentation comment (doc comment, for short). The compiler ignores this kind of comment, just like it ignores comments that use /* and */. The JDK javadoc tool uses doc comments when preparing automatically generated documentation. For more information on javadoc, see the Java tool documentation. // text The compiler ignores everything from // to the end of the line.
6 Comments There are two type of comments that you can put in your Java code: Javadoc comments (also called documentation comments) and implementation comments. Javadoc comments can be extracted by the javadoc tool to produce API documentation. Implementation comments are those comments that explain the how and why of the code. Use Also, keep in mind that good comments are helpful; bad comments are a nuisance. Example 1. Bad Comment Style // applyrotascii() -- Apply ASCII ROT private void applyrotascii(){ try{ int rotlength = Integer.parseInt(rotationLengthField.getText().trim()); // get rot len RotAscii cipher = new RotAscii(rotLength); // new cipher textarea.settext(cipher.transform(textarea.gettext())); // transform catch(exception ex){ /* Show exception */ ExceptionDialog.show(this, "Invalid rotation length: ", ex);
7 Example 2. Good Comment Style. /** * Apply the ASCII rotation cipher to the user's text. The length is retrieved * from the rotation length field, and the user's text is retrieved from the * text area. * Thornton Rose */ private void applyrotascii() { int rotlength = 0; // rotation length RotAscii cipher = null; // ASCII rotation cipher try { // Get rotation length field and convert to integer. rotlength = Integer.parseInt(rotationLengthField.getText().trim()); // Create ASCII rotation cipher and transform the user's text with it. cipher = new RotAscii(rotLength); textarea.settext(cipher.transform(textarea.gettext())); catch(exception ex) { // Report the exception to the user. ExceptionDialog.show(this, "Invalid rotation length: ", ex);
8 Blocks and Statements Use the following guidelines for writing blocks and statements: Put only one statement per line. Always use braces with control statements (e.g., 'if'). Consider marking the end of a block with a comment (e.g., // end if), particularly with long or nested blocks. Put variable declarations at the beginning of a block. Always initialize variables.. Indent the case clauses in a switch block. Put whitespace before and after operators. In if, for, or while, put whitespace before the "(". Use whitespace and parentheses in expressions to increase readability.
9 Example 3. Bad Block Style. try{ for(int i=0;i<5;i++){... int threshold=calculatethreshold(); float variance=(threshold*2.8)-1; int c=0; if (threshold<=15) c=calculatecoefficient(); switch(c){ case 1: setceiling(c*2); break; case 2: setceiling(c*3); break; else: freakout(); catch(exception ex){...
10 Example 4. Good Block Style. try { int threshold = 0; float variance = 0.0; int coefficient = 0; // Prepare 5 cycles. for (int i = 0; i < 5; i ++){ preparecycle(i); // Calculate the threshold and variance. threshold = calculatethreshold(); variance = (threshold * 2.8) - 1; // If the threshold is less than the maximum, calculate the coefficient. // Otherwise, throw an exception. if (threshold <= MAX_THRESHOLD) { coefficient = calculatecoefficient(); else { throw new RuntimeException("Threshold exceeded!"); // Set the ceiling based on the coefficient. switch (coefficient) { case 1: setceiling(coefficient * 2); break; case 2: setceiling(coefficient * 3); break; else: freakout(); // end switch
11 Bytecode Programming code that, once compiled, is run through a virtual machine instead of the computer's processor. By using this approach, source code can be run on any platform once it has been compiled and run through the virtual machine. Bytecode is the compiled format for Java programs. Once a Java program has been converted to bytecode, it can be transferred across a network and executed by Java Virtual Machine (JVM). Bytecode files generally have a.class extension.
12 JVM A Java virtual machine (JVM), an implementation of the Java Virtual Machine Specification, interprets compiled Java binary code (called bytecode) for a computer's processor (or "hardware platform") so that it can perform a Java program's instructions. Java was designed to allow application programs to be built that could be run on any platform without having to be rewritten or recompiled by the programmer for each separate platform. A Java virtual machine makes this possible because it is aware of the specific instruction lengths and other particularities of the platform. The Java Virtual Machine Specification defines an abstract -- rather than a real -- machine or processor. The Specification specifies an instruction set, a set of registers, a stack, a "garbage heap," and a method area. Once a Java virtual machine has been implemented for a given platform, any Java program (which, after compilation, is called bytecode) can run on that platform. A Java virtual machine can either interpret the bytecode one instruction at a time (mapping it to a real processor instruction) or the bytecode can be compiled further for the real processor using what is called a just-in-time compiler.
13 Object-Oriented Programming Concepts Object: is an instance of a class Class: is a template for an object Inheritance: allows the creation of hierarchical classification class MountainBike extends Bicycle { // new fields and methods defining a mountain bike would go here Interface: allows a set of methods to be implemented by one or more classes class ACMEBicycle implements Bicycle { // remainder of this class implemented as before Package: a namespace for organizing related classes and interfaces in a logical manner
14 Class Definition Every Java program is defined as a class. A class is a collection of data, stored in named fields, and coded, organized into named methods, that operates on that data. The fields and methods are called members of a class. The members of a class come in two distinct types: class, or static, members are associated with the class itself, while instance members are associated with individual instances of the class (i.e., with objects) There are four types of members: Class fields Class methods Instance fields Instance methods
15 Class Is a template that defines attributes and methods Is written by a programmer as a part of a program Does not exist when programs execute, except in the form of one or more member objects Is static in the sense that its code cannot be altered during program execution Is named by a class name
16 Object Must belong to some class Exists during the time that a program executes Must be explicitly declared and constructed by the execution program Has attributes that can change in value and method that can execute during program execution( The class to which the object belongs defines these attributes and methods. )
17 Classfield A classfield is associated with the class in which it is defined, rather than with an instance of the class. The following line declares a class field: public static final double PI = ; The static modifier says that the field is a class field. Class fields are sometimes called static fields because of this static modifier. The final modifier says that the value of the field does not change. the public modifier says that anyone can use the field. The key point to understand about a static field is that there is only a single copy of it. This field is associated with the class itself, not with instances of the class. A class field is essentially a global variable.
18 Class method As with class fields, class methods are declared with the static modifier: public static double radianstodegrees(double rads) { return rads * 180 / PI; Like class fields, class methods are associated with a class, rather than with an object. When invoking a class method from code that exists outside the class, you must specify both the name of the class and the method. A class method can use any class fields and class methods of its own class (or of any other class). But it cannot use any instance fields or instance methods because class methods are not associated with an instance of the class. class method is a global method, or global function.
19 Instance Fields Any field declared without the static modifier is an instancefield : public double r; // The radius of the circle Instance fields are associated with instances of the class, rather than with the class itself. Thus, every Circle object we create has its own copy of the double field r. In our example, r represents the radius of a circle. Thus, each Circle object can have a radius independent of all other Circle objects. Inside a class definition, instance fields are referred to by name alone. In code outside the class, the name of an instance method must be prepended by a reference to the object that contains it. For example, if we have a Circle object named c, we can refer to its instance field r as c.r Circle c = new Circle(); // Create a new Circle object; store it in variable c c.r = 2.0; // Assign a value to its instance field r, Circle d = new Circle(); // Create a different Circle object d.r = c.r * 2; // Make this one twice as big
20 Instance Methods Any method not declared with the static keyword is an instance method. An instancemethod operates on an instance of a class (an object) instead of operating on the class itself. To use an instance method from outside the class in which it is defined, we must prepend a reference to the instance that is to be operated on. For example: Circle c = new Circle(); // Create a Circle object; store in variable c c.r = 2.0; // Set an instance field of the object double a = c.area(); // Invoke an instance method of the object
21 Declaring Variables There are several kinds of variables: Member variables in a class these are called fields. Variables in a method or block of code these are called local variables. Variables in method declarations these are called parameters. Field declarations are composed of three components, in order: Zero or more modifiers, such as public or private. The field's type. The field's name.
22 public class Bicycle { Example private int cadence; private int gear; private int speed; public Bicycle(int startcadence, int startspeed, int startgear) { gear = startgear; cadence = startcadence; speed = startspeed; public int getcadence() { return cadence; public void setcadence(int newvalue) { cadence = newvalue; public int getgear() { return gear; public void setgear(int newvalue) { gear = newvalue; public int getspeed() { return speed; public void applybrake(int decrement) { speed -= decrement; public void speedup(int increment) { speed += increment;
23 Methods More generally, method declarations have six components, in order: Modifiers such as public, private,... The return type the data type of the value returned by the method, or void if the method does not return a value. The method name the rules for field names apply to method names as well, but the convention is a little different. The parameter list in parenthesis a comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses, (). If there are no parameters, you must use empty parentheses. An exception list The method body, enclosed between braces the method's code, including the declaration of local variables, goes here.
24 Overloading Methods The Java programming language supports overloading methods. public class DataArtist {... public void draw(string s) {... public void draw(int i) {... public void draw(double f) {... public void draw(int i, double f) {...
25 Constructors A class contains constructors that are invoked to create objects from the class blueprint. Constructor declarations look like method declarations except that they use the name of the class and have no return type. For example, Bicycle has one constructor: public Bicycle(int startcadence, int startspeed, int startgear) { gear = startgear; cadence = startcadence; speed = startspeed; To create a new Bicycle object called mybike, a constructor is called by the new operator: Bicycle mybike = new Bicycle(30, 0, 8) //new Bicycle(30, 0, 8) creates space in memory for the object and initializes its fields Although Bicycle only has one constructor, it could have others, including a no-argument constructor: public Bicycle() { gear = 1; cadence = 10; speed = 0; Bicycle yourbike = new Bicycle(); invokes the no-argument constructor to create a new Bicycle object called yourbike.
26 Creating Objects Creating objects has three parts: Declaration: is variable declarations that associate a variable name with an object type. Instantiation: The new keyword is a Java operator that creates the object. The new operator instantiates a class by allocating memory for a new object and returning a reference to the object it created. Initialization: The new operator is followed by a call to a constructor, which initializes the new object.
27 Parameters You can use any data type for a parameter of a method or a constructor. This includes primitive data types, such as doubles, floats, and integers, as you saw in the computepayment method, and reference data types, such as objects and arrays. public Polygon polygonfrom(point[] corners) { // method body goes here public double computepayment(double loanamt, double rate, double futurevalue, int numperiods) { double interest = rate / 100.0; double partial1 = Math.pow((1 + interest), -numperiods); double denominator = (1 - partial1) / interest; double answer = (-loanamt / denominator)- ((futurevalue * partial1) / denominator); return answer;
28 Class level access modifiers Only two access modifiers is allowed, public and no modifier If a class is public, then it CAN be accessed from ANYWHERE. If a class has no modifer, then it CAN ONLY be accessed from same package.
29 Controlling Access to Members of a Class Access level modifiers determine whether other classes can use a particular field or invoke a particular method. At the member level public, private, protected, or package-private (no explicit modifier). Modifier Class Package Subclass World Public Y Y Y Y Protected Y Y Y N No modifier Y Y N N Private Y N N N
30 Thanks for your attension!
Lesson: Classes and Objects
Lesson: Classes and Objects With the knowledge you now have of the basics of the Java programming language, you can learn to write your own classes. In this lesson, you will find information about defining
More informationCS260 Intro to Java & Android 03.Java Language Basics
03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance
More informationUniversiti Malaysia Perlis
Universiti Malaysia Perlis EKT420: SOFTWRE ENGINEERING Lab 5: Inheritance and Interfaces Pusat Pengajian Kejuruteraan Komputer Dan Perhubungan Universiti Malaysia Perlis 1 INHERITANCE Object-oriented programming
More informationInheritance, part 2: Subclassing. COMP 401, Spring 2015 Lecture 8 2/3/2015
Inheritance, part 2: Subclassing COMP 401, Spring 2015 Lecture 8 2/3/2015 Motivating Example lec8.ex1.v1 Suppose we re writing a university management system. Interfaces: Person get first and last name
More informationJava Primer 1: Types, Classes and Operators
Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,
More informationLecture 2: Java & Javadoc
Lecture 2: Java & Javadoc CS 62 Fall 2018 Alexandra Papoutsaki & William Devanny 1 Instance Variables or member variables or fields Declared in a class, but outside of any method, constructor or block
More informationInheritance. The Java Platform Class Hierarchy
Inheritance In the preceding lessons, you have seen inheritance mentioned several times. In the Java language, classes can be derived from other classes, thereby inheriting fields and methods from those
More informationIntroduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview
Introduction to Visual Basic and Visual C++ Introduction to Java Lesson 13 Overview I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Overview JDK Editions Before you can write and run the simple
More informationOutline. Object-Oriented Design Principles. Object-Oriented Design Goals. What a Subclass Inherits from Its Superclass?
COMP9024: Data Structures and Algorithms Week One: Java Programming Language (II) Hui Wu Session 1, 2014 http://www.cse.unsw.edu.au/~cs9024 Outline Inheritance and Polymorphism Interfaces and Abstract
More informationComputer Science 210: Data Structures
Computer Science 210: Data Structures Summary Today writing a Java program guidelines on clear code object-oriented design inheritance polymorphism this exceptions interfaces READING: GT chapter 2 Object-Oriented
More informationData Types. Lecture2: Java Basics. Wrapper Class. Primitive data types. Bohyung Han CSE, POSTECH
Data Types Primitive data types (2015F) Lecture2: Java Basics Bohyung Han CSE, POSTECH bhhan@postech.ac.kr Type Bits Minimum Value Maximum Value byte 8 128 127 short 16 32768 32767 int 32 2,147,483,648
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationCS 231 Data Structures and Algorithms, Fall 2016
CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard
More information12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.
Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationJava OOP (SE Tutorials: Learning the Java Language Trail : Object-Oriented Programming Concepts Lesson )
Java OOP (SE Tutorials: Learning the Java Language Trail : Object-Oriented Programming Concepts Lesson ) Dongwon Jeong djeong@kunsan.ac.kr; http://ist.kunsan.ac.kr/ Information Sciences and Technology
More informationIntroduction and Review of Java: Part 2
Introduction and Review of Java: Part 2 Fundamental Concepts (Principles) of Object Oriented Programming Java s implementation of Object Oriented Programming 1of 59 WHAT IS OBJECT ORIENTED PROGRAMMING?
More informationChapter 6 Introduction to Defining Classes
Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of
More informationOutline. Why Java? (1/2) Why Java? (2/2) Java Compiler and Virtual Machine. Classes. COMP9024: Data Structures and Algorithms
COMP9024: Data Structures and Algorithms Week One: Java Programming Language (I) Hui Wu Session 2, 2016 http://www.cse.unsw.edu.au/~cs9024 Outline Classes and objects Methods Primitive data types and operators
More informationJava Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing
Java Programming MSc Induction Tutorials 2011 Stefan Stafrace PhD Student Department of Computing s.stafrace@surrey.ac.uk 1 Tutorial Objectives This is an example based tutorial for students who want to
More informationJava Bytecode (binary file)
Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More information(SE Tutorials: Learning the Java Language Trail : Interfaces & Inheritance Lesson )
(SE Tutorials: Learning the Java Language Trail : Interfaces & Inheritance Lesson ) Dongwon Jeong djeong@kunsan.ac.kr; http://ist.kunsan.ac.kr/ Information Sciences and Technology Laboratory, Dept. of
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationSri Vidya College of Engineering & Technology
UNIT I INTRODUCTION TO OOP AND FUNDAMENTALS OF JAVA 1. Define OOP. Part A Object-Oriented Programming (OOP) is a methodology or paradigm to design a program using classes and objects. It simplifies the
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationIntroduction to. Android Saturday. Yanqiao ZHU Google Camp School of Software Engineering, Tongji University. In courtesy of The Java Tutorials
Introduction to Android Saturday Yanqiao ZHU Google Camp School of Software Engineering, Tongji University In courtesy of The Java Tutorials Getting Started Introduction to Java The Java Programming Language
More informationTony Valderrama, SIPB IAP 2009
Review Summary of topics from Tuesday Corrections Brief example of interactive application Static imports Compiling and executing from command line Class members More details about compiler/runtime environment
More informationProgramming overview
Programming overview Basic Java A Java program consists of: One or more classes A class contains one or more methods A method contains program statements Each class in a separate file MyClass defined in
More informationJava How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;
More informationWhat is the output of the following code segment:
Question 1: (12 Marks) a- what is the output made by the following portion of code int i =1, V=0, W=0; while (i
More informationLanguage Reference Manual
ALACS Language Reference Manual Manager: Gabriel Lopez (gal2129) Language Guru: Gabriel Kramer-Garcia (glk2110) System Architect: Candace Johnson (crj2121) Tester: Terence Jacobs (tj2316) Table of Contents
More informationProgram Correctness and Efficiency. Chapter 2
Program Correctness and Efficiency Chapter 2 Chapter Objectives To understand the differences between the three categories of program errors To understand the effect of an uncaught exception and why you
More informationChapter 2 Author Notes
Chapter 2 Author Notes Good Programming Practice 2.1 Every program should begin with a comment that explains the purpose of the program, the author and the date and time the program was last modified.
More informationAssoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine
More informationJava Style Guide. 1.0 General. 2.0 Visual Layout. Dr Caffeine
September 25, 2002 Java Style Guide Dr Caffeine This document defines the style convention the students must follow in submitting their programs. This document is a modified version of the document originally
More informationIT 374 C# and Applications/ IT695 C# Data Structures
IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation
More informationComputer Components. Software{ User Programs. Operating System. Hardware
Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point
More informationCSE 142 Su 04 Computer Programming 1 - Java. Objects
Objects Objects have state and behavior. State is maintained in instance variables which live as long as the object does. Behavior is implemented in methods, which can be called by other objects to request
More informationJava How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 10/e Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved. Data structures Collections of related data items. Discussed in depth in Chapters 16 21. Array objects Data
More informationCMSC 132: Object-Oriented Programming II
CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation
More informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction
Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationObject Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.
CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java
More informationKey Differences Between Python and Java
Python Python supports many (but not all) aspects of object-oriented programming; but it is possible to write a Python program without making any use of OO concepts. Python is designed to be used interpretively.
More informationOutline. Java Compiler and Virtual Machine. Why Java? Naming Conventions. Classes. COMP9024: Data Structures and Algorithms
COMP9024: Data Structures and Algorithms Week One: Java Programming Language (I) Hui Wu Session 1, 2015 http://www.cse.unsw.edu.au/~cs9024 Outline Classes and objects Methods Primitive data types and operators
More informationOutline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors
Outline Overview history and advantage how to: program, compile and execute 8 data types 3 types of errors Control statements Selection and repetition statements Classes and methods methods... 2 Oak A
More informationZhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson
Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program
More informationLecture 02, Fall 2018 Friday September 7
Anatomy of a class Oliver W. Layton CS231: Data Structures and Algorithms Lecture 02, Fall 2018 Friday September 7 Follow-up Python is also cross-platform. What s the advantage of Java? It s true: Python
More informationSTRUCTURING OF PROGRAM
Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the
More informationFundamental Concepts and Definitions
Fundamental Concepts and Definitions Identifier / Symbol / Name These terms are synonymous: they refer to the name given to a programming component. Classes, variables, functions, and methods are the most
More informationCS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find
CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS
More information13 th Windsor Regional Secondary School Computer Programming Competition
SCHOOL OF COMPUTER SCIENCE 13 th Windsor Regional Secondary School Computer Programming Competition Hosted by The School of Computer Science, University of Windsor WORKSHOP I [ Overview of the Java/Eclipse
More informationCS201 Some Important Definitions
CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler
More informationComments are almost like C++
UMBC CMSC 331 Java Comments are almost like C++ The javadoc program generates HTML API documentation from the javadoc style comments in your code. /* This kind of comment can span multiple lines */ //
More informationThe SPL Programming Language Reference Manual
The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming
More informationDecaf Language Reference Manual
Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a
More informationQuiz Start Time: 09:34 PM Time Left 82 sec(s)
Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability
More informationIndex. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107
A abbreviations 17 abstract class 105 abstract data types 105 abstract method 105 abstract types 105 abstraction 92, 105 access level 37 package 114 private 115 protected 115 public 115 accessors 24, 105
More informationOBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe
OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++
More informationCS201 Latest Solved MCQs
Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability
More informationChapter 3 Syntax, Errors, and Debugging. Fundamentals of Java
Chapter 3 Syntax, Errors, and Debugging Objectives Construct and use numeric and string literals. Name and use variables and constants. Create arithmetic expressions. Understand the precedence of different
More informationCourse Outline. Introduction to java
Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.
More informationDefinition of DJ (Diminished Java)
Definition of DJ (Diminished Java) version 0.5 Jay Ligatti 1 Introduction DJ is a small programming language similar to Java. DJ has been designed to try to satisfy two opposing goals: 1. DJ is a complete
More informationExpanded Guidelines on Programming Style and Documentation
Page 1 of 5 Expanded Guidelines on Programming Style and Documentation Introduction Introduction to Java Programming, 5E Y. Daniel Liang liang@armstrong.edu Programming style deals with the appearance
More information3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.
3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.
More informationBasics of Java Programming
Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement
More informationLecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value
Lecture Notes 1. Comments a. /* */ b. // 2. Program Structures a. public class ComputeArea { public static void main(string[ ] args) { // input radius // compute area algorithm // output area Actions to
More information20 Most Important Java Programming Interview Questions. Powered by
20 Most Important Java Programming Interview Questions Powered by 1. What's the difference between an interface and an abstract class? An abstract class is a class that is only partially implemented by
More information1/16/2013. Program Structure. Language Basics. Selection/Iteration Statements. Useful Java Classes. Text/File Input and Output.
Program Structure Language Basics Selection/Iteration Statements Useful Java Classes Text/File Input and Output Java Exceptions Program Structure 1 Packages Provide a mechanism for grouping related classes
More informationComputer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary
GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis
More informationF1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept
F1 A Java program Ch 1 in PPIJ Introduction to the course The computer and its workings The algorithm concept The structure of a Java program Classes and methods Variables Program statements Comments Naming
More informationThe Java Programming Language
The Java Programming Language Slide by John Mitchell (http://www.stanford.edu/class/cs242/slides/) Outline Language Overview History and design goals Classes and Inheritance Object features Encapsulation
More informationData Structure. Recitation IV
Data Structure Recitation IV Topic Java Generics Java error handling Stack Lab 2 Java Generics The following code snippet without generics requires casting: List list = new ArrayList(); list.add("hello");
More informationModule 10 Inheritance, Virtual Functions, and Polymorphism
Module 10 Inheritance, Virtual Functions, and Polymorphism Table of Contents CRITICAL SKILL 10.1: Inheritance Fundamentals... 2 CRITICAL SKILL 10.2: Base Class Access Control... 7 CRITICAL SKILL 10.3:
More informationBrief Summary of Java
Brief Summary of Java Java programs are compiled into an intermediate format, known as bytecode, and then run through an interpreter that executes in a Java Virtual Machine (JVM). The basic syntax of Java
More informationLecture 10 Declarations and Scope
Lecture 10 Declarations and Scope Declarations and Scope We have seen numerous qualifiers when defining methods and variables public private static final (we'll talk about protected when formally addressing
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationCpt S 122 Data Structures. Introduction to C++ Part II
Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function
More informationProgram Fundamentals
Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java
More informationCS 251 Intermediate Programming Methods and Classes
CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationCS 251 Intermediate Programming Methods and More
CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More information11 Coding Standards CERTIFICATION OBJECTIVES. Use Sun Java Coding Standards
11 Coding Standards CERTIFICATION OBJECTIVES Use Sun Java Coding Standards 2 Chapter 11: Coding Standards CERTIFICATION OBJECTIVE Use Sun Java Coding Standards Spacing Standards The Developer exam is challenging.
More information1 Shyam sir JAVA Notes
1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write
More informationChapter 2 Basic Elements of C++
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion
More informationCS11 Java. Fall Lecture 1
CS11 Java Fall 2006-2007 Lecture 1 Welcome! 8 Lectures Slides posted on CS11 website http://www.cs.caltech.edu/courses/cs11 7-8 Lab Assignments Made available on Mondays Due one week later Monday, 12 noon
More informationReview sheet for Final Exam (List of objectives for this course)
Review sheet for Final Exam (List of objectives for this course) Please be sure to see other review sheets for this semester Please be sure to review tests from this semester Week 1 Introduction Chapter
More informationCSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018
CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values
More informationLab # 2. For today s lab:
1 ITI 1120 Lab # 2 Contributors: G. Arbez, M. Eid, D. Inkpen, A. Williams, D. Amyot 1 For today s lab: Go the course webpage Follow the links to the lab notes for Lab 2. Save all the java programs you
More informationcorgi Language Reference Manual COMS W4115
corgi Language Reference Manual COMS W4115 Philippe Guillaume Losembe (pvl2109) Alisha Sindhwani (as4312) Melissa O Sullivan (mko2110) Justin Zhao (jxz2101) October 27, 2014 Chapter 1: Introduction corgi
More informationDefining Classes and Methods
Defining Classes and Methods Chapter 5 Modified by James O Reilly Class and Method Definitions OOP- Object Oriented Programming Big Ideas: Group data and related functions (methods) into Objects (Encapsulation)
More informationChapter 4 Java Language Fundamentals
Chapter 4 Java Language Fundamentals Develop code that declares classes, interfaces, and enums, and includes the appropriate use of package and import statements Explain the effect of modifiers Given an
More informationChapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More information