Basic Object-Oriented Programming in Java
|
|
- Christopher Hodge
- 7 years ago
- Views:
Transcription
1 coreservlets.com custom onsite training Basic Object-Oriented Programming in Java Originals of slides and source code for examples: Also see Java 8 tutorial: and many other Java EE tutorials: Customized Java training courses (onsite or at public venues): Slides 2016 Marty Hall, hall@coreservlets.com For additional materials, please see The Java tutorial section contains complete source code for all examples in this tutorial series, plus exercises and exercise solutions for each topic. coreservlets.com custom onsite training For customized training related to Java or JavaScript, please hall@coreservlets.com Marty is also available for consulting and development support Taught by lead author of Core Servlets & JSP, co-author of Core JSF (4 th Ed), and this tutorial. Available at public venues, or custom versions can be held on-site at your organization. Courses developed and taught by Marty Hall JSF 2.3, PrimeFaces, Java programming (using Java 8, for those new to Java), Java 8 (for Java 7 programmers), JavaScript, jquery, Ext JS, Spring Framework, Spring MVC, Java EE 8 MVC, Android, GWT, custom mix of topics Courses available in any state or country. Maryland/DC companies can also choose afternoon/evening courses. Courses Slides developed 2016 Marty and Hall, taught hall@coreservlets.com by coreservlets.com experts (edited by Marty) Hadoop, Hibernate/JPA, HTML5, RESTful Web Services For additional materials, please see Contact hall@coreservlets.com The Java tutorial section for details contains complete source code for all examples in this tutorial series, plus exercises and exercise solutions for each topic.
2 Topics in This Section Similarities and differences between Java and C++ Object-oriented nomenclature and conventions Instance variables (data members, fields) Methods (member functions) Constructors Person class with four variations 4 Object-oriented programming is an exceptionally bad idea which could only have originated in California. -- Edsger Dijkstra, 1972 Turing Award winner. Idea Tutorial Progression I progressively add features, rather than throwing many new ideas in all at once However, this means that the examples in this lecture are not satisfactory for reallife code In particular, until we introduce private instance variables, treat these examples only as means to introduce new topics, not representative real-world code 5
3 Tutorial Progression Progression of topics This lecture Instance variables Methods Constructors Next lecture Overloading Private instance variables and accessor methods From this point onward, examples are consistent with real-world style guidelines JavaDoc documentation Inheritance 6 coreservlets.com custom onsite training Basics Slides 2016 Marty Hall, hall@coreservlets.com For additional materials, please see The Java tutorial section contains complete source code for all examples in this tutorial series, plus exercises and exercise solutions for each topic.
4 Object-Oriented Nomenclature Class means a category of things A class name can be used in Java as the type of a field or local variable or as the return type of a function (method) There are also fancy uses with generic types such as List<String>. This is covered later. Object means a particular item that belongs to a class Also called an instance Example String s1 = "Hello"; Here, String is the class, and the variable s1 and the value "Hello" are objects (or instances of the String class ) 8 Comparisons to Similar Languages C++ Similar on the surface User-defined classes can be used like built-in types. Basic syntax Very different under the hood See next slide C# Very similar throughout. Different libraries, but core languages are very close Details: 9
5 Comparisons to Similar Languages Differences from C++ Methods (member functions) are the only function type Object is the topmost ancestor for all classes All methods use the run-time, not compile-time, types (i.e. all Java methods are like C++ virtual functions) The types of all objects are known at run-time All objects are allocated on the heap (so, always safe to return objects from methods). No difference between s is a String and s is pointer to String Single inheritance only Java 8 has multiple inheritance (as we will see), but via interfaces instead of by normal classes, so is a bit of a nonstandard variation of multiple inheritance 10 coreservlets.com custom onsite training Instance Variables Slides 2016 Marty Hall, hall@coreservlets.com For additional materials, please see The Java tutorial section contains complete source code for all examples in this tutorial series, plus exercises and exercise solutions for each topic.
6 Overview Definition Data that is stored inside an object. Instance variables can also be called data members or fields. Syntax public class MyClass { public SomeType field1, field2; Note In any class that also has methods, it is almost always better to declare instance variables private instead of public. But, we need more tools before we can do this. We will show how and why in the next tutorial section. 12 Persistence Motivation Instance variables let an object have values that persist over time Person p = new Person(); p.firstname = "Jane"; dosomethingelse(); checkvalueof(p.firstname); // Still "Jane" Object-oriented programming features It is often said that in OOP, objects have three characteristics: State Behavior Identity The instance variables provide the state 13
7 package ship1; Ship Example 1: Instance Variables (ship1/ship.java) public class Ship { public double x, y, speed, direction; public String name; 14 package ship1; Ship Tester (ship1/shiptest.java) public class ShipTest { public static void main(string[] args) { Ship s1 = new Ship(); s1.x = 0.0; s1.y = 0.0; s1.speed = 1.0; s1.direction = 0.0; // East s1.name = "Ship1"; Ship s2 = new Ship(); s2.x = 0.0; s2.y = 0.0; s2.speed = 2.0; s2.direction = 135.0; // Northwest s2.name = "Ship2"; 15
8 Ship Tester (Continued)... s1.x = s1.x + s1.speed * Math.cos(s1.direction * Math.PI / 180.0); s1.y = s1.y + s1.speed * Math.sin(s1.direction * Math.PI / 180.0); s2.x = s2.x + s2.speed * Math.cos(s2.direction * Math.PI / 180.0); s2.y = s2.y + s2.speed * Math.sin(s2.direction * Math.PI / 180.0); System.out.println(s1.name + " is at (" + s1.x + "," + s1.y + ")."); System.out.println(s2.name + " is at (" + s2.x + "," + s2.y + ")."); Move the ships one step based on their direction and speed. The previous slide seemed good: grouping variables together. But the code on this slide violates the primary goal of OOP: to avoid repeating identical or nearly-identical code. So, although instance variables are good, they are not enough: we need methods also. 16 Instance Variables: Results Compiling and running in Eclipse (common) Save Ship.java and ShipTest.java R-click inside ShipTest.java, Run As Java Application Compiling and running manually (rare) > javac ship1\shiptest.java > java ship1.shiptest Output: Ship1 is at (1,0). Ship2 is at ( , ). 17
9 Example 1: Major Points Java naming conventions Format of class definitions Creating classes with new Accessing fields with variablename.fieldname 18 Java Naming Conventions Start classes with uppercase letters Constructors (discussed later in this section) must exactly match class name, so they also start with uppercase letters public class MyClass {... 19
10 Java Naming Conventions Start other things with lowercase letters Instance variables, local variables, methods, parameters to methods public class MyClass { public String firstname, lastname; public String fullname() { String name = firstname + " " + lastname; return(name); 20 Objects and References Once a class is defined, you can declare variables (object reference) of that type Ship s1, s2; Point start; Color blue; Object references are initially null The null value is a distinct type in Java and is not equal to zero A primitive data type (e.g., int) cannot be cast to an object (e.g., String), but there are some conversion wrappers The new operator is required to explicitly create the object that is referenced ClassName variablename = new ClassName(); 21
11 Accessing Instance Variables Use a dot between the variable name and the field variablename.fieldname Example For example, Java has a built-in class called Point that has x and y fields Point p = new Point(2, 3); // Build a Point object int xsquared = p.x * p.x; // xsquared is 4 int xplusy = p.x + p.y; // xplusy is 5 p.x = 7; xsquared = p.x * p.x; // Now xsquared is 49 Exceptions Can access fields of current object without varname See upcoming method examples It is conventional to make all instance variables private In which case outside code can t access them directly. We will show later how to hook them to outside with methods. 22 coreservlets.com custom onsite training Methods Slides 2016 Marty Hall, hall@coreservlets.com For additional materials, please see The Java tutorial section contains complete source code for all examples in this tutorial series, plus exercises and exercise solutions for each topic.
12 Definition 24 Overview Functions that are defined inside a class. Methods can also be called member functions. Syntax public class MyClass { Note public ReturnType mymethod(...) {... This example uses public methods because we have not yet explained about private. Once you learn about private, your strategy is this: If you want code that uses your class to access the method, make it public. If your method is called only by other methods in the same class, make it private. Make it private unless you have a specific reason to do otherwise. Motivation Behavior Methods let an object calculate values or do operations, usually based on its current state (instance variables). public class Person { public String firstname, lastname;... public String getfullname() { return(firstname + " " + lastname); Object-oriented programming features It is often said that objects have three characteristics: state, behavior, and identity The methods provide the behavior 25
13 package ship2; Ship Example 2: Methods (ship2/ship.java) public class Ship { public double x=0.0, y=0.0, speed=1.0, direction=0.0; public String name = "UnnamedShip"; private double degreestoradians(double degrees) { return(degrees * Math.PI / 180.0); public void move() { double angle = degreestoradians(direction); x = x + speed * Math.cos(angle); y = y + speed * Math.sin(angle); In next lecture, we will show that the instance variables (x, y, etc.) should be private. But we need to first explain how to hook them to the outside world if private. So, just keep in the back of your mind the fact that we are making the fields public for now, but would not do so in real life. 26 public void printlocation() { System.out.println(name + " is at (" + x + "," + y + ")."); package ship2; Ship Tester (ship2/shiptest.java) public class ShipTest { public static void main(string[] args) { Ship s1 = new Ship(); s1.name = "Ship1"; Ship s2 = new Ship(); s2.direction = 135.0; // Northwest s2.speed = 2.0; s2.name = "Ship2"; s1.move(); s2.move(); s1.printlocation(); s2.printlocation(); 27
14 Methods: Results Compiling and running in Eclipse (common) Save Ship.java and ShipTest.java R-click inside ShipTest.java, Run As Java Application Compiling and running manually (rare) > javac ship2\shiptest.java > java ship2.shiptest Output: Ship1 is at (1,0). Ship2 is at ( , ). 28 Example 2: Major Points Format of method definitions Methods that access local fields Calling methods Static methods Default values for fields public/private distinction 29
15 Defining Methods (Functions Inside Classes) Basic method declaration: public ReturnType methodname(type1 arg1, Type2 arg2,...) {... return(somethingofreturntype); Exception to this format: if you declare the return type as void This special syntax that means this method isn t going to return a value it is just going to do some side effect like printing on the screen In such a case you do not need (in fact, are not permitted), a return statement that includes a value to be returned 30 Examples of Defining Methods // Example function call: // int val = square(7); public int square(int x) { return(x*x); // Example function call: // Ship faster = fastership(someship, someothership); 31 public Ship fastership(ship ship1, Ship ship2) { if (ship1.speed > ship2.speed) { return(ship1); else { return(ship2);
16 Calling Methods Terminology Method means function associated with an object (I.e., member function ) Calling methods variablename.methodname(argumentstomethod); Example The touppercase method doesn t take any arguments, so you just put empty parentheses after the function (method) name. String s1 = "Hello"; String s2 = s1.touppercase(); // s2 is now "HELLO" Accessing External and Internal Methods Accessing methods in other classes Get an object that refers to instance of other class Ship s = new Ship(); Call method on that object s.move(); Accessing instance vars in same class Call method directly (no variable name and dot in front) move(); double d = degreestoradians(); For local methods, you can use a variable name if you want, and Java automatically defines one called this for that purpose. See constructors section. Accessing static methods Use ClassName.methodName(args) double d = Math.cos(Math.PI/2);
17 Calling Methods (Continued) Calling a method of the current class You don t need the variable name and the dot For example, a Ship class might define a method called degreeestoradians, then, within another function in the same class definition, do this: double angle = degreestoradians(direction); No variable name and dot is required in front of degreestoradians since it is defined in the same class as the method that is calling it Calling static methods Use ClassName.methodName(args) double randomnumber = Math.random(); 34 Method Visibility public/private distinction A declaration of private means that outside methods can t call it only methods within the same class can Thus, for example, the main method of the Test2 class could not have done double x = s1.degreestoradians(2.2); Attempting to do so would have resulted in an error at compile time Only say public for methods that you want to guarantee your class will make available to users You are free to change or eliminate private methods without telling users of your class private instance variables In next lecture, we will see that you always make instance vars private and use methods to access them 35
18 36 Static Methods Also called class methods (vs. instance methods ) Static functions do not access any non-static methods or fields within their class and are almost like global functions in other languages Call a static method through the class name ClassName.functionName(arguments); Example: Math.cos The Math class has a static method called cos that expects a double precision number as an argument. So, you can call Math.cos(3.5) without ever having any object (instance) of the Math class double cosine = Math.cos(someAngle); Note on the main method Since the system calls main without first creating an object, static methods are the only type of methods that main can call directly (i.e. without building an object and calling the method of that object) coreservlets.com custom onsite training Constructors Slides 2016 Marty Hall, hall@coreservlets.com For additional materials, please see The Java tutorial section contains complete source code for all examples in this tutorial series, plus exercises and exercise solutions for each topic.
19 Overview Definition Code that gets executed when new is called Syntax Method that exactly matches the class name and has no return type (not even void). public class MyClass { public MyClass(...) { Motivation Shorter code Lets you build an instance of the class, and assign values to instance variables, all in one line Vs. one line to build instance, then several additional lines to assign instance variables Consistency Lets you enforce that all instances have certain properties For example, a Ship might not be legal without a name, but with instance variables, there is no way to force the programmer to assign a name Side effects Constructors let you run extra code when class is instantiated. You can draw the Ship on the GUI, add the Ship to the fleet, keep a count of all Ships, etc. 39
20 40 Example: No User-Defined Constructor Person public class Person1 { public String firstname, lastname; PersonTest public class Person1Test { public static void main(string[] args) { Person1 p = new Person1(); p.firstname = "Larry"; p.lastname = "Ellison"; // dosomethingwith(p); It took three lines of code to make a properly constructed person. It would be possible for a programmer to build a person and forget to assign a first or last name. Example: User-Defined Constructor Person public class Person2 { public String firstname, lastname; 41 public Person2(String initialfirstname, String initiallastname) { firstname = initialfirstname; lastname = initiallastname; PersonTest public class Person2Test { public static void main(string[] args) { Person2 p = new Person2("Larry", "Page"); // dosomethingwith(p); Constructor. This one takes two strings as arguments. It took one line of code to make a properly constructed person. It would not be possible for a programmer to build a person and forget to assign a first or last name.
21 Ship Example 3: Constructors (ship3/ship.java) public class Ship { public double x, y, speed, direction; public String name; public Ship(double x, double y, double speed, double direction, String name) { this.x = x; // "this" differentiates instance this.y = y; // vars from local vars. this.speed = speed; this.direction = direction; this.name = name; // Same methods as last example package ship3; Ship Tester (ship3/shiptest.java) public class ShipTest { public static void main(string[] args) { Ship s1 = new Ship(0.0, 0.0, 1.0, 0.0, "Ship1"); Ship s2 = new Ship(0.0, 0.0, 2.0, 135.0, "Ship2"); s1.move(); s2.move(); s1.printlocation(); s2.printlocation(); 43
22 Constructors: Results Compiling and running in Eclipse (common) Save Ship.java and ShipTest.java R-click inside ShipTest.java, Run As Java Application Compiling and running manually (rare) > javac ship3\shiptest.java > java ship3.shiptest Output: Ship1 is at (1,0). Ship2 is at ( , ). 44 Example 3: Major Points Format of constructor definitions The this reference Destructors (not!) 45
23 Format of Constructors Syntax public class MyClass { public MyClass( ) { When used MyClass m = new MyClass(); 46 The this Variable The this variable The this object reference can be used inside any non-static method to refer to the current object The common uses of the this reference are: To pass pointer to the current object to another method somemethod(this); To resolve name conflicts public class Blah { private int x; public Blah(int x) { this.x = x; It is only necessary to say this.fieldname when you have a local variable and a field with the same name; otherwise just use fieldname with no this 47
24 Destructors This Page Intentionally Left Blank 48 coreservlets.com custom onsite training Example: Person Class Slides 2016 Marty Hall, For additional materials, please see The Java tutorial section contains complete source code for all examples in this tutorial series, plus exercises and exercise solutions for each topic.
25 Idea Goal Make a class to represent a person s first and last name Approach: 4 iterations Person with instance variables only And test case Add a getfullname method And test case Add a constructor And test case Change constructor to use this variable And test case Also have test case make a Person[] 50 Iteration 1: Instance Variables Person.java PersonTest.java public class Person { public String firstname, lastname; public class PersonTest { public static void main(string[] args) { Person p = new Person(); p.firstname = "Larry"; p.lastname = "Ellison"; System.out.println("Person's first name: " + p.firstname); System.out.println("Person's last name: " + p.lastname);
26 Iteration 2: Methods Person.java PersonTest.java public class Person { public String firstname, lastname; public String getfullname() { return(firstname + " " + lastname); public class PersonTest { public static void main(string[] args) { Person p = new Person(); p.firstname = "Bill"; p.lastname = "Gates"; System.out.println("Person's full name: " + p.getfullname()); Iteration 3: Constructors Person.java public class Person { public String firstname, lastname; public Person(String initialfirstname, String initiallastname) { firstname = initialfirstname; lastname = initiallastname; PersonTest.java public class PersonTest { public static void main(string[] args) { Person p = new Person("Larry", "Page"); System.out.println("Person's full name: " + p.getfullname()); public String getfullname() { return(firstname + " " + lastname);
27 Iteration 4: Constructors with the this Variable (and Arrays) Person.java public class Person { public String firstname, lastname; public Person(String firstname, String lastname) { this.firstname = firstname; this.lastname = lastname; public String getfullname() { return(firstname + " " + lastname); PersonTest.java public class PersonTest { public static void main(string[] args) { Person[] people = new Person[20]; for(int i=0; i<people.length; i++) { people[i] = new Person(NameUtils.randomFirstName(), NameUtils.randomLastName()); for(person person: people) { System.out.println("Person's full name: " + person.getfullname()); Helper Class for Iteration 4 public class NameUtils { public static String randomfirstname() { int num = (int)(math.random()*1000); return("john" + num); public static String randomlastname() { int num = (int)(math.random()*1000); return("smith" + num); 55
28 To Do: Later Iterations Use accessor methods Make instance variables private, then use getfirstname, setfirstname, getlastname, and setlastname Document code with JavaDoc Add JavaDoc-style comments so that the online API for Person class will be useful Use inheritance Make a class (Employee) based on the Person class. Don t repeat the code from the Person class. Next lecture Covers all of these ideas, then shows updated code 56 coreservlets.com custom onsite training Wrap-Up Slides 2016 Marty Hall, hall@coreservlets.com For additional materials, please see The Java tutorial section contains complete source code for all examples in this tutorial series, plus exercises and exercise solutions for each topic.
29 58 Summary Conventions Class names start with upper case. Names for methods, variables, and packages start with lower case Indent nested blocks consistently Example class public class Circle { public double radius; // We ll make this private next lecture public Circle(double radius) { this.radius = radius; public double getarea() { return(math.pi*radius*radius); Example usage Circle c1 = new Circle(10.0); double area = c1.getarea(); coreservlets.com custom onsite training Questions? More info: General Java programming tutorial Java 8 tutorial Customized Java training courses, at public venues or onsite at your organization JSF 2, PrimeFaces, Java 7 or 8, Ajax, jquery, Hadoop, RESTful Web Services, Android, HTML5, Spring, Hibernate, Servlets, JSP, GWT, and other Java EE training Many additional free tutorials at coreservlets.com (JSF, Android, Ajax, Hadoop, and lots more) Slides 2016 Marty Hall, hall@coreservlets.com For additional materials, please see The Java tutorial section contains complete source code for all examples in this tutorial series, plus exercises and exercise solutions for each topic.
Basic Object-Oriented Programming in Java
core programming Basic Object-Oriented Programming in Java 1 2001-2003 Marty Hall, Larry Brown http:// Agenda Similarities and differences between Java and C++ Object-oriented nomenclature and conventions
More informationObject-Oriented Programming in Java: More Capabilities
coreservlets.com custom onsite training Object-Oriented Programming in Java: More Capabilities Originals of slides and source code for examples: http://courses.coreservlets.com/course-materials/java.html
More informationOfficial Android Coding Style Conventions
2012 Marty Hall Official Android Coding Style Conventions Originals of Slides and Source Code for Examples: http://www.coreservlets.com/android-tutorial/ Customized Java EE Training: http://courses.coreservlets.com/
More informationJava with Eclipse: Setup & Getting Started
Java with Eclipse: Setup & Getting Started Originals of slides and source code for examples: http://courses.coreservlets.com/course-materials/java.html Also see Java 8 tutorial: http://www.coreservlets.com/java-8-tutorial/
More informationAdvanced Java Client API
2012 coreservlets.com and Dima May Advanced Java Client API Advanced Topics Originals of slides and source code for examples: http://www.coreservlets.com/hadoop-tutorial/ Also see the customized Hadoop
More informationFor live Java EE training, please see training courses
2012 Marty Hall Basic Java Syntax Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/java.htmlcoreservlets com/course-materials/java html 3 Customized Java
More informationHadoop Streaming. 2012 coreservlets.com and Dima May. 2012 coreservlets.com and Dima May
2012 coreservlets.com and Dima May Hadoop Streaming Originals of slides and source code for examples: http://www.coreservlets.com/hadoop-tutorial/ Also see the customized Hadoop training courses (onsite
More informationMap Reduce Workflows
2012 coreservlets.com and Dima May Map Reduce Workflows Originals of slides and source code for examples: http://www.coreservlets.com/hadoop-tutorial/ Also see the customized Hadoop training courses (onsite
More informationThe Google Web Toolkit (GWT): The Model-View-Presenter (MVP) Architecture Official MVP Framework
2013 Marty Hall & Yaakov Chaikin The Google Web Toolkit (GWT): The Model-View-Presenter (MVP) Architecture Official MVP Framework (GWT 2.5 Version) Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/gwt.html
More informationApache Pig Joining Data-Sets
2012 coreservlets.com and Dima May Apache Pig Joining Data-Sets Originals of slides and source code for examples: http://www.coreservlets.com/hadoop-tutorial/ Also see the customized Hadoop training courses
More informationThe Google Web Toolkit (GWT): Declarative Layout with UiBinder Basics
2013 Marty Hall & Yaakov Chaikin The Google Web Toolkit (GWT): Declarative Layout with UiBinder Basics (GWT 2.5 Version) Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/gwt.html
More informationAndroid Programming: Installation, Setup, and Getting Started
2012 Marty Hall Android Programming: Installation, Setup, and Getting Started Originals of Slides and Source Code for Examples: http://www.coreservlets.com/android-tutorial/ Customized Java EE Training:
More informationBasic Java Syntax. Slides 2016 Marty Hall, hall@coreservlets.com
coreservlets.com custom onsite training Basic Java Syntax Originals of slides and source code for examples: http://courses.coreservlets.com/course-materials/java.html Also see Java 8 tutorial: http://www.coreservlets.com/java-8-tutorial/
More informationHBase Key Design. 2012 coreservlets.com and Dima May. 2012 coreservlets.com and Dima May
2012 coreservlets.com and Dima May HBase Key Design Originals of slides and source code for examples: http://www.coreservlets.com/hadoop-tutorial/ Also see the customized Hadoop training courses (onsite
More informationVirtual Machine (VM) For Hadoop Training
2012 coreservlets.com and Dima May Virtual Machine (VM) For Hadoop Training Originals of slides and source code for examples: http://www.coreservlets.com/hadoop-tutorial/ Also see the customized Hadoop
More informationBuilding Web Services with Apache Axis2
2009 Marty Hall Building Web Services with Apache Axis2 Part I: Java-First (Bottom-Up) Services Customized Java EE Training: http://courses.coreservlets.com/ Servlets, JSP, Struts, JSF/MyFaces/Facelets,
More informationClasses and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:
In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our
More informationHBase Java Administrative API
2012 coreservlets.com and Dima May HBase Java Administrative API Originals of slides and source code for examples: http://www.coreservlets.com/hadoop-tutorial/ Also see the customized Hadoop training courses
More informationMoving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
More informationThe Google Web Toolkit (GWT): Overview & Getting Started
2013 Marty Hall & Yaakov Chaikin The Google Web Toolkit (GWT): Overview & Getting Started (GWT 2.5 Version) Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/gwt.html
More informationAndroid Programming: 2D Drawing Part 1: Using ondraw
2012 Marty Hall Android Programming: 2D Drawing Part 1: Using ondraw Originals of Slides and Source Code for Examples: http://www.coreservlets.com/android-tutorial/ Customized Java EE Training: http://courses.coreservlets.com/
More informationManaged Beans II Advanced Features
2014 Marty Hall Managed Beans II Advanced Features Originals of Slides and Source Code for Examples: http://www.coreservlets.com/jsf-tutorial/jsf2/ Customized Java EE Training: http://courses.coreservlets.com/
More informationHadoop Distributed File System (HDFS) Overview
2012 coreservlets.com and Dima May Hadoop Distributed File System (HDFS) Overview Originals of slides and source code for examples: http://www.coreservlets.com/hadoop-tutorial/ Also see the customized
More informationAndroid Programming Basics
2012 Marty Hall Android Programming Basics Originals of Slides and Source Code for Examples: http://www.coreservlets.com/android-tutorial/ Customized Java EE Training: http://courses.coreservlets.com/
More informationWeb Applications. Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/msajsp.html
2009 Marty Hall Using and Deploying Web Applications Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/msajsp.html Customized Java EE Training: http://courses.coreservlets.com/
More informationCMPT 183 Foundations of Computer Science I
Computer Science is no more about computers than astronomy is about telescopes. -Dijkstra CMPT 183 Foundations of Computer Science I Angel Gutierrez Fall 2013 A few questions Who has used a computer today?
More informationHDFS - Java API. 2012 coreservlets.com and Dima May. 2012 coreservlets.com and Dima May
2012 coreservlets.com and Dima May HDFS - Java API Originals of slides and source code for examples: http://www.coreservlets.com/hadoop-tutorial/ Also see the customized Hadoop training courses (onsite
More informationFree Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2015 The third
More informationFree Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman
More informationSpecialized Programme on Web Application Development using Open Source Tools
Specialized Programme on Web Application Development using Open Source Tools Objective: At the end of the course, Students will be able to: Understand various open source tools(programming tools and databases)
More informationObject-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007
Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,
More informationBasic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C
Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in
More informationCSE 308. Coding Conventions. Reference
CSE 308 Coding Conventions Reference Java Coding Conventions googlestyleguide.googlecode.com/svn/trunk/javaguide.html Java Naming Conventions www.ibm.com/developerworks/library/ws-tipnamingconv.html 2
More informationMapReduce on YARN Job Execution
2012 coreservlets.com and Dima May MapReduce on YARN Job Execution Originals of slides and source code for examples: http://www.coreservlets.com/hadoop-tutorial/ Also see the customized Hadoop training
More informationIntroduction to Object-Oriented Programming
Introduction to Object-Oriented Programming Programs and Methods Christopher Simpkins chris.simpkins@gatech.edu CS 1331 (Georgia Tech) Programs and Methods 1 / 8 The Anatomy of a Java Program It is customary
More informationInstall Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html
CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install
More informationFundamentals of Java Programming
Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors
More informationWeb Applications. For live Java training, please see training courses at
2009 Marty Hall Using and Deploying Web Applications Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/msajsp.html Customized Java EE Training: http://courses.coreservlets.com/
More informationJHU/EP Server Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/csajsp2.html
2010 Marty Hall Deploying Apps to the JHU/EP Server Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/csajsp2.html 2 Customized Java EE Training: http://courses.coreservlets.com/
More informationHow To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For
Projet Java Responsables: Ocan Sankur, Guillaume Scerri (LSV, ENS Cachan) Objectives - Apprendre à programmer en Java - Travailler à plusieurs sur un gros projet qui a plusieurs aspects: graphisme, interface
More informationC++ INTERVIEW QUESTIONS
C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get
More informationMore on Objects and Classes
Software and Programming I More on Objects and Classes Roman Kontchakov Birkbeck, University of London Outline Object References Class Variables and Methods Packages Testing a Class Discovering Classes
More informationLecture 5: Java Fundamentals III
Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd
More informationD06 PROGRAMMING with JAVA. Ch3 Implementing Classes
Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch3 Implementing Classes PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com,
More informationwww.sahajsolns.com Chapter 4 OOPS WITH C++ Sahaj Computer Solutions
Chapter 4 OOPS WITH C++ Sahaj Computer Solutions 1 Session Objectives Classes and Objects Class Declaration Class Members Data Constructors Destructors Member Functions Class Member Visibility Private,
More informationLAB4 Making Classes and Objects
LAB4 Making Classes and Objects Objective The main objective of this lab is class creation, how its constructer creation, object creation and instantiation of objects. We will use the definition pane to
More informationChapter 1 Java Program Design and Development
presentation slides for JAVA, JAVA, JAVA Object-Oriented Problem Solving Third Edition Ralph Morelli Ralph Walde Trinity College Hartford, CT published by Prentice Hall Java, Java, Java Object Oriented
More informationIntroduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.
1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays
More informationCS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5
This Week CS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5 School of Computer Science University of St Andrews Graham Kirby Alan Dearle More on Java classes Constructors Modifiers cdn.videogum.com/img/thumbnails/photos/commenter.jpg
More informationNo no-argument constructor. No default constructor found
Every software developer deals with bugs. The really tough bugs aren t detected by the compiler. Nasty bugs manifest themselves only when executed at runtime. Here is a list of the top ten difficult and
More informationJava Application Developer Certificate Program Competencies
Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle
More informationINTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011
INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011 1 Goals of the Lecture Present an introduction to Objective-C 2.0 Coverage of the language will be INCOMPLETE
More informationYou are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:
Lecture 7 Picking Balls From an Urn The problem: An urn has n (n = 10) balls numbered from 0 to 9 A ball is selected at random, its' is number noted, it is set aside, and another ball is selected from
More informationObject-Oriented Programming Lecture 2: Classes and Objects
Object-Oriented Programming Lecture 2: Classes and Objects Dr. Lê H!ng Ph"#ng -- Department of Mathematics, Mechanics and Informatics, VNUH July 2012 1 Content Class Object More on class Enum types Package
More informationHDFS Installation and Shell
2012 coreservlets.com and Dima May HDFS Installation and Shell Originals of slides and source code for examples: http://www.coreservlets.com/hadoop-tutorial/ Also see the customized Hadoop training courses
More informationJava Interview Questions and Answers
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 and compile the java
More information2011 Marty Hall An Overview of Servlet & JSP Technology Customized Java EE Training: http://courses.coreservlets.com/
2011 Marty Hall An Overview of Servlet & JSP Technology Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/csajsp2.html 3 Customized Java EE Training: http://courses.coreservlets.com/
More informationSpecialized Programme on Web Application Development using Open Source Tools
Specialized Programme on Web Application Development using Open Source Tools A. NAME OF INSTITUTE Centre For Development of Advanced Computing B. NAME/TITLE OF THE COURSE C. COURSE DATES WITH DURATION
More informationCrash Course in Java
Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is
More informationSession Tracking Customized Java EE Training: http://courses.coreservlets.com/
2012 Marty Hall Session Tracking Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/csajsp2.html 2 Customized Java EE Training: http://courses.coreservlets.com/
More informationSyllabus for CS 134 Java Programming
- Java Programming Syllabus Page 1 Syllabus for CS 134 Java Programming Computer Science Course Catalog 2000-2001: This course is an introduction to objectoriented programming using the Java language.
More informationHandling the Client Request: Form Data
2012 Marty Hall Handling the Client Request: Form Data Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/csajsp2.html 3 Customized Java EE Training: http://courses.coreservlets.com/
More informationJava Programming Fundamentals
Lecture 1 Part I Java Programming Fundamentals Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Introduction to Java We start by making a few
More informationJava Classes. GEEN163 Introduction to Computer Programming
Java Classes GEEN163 Introduction to Computer Programming Never interrupt someone doing what you said couldn't be done. Amelia Earhart Classes, Objects, & Methods Object-oriented programming uses classes,
More informationUnit Testing with JUnit: A Very Brief Introduction
coreservlets.com custom onsite training Unit Testing with JUnit: A Very Brief Introduction Originals of slides and source code for examples: http://courses.coreservlets.com/course-materials/java.html Also
More informationCMSC 202H. ArrayList, Multidimensional Arrays
CMSC 202H ArrayList, Multidimensional Arrays What s an Array List ArrayList is a class in the standard Java libraries that can hold any type of object an object that can grow and shrink while your program
More informationSome Scanner Class Methods
Keyboard Input Scanner, Documentation, Style Java 5.0 has reasonable facilities for handling keyboard input. These facilities are provided by the Scanner class in the java.util package. A package is a
More informationIntroduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
More informationAP Computer Science Java Subset
APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall
More informationHistory OOP languages Year Language 1967 Simula-67 1983 Smalltalk
History OOP languages Intro 1 Year Language reported dates vary for some languages... design Vs delievered 1957 Fortran High level programming language 1958 Lisp 1959 Cobol 1960 Algol Structured Programming
More informationWeb development... the server side (of the force)
Web development... the server side (of the force) Fabien POULARD Document under license Creative Commons Attribution Share Alike 2.5 http://www.creativecommons.org/learnmore Web development... the server
More informationObject-Oriented Programming in Java
CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio
More informationJavaScript: A Crash Course
2009 Marty Hall JavaScript: A Crash Course Part I: Core Language Syntax Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/ajax.html Customized Java EE Training:
More informationAn Overview of Java. overview-1
An Overview of Java overview-1 Contents What is Java Major Java features Java virtual machine Java programming language Java class libraries (API) GUI Support in Java Networking and Threads in Java overview-2
More informationJava CPD (I) Frans Coenen Department of Computer Science
Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials
More informationThe Interface Concept
Multiple inheritance Interfaces Four often used Java interfaces Iterator Cloneable Serializable Comparable The Interface Concept OOP: The Interface Concept 1 Multiple Inheritance, Example Person name()
More informationCSC 551: Web Programming. Fall 2001
CSC 551: Web Programming Fall 2001 Java Overview! Design goals & features "platform independence, portable, secure, simple, object-oriented,! Language overview " program structure, public vs. private "instance
More informationComputer Programming I
Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,
More informationMasters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013
Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper
More informationExample of a Java program
Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);
More informationThe Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1
The Java Series Java Essentials I What is Java? Basic Language Constructs Slide 1 What is Java? A general purpose Object Oriented programming language. Created by Sun Microsystems. It s a general purpose
More informationAdvanced OOP Concepts in Java
Advanced OOP Concepts in Java Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh spring@imap.pitt.edu http://www.sis.pitt.edu/~spring 09/28/2001 1 Overview
More informationIntroduction to Objective-C. Kevin Cathey
Introduction to Objective-C Kevin Cathey Introduction to Objective-C What are object-oriented systems? What is the Objective-C language? What are objects? How do you create classes in Objective-C? acm.uiuc.edu/macwarriors/devphone
More informationDebugging Ajax Pages: Firebug
2010 Marty Hall Ajax: Development and Debugging g Tools Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/ajax.html Customized Java EE Training: http://courses.coreservlets.com/
More informationHadoop Introduction. 2012 coreservlets.com and Dima May. 2012 coreservlets.com and Dima May
2012 coreservlets.com and Dima May Hadoop Introduction Originals of slides and source code for examples: http://www.coreservlets.com/hadoop-tutorial/ Also see the customized Hadoop training courses (onsite
More informationWhat servlets and JSP are all about
2012 Marty Hall An Overview of Servlet & JSP Technology Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/csajsp2.html 3 Customized Java EE Training: http://courses.coreservlets.com/
More information13 Classes & Objects with Constructors/Destructors
13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.
More informationWhat is Java? Applications and Applets: Result of Sun s efforts to remedy bad software engineering practices
What is Java? Result of Sun s efforts to remedy bad software engineering practices It is commonly thought of as a way to make Web pages cool. It has evolved into much more. It is fast becoming a computing
More informationCoding Standard for Java
Coding Standard for Java 1. Content 1. Content 1 2. Introduction 1 3. Naming convention for Files/Packages 1 4. Naming convention for Classes, Interfaces, Members and Variables 2 5. File Layout (.java)
More informationCSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.
CSCI 253 Object Oriented Design: Java Review OOP George Blankenship George Blankenship 1 Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation Abstract Data Type (ADT) Implementation
More informationCS-XXX: Graduate Programming Languages. Lecture 25 Multiple Inheritance and Interfaces. Dan Grossman 2012
CS-XXX: Graduate Programming Languages Lecture 25 Multiple Inheritance and Interfaces Dan Grossman 2012 Multiple Inheritance Why not allow class C extends C1,C2,...{...} (and C C1 and C C2)? What everyone
More information1/23/2012. Rich Internet Applications. The importance of JavaScript. Why learn JavaScript? Many choices open to the developer for server-side
The importance of JavaScript Many choices open to the developer for server-side Can choose server technology for development and deployment ASP.NET, PHP, Ruby on Rails, etc No choice for development of
More informationHigh-Level Language. Building a Modern Computer From First Principles. www.nand2tetris.org
High-Level Language Building a Modern Computer From First Principles www.nand2tetris.org Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org, Chapter 9: High-Level Language
More informationCurriculum Map. Discipline: Computer Science Course: C++
Curriculum Map Discipline: Computer Science Course: C++ August/September: How can computer programs make problem solving easier and more efficient? In what order does a computer execute the lines of code
More informationTopics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:
Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of
More informationStack Allocation. Run-Time Data Structures. Static Structures
Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,
More informationStorage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas
CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage
More informationApplication Security
2009 Marty Hall Declarative Web Application Security Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/msajsp.html Customized Java EE Training: http://courses.coreservlets.com/
More informationThe Google Web Toolkit (GWT): JavaScript Native Interface (JSNI)
2013 Marty Hall & Yaakov Chaikin The Google Web Toolkit (GWT): JavaScript Native Interface (JSNI) (GWT 2.5 Version) Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/gwt.html
More information