STATIC VARIABLE/ METHODS, INHERITANCE, INTERFACE AND COMMAND LINE ARGUMENTS
|
|
- Jade Kennedy
- 7 years ago
- Views:
Transcription
1 STATIC VARIABLE/ METHODS, INHERITANCE, INTERFACE AND COMMAND LINE ARGUMENTS Example 1: Static Member Variable 1. /* 2. This Java Example shows how to declare and use static member variable inside a java class. 3. */ public class StaticMemberExample 6. { 7. public static void main(string[] args) 8. { 9. ObjectCounter object1 = new ObjectCounter(); 10. System.out.println(object1.getNumberOfObjects()); ObjectCounter object2 = new ObjectCounter(); 13. System.out.println(object2.getNumberOfObjects()); 14. } 15. } class ObjectCounter 18. { 19. /* 20. * Static members are class level variables and shared by all 21. * the objects of the class. 22. * To define static member, use static keyword 23. * e.g. static int i=0; 24. * 25. * Please note that static member variables can be accessed 26. * inside non static methods because they are class level 27. * variables. 28. */ static int counter=0; public ObjectCounter() 33. { /*increase the object counter. Since only one varible 36. *is shared between all objects of this class, it 37. *always return number of objects till now. 38. */ 39. counter++; 40. } //returns number of objects created till now 43. public int getnumberofobjects() 44. { 45. return counter; 46. } 47. } Page 1
2 Example 2: Static Method 1. /* 2. This Java Example shows how to declare and use static methods inside 3. a java class. 4. */ public class StaticMethodExample 7. { public static void main(string[] args) 10. { int result = MathUtility.add(1, 2); 13. System.out.println("(1+2) is : " + result); 14. } } class MathUtility 19. { /* 22. * To declare static method use static keyword. 23. * Static methods are class level methods and can not access 24. * any instance 25. * member directly. However, it can access member's of a 26. * particular object 27. * using its reference. 28. * 29. * Static methods are generally written as a utility method or 30. * it performs task for all objects of the class. 31. * 32. */ public static int add(int first, int second) 35. { 36. return first + second; 37. } 38. } Page 2
3 Example 3: Inheritance 1. //Inheritance, In Java You Can Only Inherit from One Class, 2. //Multiple Inheritance is not allowed class Parent 5. { 6. //data members 7. private int a; 8. public int b; 9. protected int c; //default constructor 12. public Parent() 13. { 14. a = b = c = 0; 15. System.out.println("I am class A's default constructor"); 16. } //parameterized constructor 19. public Parent(int a, int b, int c) 20. { 21. this.a = a; 22. this.b = b; 23. this.c = c; 24. } //get and set methods for a 27. public int geta() 28. { 29. return a; 30. } public void seta(int a) 33. { 34. this.a = a; 35. } //get and set methods for b 38. public int getb() 39. { 40. return b; 41. } public void setb(int b) 44. { 45. this.b = b; 46. } //get and set methods for c 49. public int getc() 50. { 51. return c; 52. } Page 3
4 53. public void setc(int c) 54. { 55. this.c = c; 56. } 57. } //child class inherit the properties of Parent 60. public class Child extends Parent 61. { 62. //default constructor 63. public Child() 64. { 65. System.out.println("I am class B's default constructor"); 66. } //parameterized constructor 69. public Child(int a, int b, int c) 70. { 71. //calling base class (A's) parameterized constructor 72. super(a,b,c); 73. } public static void main(string args[]) 76. { 77. Child obj1 = new Child(); 78. Child obj2 = new Child(1,2,3); //Assigning Child's Reference To Parent 81. Parent objp = new Child(); System.out.println("\nThe value of a can-not be accessed directly in child bcz its private in parent"); 84. System.out.println("\nThe value of b = " + obj2.b); 85. System.out.println("\nThe value of c = " + obj2.c); 86. } 87. } Page 4
5 Example 4: Constructor Call Sequence in Inheritance 1. //Constructor call sequence in inheritance class GrandFather 4. { 5. //Default Constructor 6. public GrandFather() 7. { 8. System.out.println("Grand Father's Constructor"); 9. } 10. } class Father extends GrandFather 13. { 14. //Default Constructor 15. public Father() 16. { 17. System.out.println("Father's Constructor"); 18. } 19. } class Child1 extends Father 22. { 23. //Default Constructor 24. public Child1() 25. { 26. System.out.println("Child1's Constructor"); 27. } 28. } class Child2 extends Father 31. { 32. //Default Constructor 33. public Child2() 34. { 35. System.out.println("Child2's Constructor"); 36. } 37. } class CallingCons 40. { 41. //Main function 42. public static void main(string []args) 43. { 44. Child1 objc1 = new Child1(); 45. System.out.println(); 46. Child2 objc2 = new Child2(); 47. } 48. } Page 5
6 Example 5: Usage of super 1. /*usage of super, method overriding and member overriding*/ class Parent 4. { 5. int num; //Function to tell about the class 8. void TellAbout() 9. { 10. System.out.println("Hello, I am Parent called by super"); 11. } 12. } class Child extends Parent 15. { 16. //hidding num1 of Parent 17. int num; //paremetrized constructor of child 20. public Child(int num1, int num2) 21. { 22. super.num = num1; 23. num = num2; 24. } //function to display the vlaues 27. void Display() 28. { 29. System.out.println("num in Parent Class = " + super.num); 30. System.out.println("num in Child Class = " + num); 31. } //function to tell about the class, (overridden method) 34. void TellAbout() 35. { 36. super.tellabout(); 37. System.out.println("Hello, I am child"); 38. } 39. } class UsingSuper 42. { 43. public static void main(string []args) 44. { 45. Child obj = new Child(2,3); 46. obj.tellabout(); 47. obj.display(); 48. } 49. } Page 6
7 Example 6: Abstract Class 1. /*abstract classes and abstract method. 2. *You cant intansiate the object of abstract class. 3. *To access the functionality of the abstract class 4. *you have to inherit it into sub-class 5. *you can provide only declaration of methods with abstract key-word 6. *you can provide implementation of methods in it 7. *you have to provide the defination of abstract methods in sub-class 8. *otherwise the sub-class becomes abstract as well*/ 9. abstract class DrawingShapes 10. { 11. //data member 12. String ShapeType; 13. //abstract mehtod whose implementation required in sub-class 14. abstract void draw(); 15. //con-crete methods are still allowed in abstract class 16. void BackGroundColor(String color) 17. { 18. System.out.println(ShapeType + " Drawn With Back-Ground-Color " + color); 19. } 20. } 21. //Circle class, extending the DrawingShapes 22. class Circle extends DrawingShapes 23. { 24. //implementation of abstract method 25. void draw() 26. { 27. ShapeType = "Circle"; 28. } 29. } 30. //Rectangle class, extending the Drawing Shpaes 31. class Rectangle extends DrawingShapes 32. { 33. //implementation of abstract method 34. void draw() 35. { 36. ShapeType = "Rectangle"; 37. } 38. } Page 7
8 39. class UsingAbstract 40. { 41. public static void main(string []args) 42. { 43. //object of type Circle 44. Circle c = new Circle(); //object of type Rectangle 47. Rectangle r = new Rectangle(); //obtain a reference of type DrawingShapes (abstract class) 50. DrawingShapes ds; //calling draw method of Circle class 53. c.draw(); //calling BackGroundColor method of Circle class 56. c.backgroundcolor("yellow"); //ds of abstract class, refers to Rectangle class's object 59. ds = r; //calling draw mehtod of Rectangle class 62. ds.draw(); //calling BackGroundColor method of Rectangle class 65. ds.backgroundcolor("blue"); 66. } 67. } Page 8
9 Example 7: Creating and Using Interface 1. //declaring a simple interface that contains five abstract mehtods 2. interface ISimpleMath 3. { 4. float Add(float num1, float num2); 5. float Sub(float num1, float num2); 6. float Mul(float num1, float num2); 7. float Div(float num1, float num2); 8. float Rem(float num1, float num2); 9. } //implementing the ISimpleMath interface (declared above) in //Calculator class 12. class Calculator implements ISimpleMath 13. { 14. //implementation of the interface methods 15. //implementing Add(Addition) function 16. public float Add(float num1, float num2) 17. { 18. return num1 + num2; 19. } //implementing Sub(Subtraction) function 22. public float Sub(float num1, float num2) 23. { 24. return num1 - num2; 25. } //implementing Mul(multiply) function 28. public float Mul(float num1, float num2) 29. { 30. return num1 * num2; 31. } //implementing Div(Division) function 34. public float Div(float num1, float num2) 35. { 36. return num1 / num2; 37. } //implementing Rem(Remainder) function 40. public float Rem(float num1, float num2) 41. { 42. return num1 % num2; 43. } //get and set property methods for num1 46. public float GetNum1() 47. { 48. return num1; 49. } Page 9
10 54. public void SetNum1(float num1) 55. { 56. this.num1 = num1; 57. } //get and set property methods for num2 60. public float GetNum2() 61. { 62. return num2; 63. } public void SetNum2(float num2) 66. { 67. this.num2 = num2; 68. } //class function to take input, by using Keyboard class 71. void TakeInput() 72. { 73. System.out.print(" Enter First Number = "); 74. num1 = Keyboard.readFloat(); System.out.print(" Enter Second Number = "); 77. num2 = Keyboard.readFloat(); 78. } //class function to display results 81. void Display(float a, float s, float m, float d, float r) 82. { 83. System.out.println(" Sum = " + a); 84. System.out.println(" Sub = " + s); 85. System.out.println(" Mul = " + m); 86. System.out.println(" Div = " + d); 87. System.out.println(" Rem = " + r); 88. } //Main Function 91. public static void main(string args[]) 92. { 93. //Creating an object of Calculator class 94. Calculator objc = new Calculator(); //Calling input function of Calculator class 97. objc.takeinput(); //calling calculation methods of Calculator class 100. float a = objc.add(objc.getnum1(), objc.getnum2()); 101. float s = objc.sub(objc.getnum1(), objc.getnum2()); 102. float m = objc.mul(objc.getnum1(), objc.getnum2()); 103. float d = objc.div(objc.getnum1(), objc.getnum2()); 104. float r = objc.rem(objc.getnum1(), objc.getnum2()); //Displaying the result of calculation 107. objc.display(a, s, m, d, r); 108. } Page 10
11 109. //class data members 110. private float num1; 111. private float num2; 112. } Example 8: Displaying Command Line Arguments Passed to the Program 1. class CommandLineArgs 2. { 3. public static void main(string []args) 4. { 5. //getting the length of passed arguments 6. int len = args.length; 7. if(len==0) 8. { 9. System.out.println("No Argument(s) Have Been Passed"); 10. } 11. else 12. { 13. //displaying the passed arguments 14. for(int i=0; i<len; i++) 15. System.out.println("The Argument At Location args[ "+ i + " ] is " + args[i]); 16. } 17. } 18. } THE END Page 11
Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75
Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship
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 informationJAVA - METHODS. Method definition consists of a method header and a method body. The same is shown below:
http://www.tutorialspoint.com/java/java_methods.htm JAVA - METHODS Copyright tutorialspoint.com A Java method is a collection of statements that are grouped together to perform an operation. When you call
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 informationJAVA - INHERITANCE. extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword.
http://www.tutorialspoint.com/java/java_inheritance.htm JAVA - INHERITANCE Copyright tutorialspoint.com Inheritance can be defined as the process where one class acquires the properties methodsandfields
More informationAgenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism
Polymorphism 1 Agenda What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism 2 What is & Why Polymorphism? 3 What is Polymorphism? Generally, polymorphism refers
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 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 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 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 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 informationBuilding Java Programs
Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print
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 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 informationFirst Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
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 informationBuilding Java Programs
Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print
More informationConstruction of classes with classes
(November 13, 2014 Class hierarchies 1 ) Construction of classes with classes Classes can be built on existing classes through attributes of object types. Example: I A class PairOfDice can be constructed
More informationSystem.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :
Benjamin Michael Java Homework 3 10/31/2012 1) Sales.java Code // Sales.java // Program calculates sales, based on an input of product // number and quantity sold import java.util.scanner; public class
More informationCohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT
BSc (Hons) in Computer Applications, BSc (Hons) Computer Science with Network Security, BSc (Hons) Business Information Systems & BSc (Hons) Software Engineering Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT
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 informationJ a v a Quiz (Unit 3, Test 0 Practice)
Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points
More informationJAVA ARRAY EXAMPLE PDF
JAVA ARRAY EXAMPLE PDF Created By: Umar Farooque Khan 1 Java array example for interview pdf Program No: 01 Print Java Array Example using for loop package ptutorial; public class PrintArray { public static
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 informationPart I. Multiple Choice Questions (2 points each):
Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******
More informationInheritance, overloading and overriding
Inheritance, overloading and overriding Recall with inheritance the behavior and data associated with the child classes are always an extension of the behavior and data associated with the parent class
More informationCSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]
More informationINTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction
INTRODUCTION TO COMPUTER PROGRAMMING Richard Pierse Class 7: Object-Oriented Programming Introduction One of the key issues in programming is the reusability of code. Suppose that you have written a program
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 informationpublic static void main(string[] args) { System.out.println("hello, world"); } }
Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static
More informationThis explanations are for absolute beginners. Skilled programmers should (and probably will) use more effective approach.
JAVA EXAMPLES REMARK It turned out that all Workstation in the classroom are NOT set equally. This is why I wil demonstrate all examples using an on-line web tool http://www.browxy.com and/or http://www.compileonline.com.
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 informationChapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output
Chapter 2 Console Input and Output System.out.println for console output System.out is an object that is part of the Java language println is a method invoked dby the System.out object that can be used
More informationTutorial on Writing Modular Programs in Scala
Tutorial on Writing Modular Programs in Scala Martin Odersky and Gilles Dubochet 13 September 2006 Tutorial on Writing Modular Programs in Scala Martin Odersky and Gilles Dubochet 1 of 45 Welcome to the
More informationDebugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go
Debugging ESE112 Java Programming: API, Psuedo-Code, Scope It is highly unlikely that you will write code that will work on the first go Bugs or errors Syntax Fixable if you learn to read compiler error
More informationShort Introduction to the Concepts of Programming in Java Overview over the most important constructs
Introduction to Java Short Introduction to the Concepts of Programming in Java Overview over the most important constructs OOIS 1998/99 Ulrike Steffens Software Systems Institute ul.steffens@tu- harburg.de
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 informationChapter 2 Introduction to Java programming
Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break
More informationHandout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.
Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java
More informationqwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui
More information1 Hour, Closed Notes, Browser open to Java API docs is OK
CSCI 143 Exam 2 Name 1 Hour, Closed Notes, Browser open to Java API docs is OK A. Short Answer For questions 1 5 credit will only be given for a correct answer. Put each answer on the appropriate line.
More informationIn this Chapter you ll learn:
Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then stop. Lewis
More information1. Use the class definition above to circle and identify the parts of code from the list given in parts a j.
public class Foo { private Bar _bar; public Foo() { _bar = new Bar(); public void foobar() { _bar.moveforward(25); 1. Use the class definition above to circle and identify the parts of code from the list
More informationChapter 13 - Inheritance
Goals Chapter 13 - Inheritance To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package
More informationDescription of Class Mutation Mutation Operators for Java
Description of Class Mutation Mutation Operators for Java Yu-Seung Ma Electronics and Telecommunications Research Institute, Korea ysma@etri.re.kr Jeff Offutt Software Engineering George Mason University
More informationVB.NET - CLASSES & OBJECTS
VB.NET - CLASSES & OBJECTS http://www.tutorialspoint.com/vb.net/vb.net_classes_objects.htm Copyright tutorialspoint.com When you define a class, you define a blueprint for a data type. This doesn't actually
More informationWA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.
WA2099 Introduction to Java using RAD 8.0 Student Labs Web Age Solutions Inc. 1 Table of Contents Lab 1 - The HelloWorld Class...3 Lab 2 - Refining The HelloWorld Class...20 Lab 3 - The Arithmetic Class...25
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 informationJAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.
http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral
More information3 Pillars of Object-oriented Programming. Industrial Programming Systems Programming & Scripting. Extending the Example.
Industrial Programming Systems Programming & Scripting Lecture 12: C# Revision 3 Pillars of Object-oriented Programming Encapsulation: each class should be selfcontained to localise changes. Realised through
More informationProgrammierpraktikum
Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 21 10/16/2012 09:29 AM Java - A First Glance 2 of 21 10/16/2012 09:29 AM programming languages
More informationComp 248 Introduction to Programming
Comp 248 Introduction to Programming Chapter 2 - Console Input & Output Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada These slides has been
More informationJava Program Coding Standards 4002-217-9 Programming for Information Technology
Java Program Coding Standards 4002-217-9 Programming for Information Technology Coding Standards: You are expected to follow the standards listed in this document when producing code for this class. Whether
More informationSample CSE8A midterm Multiple Choice (circle one)
Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names
More informationCS170 Lab 11 Abstract Data Types & Objects
CS170 Lab 11 Abstract Data Types & Objects Introduction: Abstract Data Type (ADT) An abstract data type is commonly known as a class of objects An abstract data type in a program is used to represent (the
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 informationChulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.
Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command
More informationSE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin
SE 360 Advances in Software Development Object Oriented Development in Java Polymorphism Dr. Senem Kumova Metin Modified lecture notes of Dr. Hüseyin Akcan Inheritance Object oriented programming languages
More informationB.Sc (Honours) - Software Development
Galway-Mayo Institute of Technology B.Sc (Honours) - Software Development E-Commerce Development Technologies II Lab Session Using the Java URLConnection Class The purpose of this lab session is to: (i)
More informationWeb Development and Core Java Lab Manual V th Semester
Web Development and Core Java Lab Manual V th Semester DEPT. OF COMPUTER SCIENCE AND ENGINEERING Prepared By: Kuldeep Yadav Assistant Professor, Department of Computer Science and Engineering, RPS College
More informationIntroducing Variance into the Java Programming Language DRAFT
Introducing Variance into the Java Programming Language A Quick Tutorial DRAFT Christian Plesner Hansen Peter von der Ahé Erik Ernst Mads Torgersen Gilad Bracha June 3, 2003 1 Introduction Notice: This
More informationMany applications consist of one or more classes, each containing one or more methods. If you become part of a development team in industry, you may
Chapter 1 Many applications consist of one or more classes, each containing one or more methods. If you become part of a development team in industry, you may work on applications that contain hundreds,
More informationPolymorphism. Why use polymorphism Upcast revisited (and downcast) Static and dynamic type Dynamic binding. Polymorphism.
Why use polymorphism Upcast revisited (and downcast) Static and dynamic type Dynamic binding Polymorphism Polymorphism A polymorphic field (the state design pattern) Abstract classes The composite design
More informationCS193j, Stanford Handout #10 OOP 3
CS193j, Stanford Handout #10 Summer, 2003 Manu Kumar OOP 3 Abstract Superclass Factor Common Code Up Several related classes with overlapping code Factor common code up into a common superclass Examples
More informationYosemite National Park, California. CSE 114 Computer Science I Inheritance
Yosemite National Park, California CSE 114 Computer Science I Inheritance Containment A class contains another class if it instantiates an object of that class HAS-A also called aggregation PairOfDice
More information106 #3 EXAMPLE FOR SCOPE REGIONS void A() { int B; void E() { int C; { int D; #4 LARGE EXAMPLE FOR HAND SIMULATION class HS { int g1 = 100; int g2 = 2
105 SOURCE CODE EXAMPLES: JAVA This appendix contains the code examples referred to in the main text. There is a version of the appendix for each language. This is the Java version. #1 EXAMPLE FOR THE
More informationScanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard
INPUT & OUTPUT I/O Example Using keyboard input for characters import java.util.scanner; class Echo{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); // scanner for the keyboard
More information1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius
Programming Concepts Practice Test 1 1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius 2) Consider the following statement: System.out.println("1
More informationJava Programming Language
Lecture 1 Part II Java Programming Language Additional Features and Constructs Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Subclasses and
More informationJava Cheatsheet. http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix
Java Cheatsheet http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix Hello World bestand genaamd HelloWorld.java naam klasse main methode public class HelloWorld
More informationJava: overview by example
Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: overview by example Bank Account A Bank Account maintain a balance (in CHF) of the total amount of money balance can go
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 informationAP Computer Science Static Methods, Strings, User Input
AP Computer Science Static Methods, Strings, User Input Static Methods The Math class contains a special type of methods, called static methods. A static method DOES NOT operate on an object. This is because
More informationCollections.sort(population); // Método de ordenamiento
import java.util.collections; import java.util.linkedlist; import java.util.random; public class GeneticAlgorithms static long BEGIN; static final boolean _DEBUG = true; LinkedList population
More informationLaboratory Assignments of OBJECT ORIENTED METHODOLOGY & PROGRAMMING (USING C++) [IT 553]
Laboratory Assignments of OBJECT ORIENTED METHODOLOGY & PROGRAMMING (USING C++) [IT 553] Books: Text Book: 1. Bjarne Stroustrup, The C++ Programming Language, Addison Wesley 2. Robert Lafore, Object-Oriented
More informationObject-Oriented Programming: Polymorphism
1 10 Object-Oriented Programming: Polymorphism 10.3 Demonstrating Polymorphic Behavior 10.4 Abstract Classes and Methods 10.5 Case Study: Payroll System Using Polymorphism 10.6 final Methods and Classes
More informationSmallest Java Package? Java.applet.* having 1 class and 3 interfaces. Applet Class and AppletContext, AppletStub, Audioclip interfaces.
OBJECTIVES OF JAVA Objects in java cannot contain other objects; they can only have references to other objects. Deletion of objects will be managed by Run time system. An Object can pass a message to
More informationMultichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is
Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations
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 informationContents. 9-1 Copyright (c) 1999-2004 N. Afshartous
Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to
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 informationObject Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
More informationINPUT AND OUTPUT STREAMS
INPUT AND OUTPUT The Java Platform supports different kinds of information sources and information sinks. A program may get data from an information source which may be a file on disk, a network connection,
More informationIntroduction to programming
Unit 1 Introduction to programming Summary Architecture of a computer Programming languages Program = objects + operations First Java program Writing, compiling, and executing a program Program errors
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 informationHomework/Program #5 Solutions
Homework/Program #5 Solutions Problem #1 (20 points) Using the standard Java Scanner class. Look at http://natch3z.blogspot.com/2008/11/read-text-file-using-javautilscanner.html as an exampleof using the
More informationGetting Started with the Internet Communications Engine
Getting Started with the Internet Communications Engine David Vriezen April 7, 2014 Contents 1 Introduction 2 2 About Ice 2 2.1 Proxies................................. 2 3 Setting Up ICE 2 4 Slices 2
More informationLecture J - Exceptions
Lecture J - Exceptions Slide 1 of 107. Exceptions in Java Java uses the notion of exception for 3 related (but different) purposes: Errors: an internal Java implementation error was discovered E.g: out
More informationBuilding Java Programs
Building Java Programs Chapter 9 Lecture 9-1: Inheritance reading: 9.1 The software crisis software engineering: The practice of developing, designing, documenting, testing large computer programs. Large-scale
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 informationAP Computer Science A 2010 Scoring Guidelines
AP Computer Science A 2010 Scoring Guidelines The College Board The College Board is a not-for-profit membership association whose mission is to connect students to college success and opportunity. Founded
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 informationAssignment No.3. /*-- Program for addition of two numbers using C++ --*/
Assignment No.3 /*-- Program for addition of two numbers using C++ --*/ #include class add private: int a,b,c; public: void getdata() couta; cout
More informationIntroduction to Java Applets (Deitel chapter 3)
Introduction to Java Applets (Deitel chapter 3) 1 2 Plan Introduction Sample Applets from the Java 2 Software Development Kit Simple Java Applet: Drawing a String Drawing Strings and Lines Adding Floating-Point
More information15-214: Principles of Software Construction 8 th March 2012
15-214 Midterm Exam Andrew ID: SOLUTIONS 1 / 13 15-214: Principles of Software Construction 8 th March 2012 Name: SOLUTIONS Recitation Section (or Time): Instructions: Make sure that your exam is not missing
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 informationCOMPUTER SCIENCE. Paper 1 (THEORY)
COMPUTER SCIENCE Paper 1 (THEORY) (Three hours) Maximum Marks: 70 (Candidates are allowed additional 15 minutes for only reading the paper. They must NOT start writing during this time) -----------------------------------------------------------------------------------------------------------------------
More informationProgramming Languages Featherweight Java David Walker
Programming Languages Featherweight Java David Walker Overview Featherweight Java (FJ), a minimal Javalike language. Models inheritance and subtyping. Immutable objects: no mutation of fields. Trivialized
More information