SlideShare a Scribd company logo
2016 Winter
LAB #3
Prepared by: Berk Soysal
2016 Winter
• The operator ”==” is used to compare two objects
regarding their references.
• This means, the operator checks whether
or not these two objects refer to the same place in
memory.
• For example;
String s1 = new String("xyz");
String s2 = new String("xyz");
if(s1 == s2)
System.out.println(“s1==s2 is TRUE");
else
System.out.println(“s1==s2 is FALSE");
Folder Lab3 Lab3 Examples Equality.java
• Note 1: Every time we create a new object, the
object gets its own unique address in the memory.
• Note 2: This type of comparison is called reference
comparison.
2016 Winter
• The intent of the equals method is to compare whether two
objects are semantically the same, if they have the same
content.
• For classes from the Java library (Wrappers, Strings etc.), this
is indeed what will happen.
• For your own class however, you have to provide your own
implementation of equals.
For example;
String s1 = new String("xyz");
String s2 = new String("xyz");
if(s1.equals(s2))
System.out.println(“s1 equals s2 is TRUE");
else
System.out.println(“s1 equals s2 is FALSE");
2016 Winter Folder Lab3 Lab3 Examples Equality.java
• Another important aspect of software development
is the documentation.
• JavaDoc is a format for your Java comments, and a
set of tools for producing Web pages automatically.
• In this lab, we are asking you to document your
code (variables, methods, etc.) using JavaDoc.
2016 Winter
2016 Winter
• Let’s complete the implementation of the (static)
class method String[] findAndReplace(String[] in,
String[] what, String[] with) of the class Utils.
• The method returns a copy of the array in where
each word occurring in the array what has been
replaced by the word occurring at the
corresponding position in the array with.
• The array designated by in must remain
unchanged.
2016 Winter
• JUnit is a simple framework to write repeatable tests. It is an
instance of the xUnit architecture for unit testing
frameworks.
• A set of test cases is written
to test a method’s operation.
• We use various methods of the
Assert Class to test our
findAndReplace() method.
• Only the failed assertions are recorded.
2016 Winter
• Let us implement a class to represent rational
numbers..
• Each rational number consists of a numerator
and a denominator, both of type int. Since each
rational number has its own numerator and
denominator, these must be instance variables.
Solutions-> Rational and TestRational
2016 Winter
• The public setXYZ () and getXYZ() methods are the
access points of the instance variables of a class.
• Normally, these methods are referred as getters
and setters.
• Therefore any class that wants to access the
variables should access them through these getters
and setters.
• An object that has no setter methods, and no other
methods for transforming the state of the object, is
said to be immutable.
2016 Winter
• An object is considered immutable if its state
cannot change after it is constructed. Maximum
reliance on immutable objects is widely accepted as
a sound strategy for creating simple, reliable code.
• Since they cannot change state, they cannot be
corrupted by thread interference or observed in an
inconsistent state.
2016 Winter
• Sometimes, you want to have variables that are
common to all objects. This is accomplished with
the static modifier. Fields that have the static
modifier in their declaration are called class
methods.
• When a number of objects are created from the
same class blueprint, they each have their own
distinct copies of instance methods.
2016 Winter
You can do this to execute a static method:
MyClass.staticMethod();
//Simply refers to the class's static code
But to execute a non-static method, you must do this:
//Create an instance
MyClass obj = new MyClass();
//Refer to the instance's class's code
obj.nonstaticMethod();
2016 Winter
Documentation Exercise !
Add JavaDoc comments for the class Rational.
1. Add JavaDoc comments for all the methods. Each
comment should include a brief description of what the
method does and descriptions of the parameters and the
return value using JavaDoc format.
2. Add a brief description of the class Rational, using the
JavaDoc syntax, make sure to include
the name of the author of the class (you).
2016 Winter
Java Tutorial Lab 3

More Related Content

What's hot

Knolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in ScalaKnolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in ScalaAyush Mishra
 
Simplicitly
SimplicitlySimplicitly
Simplicitly
Martin Odersky
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
agorolabs
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding
Michael Heron
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
Martin Odersky
 
Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
baabtra.com - No. 1 supplier of quality freshers
 
Adobe Flash Actionscript language basics chapter-2
Adobe Flash Actionscript language basics chapter-2Adobe Flash Actionscript language basics chapter-2
Adobe Flash Actionscript language basics chapter-2
Nafis Ahmed
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
Martin Odersky
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
Martin Odersky
 
Net framework
Net frameworkNet framework
Net framework
Abhishek Mukherjee
 
Python programming
Python programmingPython programming
Python programming
sirikeshava
 
2CPP13 - Operator Overloading
2CPP13 - Operator Overloading2CPP13 - Operator Overloading
2CPP13 - Operator Overloading
Michael Heron
 
Differences between method overloading and method overriding
Differences between method overloading and method overridingDifferences between method overloading and method overriding
Differences between method overloading and method overriding
Pinky Anaya
 
Java Programming
Java ProgrammingJava Programming
Java Programming
Nanthini Kempaiyan
 
Method overloading
Method overloadingMethod overloading
Method overloading
Lovely Professional University
 
Introduction java programming
Introduction java programmingIntroduction java programming
Introduction java programming
Nanthini Kempaiyan
 
Introduction on Data Structures
Introduction on Data StructuresIntroduction on Data Structures
Introduction on Data Structures
Nanthini Kempaiyan
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method Overloading
Michael Heron
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Rahul Jain
 
30csharp
30csharp30csharp
30csharp
Sireesh K
 

What's hot (20)

Knolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in ScalaKnolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in Scala
 
Simplicitly
SimplicitlySimplicitly
Simplicitly
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
 
Adobe Flash Actionscript language basics chapter-2
Adobe Flash Actionscript language basics chapter-2Adobe Flash Actionscript language basics chapter-2
Adobe Flash Actionscript language basics chapter-2
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
Net framework
Net frameworkNet framework
Net framework
 
Python programming
Python programmingPython programming
Python programming
 
2CPP13 - Operator Overloading
2CPP13 - Operator Overloading2CPP13 - Operator Overloading
2CPP13 - Operator Overloading
 
Differences between method overloading and method overriding
Differences between method overloading and method overridingDifferences between method overloading and method overriding
Differences between method overloading and method overriding
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Introduction java programming
Introduction java programmingIntroduction java programming
Introduction java programming
 
Introduction on Data Structures
Introduction on Data StructuresIntroduction on Data Structures
Introduction on Data Structures
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method Overloading
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
30csharp
30csharp30csharp
30csharp
 

Similar to Java Tutorial Lab 3

‫Object Oriented Programming_Lecture 3
‫Object Oriented Programming_Lecture 3‫Object Oriented Programming_Lecture 3
‫Object Oriented Programming_Lecture 3
Mahmoud Alfarra
 
Java
JavaJava
Pattern Matching - at a glance
Pattern Matching - at a glancePattern Matching - at a glance
Pattern Matching - at a glance
Knoldus Inc.
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
Epsiba1
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Concepts
mdfkhan625
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Viyaan Jhiingade
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java conceptsChikugehlot
 
Intro to Scala
 Intro to Scala Intro to Scala
Intro to Scala
manaswinimysore
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
ssuser8347a1
 
Java for newcomers
Java for newcomersJava for newcomers
Java for newcomers
Amith jayasekara
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Sagar Verma
 
Java basics
Java basicsJava basics
Java basics
Shivanshu Purwar
 
Lesson3
Lesson3Lesson3
Lesson3
Arpan91
 
CHAPTER 3 part2.pdf
CHAPTER 3 part2.pdfCHAPTER 3 part2.pdf
CHAPTER 3 part2.pdf
FacultyAnupamaAlagan
 
Java As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & AppletsJava As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & Applets
Helen SagayaRaj
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
Elizabeth alexander
 

Similar to Java Tutorial Lab 3 (20)

Java
JavaJava
Java
 
‫Object Oriented Programming_Lecture 3
‫Object Oriented Programming_Lecture 3‫Object Oriented Programming_Lecture 3
‫Object Oriented Programming_Lecture 3
 
Java
JavaJava
Java
 
Pattern Matching - at a glance
Pattern Matching - at a glancePattern Matching - at a glance
Pattern Matching - at a glance
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Concepts
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java concepts
 
Intro to Scala
 Intro to Scala Intro to Scala
Intro to Scala
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Java for newcomers
Java for newcomersJava for newcomers
Java for newcomers
 
Java Day-4
Java Day-4Java Day-4
Java Day-4
 
Day 2
Day 2Day 2
Day 2
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3
 
Java basics
Java basicsJava basics
Java basics
 
Lesson3
Lesson3Lesson3
Lesson3
 
Lesson3
Lesson3Lesson3
Lesson3
 
CHAPTER 3 part2.pdf
CHAPTER 3 part2.pdfCHAPTER 3 part2.pdf
CHAPTER 3 part2.pdf
 
Java As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & AppletsJava As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & Applets
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
 

More from Berk Soysal

Guest author manual
Guest author manualGuest author manual
Guest author manual
Berk Soysal
 
Comparison of BER performances of 64-PSK and 64-QAM in AWGN channels
Comparison of BER performances of  64-PSK and 64-QAM in  AWGN channelsComparison of BER performances of  64-PSK and 64-QAM in  AWGN channels
Comparison of BER performances of 64-PSK and 64-QAM in AWGN channels
Berk Soysal
 
Biomedical project report detecting emg noise
Biomedical project report detecting emg noiseBiomedical project report detecting emg noise
Biomedical project report detecting emg noise
Berk Soysal
 
Self Evaluation Test
Self Evaluation Test Self Evaluation Test
Self Evaluation Test
Berk Soysal
 
Java Tutorial Lab 9
Java Tutorial Lab 9Java Tutorial Lab 9
Java Tutorial Lab 9
Berk Soysal
 
Java Tutorial Lab 8
Java Tutorial Lab 8Java Tutorial Lab 8
Java Tutorial Lab 8
Berk Soysal
 

More from Berk Soysal (6)

Guest author manual
Guest author manualGuest author manual
Guest author manual
 
Comparison of BER performances of 64-PSK and 64-QAM in AWGN channels
Comparison of BER performances of  64-PSK and 64-QAM in  AWGN channelsComparison of BER performances of  64-PSK and 64-QAM in  AWGN channels
Comparison of BER performances of 64-PSK and 64-QAM in AWGN channels
 
Biomedical project report detecting emg noise
Biomedical project report detecting emg noiseBiomedical project report detecting emg noise
Biomedical project report detecting emg noise
 
Self Evaluation Test
Self Evaluation Test Self Evaluation Test
Self Evaluation Test
 
Java Tutorial Lab 9
Java Tutorial Lab 9Java Tutorial Lab 9
Java Tutorial Lab 9
 
Java Tutorial Lab 8
Java Tutorial Lab 8Java Tutorial Lab 8
Java Tutorial Lab 8
 

Recently uploaded

Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
Peter Caitens
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 

Recently uploaded (20)

Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 

Java Tutorial Lab 3

  • 1. 2016 Winter LAB #3 Prepared by: Berk Soysal
  • 2. 2016 Winter • The operator ”==” is used to compare two objects regarding their references. • This means, the operator checks whether or not these two objects refer to the same place in memory. • For example; String s1 = new String("xyz"); String s2 = new String("xyz"); if(s1 == s2) System.out.println(“s1==s2 is TRUE"); else System.out.println(“s1==s2 is FALSE"); Folder Lab3 Lab3 Examples Equality.java
  • 3. • Note 1: Every time we create a new object, the object gets its own unique address in the memory. • Note 2: This type of comparison is called reference comparison. 2016 Winter
  • 4. • The intent of the equals method is to compare whether two objects are semantically the same, if they have the same content. • For classes from the Java library (Wrappers, Strings etc.), this is indeed what will happen. • For your own class however, you have to provide your own implementation of equals. For example; String s1 = new String("xyz"); String s2 = new String("xyz"); if(s1.equals(s2)) System.out.println(“s1 equals s2 is TRUE"); else System.out.println(“s1 equals s2 is FALSE"); 2016 Winter Folder Lab3 Lab3 Examples Equality.java
  • 5. • Another important aspect of software development is the documentation. • JavaDoc is a format for your Java comments, and a set of tools for producing Web pages automatically. • In this lab, we are asking you to document your code (variables, methods, etc.) using JavaDoc. 2016 Winter
  • 7. • Let’s complete the implementation of the (static) class method String[] findAndReplace(String[] in, String[] what, String[] with) of the class Utils. • The method returns a copy of the array in where each word occurring in the array what has been replaced by the word occurring at the corresponding position in the array with. • The array designated by in must remain unchanged. 2016 Winter
  • 8. • JUnit is a simple framework to write repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks. • A set of test cases is written to test a method’s operation. • We use various methods of the Assert Class to test our findAndReplace() method. • Only the failed assertions are recorded. 2016 Winter
  • 9. • Let us implement a class to represent rational numbers.. • Each rational number consists of a numerator and a denominator, both of type int. Since each rational number has its own numerator and denominator, these must be instance variables. Solutions-> Rational and TestRational 2016 Winter
  • 10. • The public setXYZ () and getXYZ() methods are the access points of the instance variables of a class. • Normally, these methods are referred as getters and setters. • Therefore any class that wants to access the variables should access them through these getters and setters. • An object that has no setter methods, and no other methods for transforming the state of the object, is said to be immutable. 2016 Winter
  • 11. • An object is considered immutable if its state cannot change after it is constructed. Maximum reliance on immutable objects is widely accepted as a sound strategy for creating simple, reliable code. • Since they cannot change state, they cannot be corrupted by thread interference or observed in an inconsistent state. 2016 Winter
  • 12. • Sometimes, you want to have variables that are common to all objects. This is accomplished with the static modifier. Fields that have the static modifier in their declaration are called class methods. • When a number of objects are created from the same class blueprint, they each have their own distinct copies of instance methods. 2016 Winter
  • 13. You can do this to execute a static method: MyClass.staticMethod(); //Simply refers to the class's static code But to execute a non-static method, you must do this: //Create an instance MyClass obj = new MyClass(); //Refer to the instance's class's code obj.nonstaticMethod(); 2016 Winter
  • 14. Documentation Exercise ! Add JavaDoc comments for the class Rational. 1. Add JavaDoc comments for all the methods. Each comment should include a brief description of what the method does and descriptions of the parameters and the return value using JavaDoc format. 2. Add a brief description of the class Rational, using the JavaDoc syntax, make sure to include the name of the author of the class (you). 2016 Winter