DATA STRUCTURES AND JAVA CLASS LIBRARY
PERSONAL NOTES ( S2M1 )
UNIT 1 - PROGRAMMING STYLE
Why comment and document the code ?
1. Readability - Easier to read
2. Comprehensibility - Can be understood by others
3. Collaboration - Can facilitate fruitful collaboration
4. Reusability - Can be effectively used by others
How to comment and document code
1. Write documentation in comments
2. Use Javadoc
3. Provide code annotations
4. Use code conventions effectively
Comments are used to describe and document source code
- Special characters inform compiler that following words shouldn’t be interpreted as code
- Single-line comments ( “//” )
- Multi-line comments ( "/* */”)
Javadoc allows to automatically generate documentation from code that is commented following
some standard notation
- These comments must be introduced using (“/**”)
- Uses (“@”) to generate HTML documentation pages
- @author denotes the author of the file
- @param describes a method’s parameter
- @returns describes what the method returns
- @throws lists possible error sources and thrown exceptions
, Code Annotations add metadata to source code
- Annotations start with (“@”)
- Used to annotate classes, methods and attributes
- Helps developers recognize errors more quickly
- @Override marks methods that override the methods of a superclass
- @Deprecated marks classes, methods and attributes that shouldn’t be used in new code
Code Conventions is a standardized way of structuring and formatting code improving readability
- Package names in lowercase
- Name classes and interfaces as nouns starting with capital letter
- Camel case when name consists of multiple words
- Name methods as verbs
- Fully capitalize constants
- Order related items together
- Declare variables at beginning of code block
- Write each declaration on separate line
- Group sections using blank lines
- Indent code properly using (“{}”)
UNIT 2 - WORKING WITH OBJECTS
How to work effectively with objects
String representation
- Method toString() outputs any object content to the console as a string
- It reduces programming effort and unnecessary concatenations of strings
Equality operator (“==”) compares the identity of objects, not content
- Compares whether two data types refer to the same object
- Primitive data types are easily compared
- Complex data types, doesn’t compare content of objects
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through EFT, credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying this summary from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller DylanHattingh. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy this summary for R200,00. You're not tied to anything after your purchase.