Mapa mental
Core Concepts

Mind map: Core concepts of Java programming
Conteúdo do mapa
Core Concepts
Code Styles
- General Principles
- Document any deviations
- Adhere Principle of Least Astonishment
- adhere to the style of the original
- Least astonishment
- Simplicity
- Build simple classes and simple methods.
- Clarity
- Ensure each class, interface, method, variable, and object has a clear purpose.
- Completeness
- Provide the minimum functionality that any reasonable user would expect to find and use. Create complete documentation
- Consistency
- Similar entities look,behave the same; dissimilar entities look,behave differently. Create and apply standards
- Robustness
- Provide predictable documented behavior in response to errors and exceptions. Do not hide errors and do not force clients to detect errors.
- Simplicity
- Formatting Conventions
- Indent nested code
- Specify the amount of space and use of tabs
- Break up long lines
- Split long expressions
- Include white space not just between lines
- Indent nested code
- Naming conventions
- Use meaningful names (Including constants instead of literals)
- Question excessively long names
- Join the vowel generation (don't shorten by taking vowels out)
- Use familiar names (for the target domain)
- Do not use names that differ only in case
- Capitalize only the first letter in acronyms
- package Names
- Use the reversed, lowercase form of your organization's Internet domain name as the root qualifier for your package names
- Use the same name for a new version of a package, but only if that new version is still binary compatible with the previous version, otherwise, use a new name
- Use a single, lowercase word as the root name of each package
- method Names
- Use lowercase for the first word and capitalize only the first letter of each subsequent word that appears in a method name
- Use verbs when naming methods
- Follow the JavaBeans™ conventions for naming property accessor methods
- type Names
- Same name for a new version of a package, but only if that new version is still binary compatible with the previous version, otherwise, use a new name
- Use nouns when naming classes
- Use nouns or adjectives when naming interfaces
- Pluralize the names of classes that group related attributes, static services, or constants
- field Names
- Use uppercase letters for each word and separate each pair of words with an underscore when naming constants
- When a constructor or "set" method assigns a parameter to afield, give that parameter the same name as the field
- variable Names
- Use nouns to name variables
- Pluralize the names of collection references
- Use lowercase for the first word and capitalize only the first letter of each word in variable name
- Establish and use a set of standard names for trivial "throwaway" variables
- Other conventions
- Documentation conventions
- Programming conventions Do not repeat statements or expressions, replace with methods
- Packaging conventions
- General Principles
Basic Tools
- Integrated Development Environment
- System that combines an editor with language specific support tools, including a debugger
- Standard basic features are:
- Debugger
- Code Completion
- Automatic Indentation
- Syntax highlighting
- Complication error highlighting
- Automate common tasks
- The master should always work:
- Updates to working copies
- Changes quickly updated to repository
- Commit triggers build and test
- System largely automated
- Build results often promiently communicated to developers
- Revision Control
- Manga sharing of code between team etc.
- Integration in IDE allows to see changes made even in the editor
- Going back and forth between revisions
- Build systems
- Generally powerful scripting environments, that do other stuff to.
- Automate various tasks related to building software
- "Target"s allow a user to specify what needs to be done
- Standard systems:
- Ant - java
- Maven - java project management
- Make - For C/C++ (unix)
- Static analyzers
- Compilers are designed to translate software into executable code
- Most languages don't enforce conventions neither do compilers.
- Conventions can promote correctness
- Complex analysis can find bugs in "valid" code
- May score code on "correctness" dimensions
- Can check for certain broken patterns
- Code Formatters
- Code readability helps understanding,correctness, maintenance
- Formatters automatically format code
- Help with conformance to code style + consistency
- Refactoring
- When code changes, the design may change along
- Changing the organisation of code or design of the system is called refactoring
- Refactoring involves aspects such as:
- Renaming "things"
- Reordering parameters
- Introducing Classes or interfaces
- Moving Methods
- Debugging
- Step over - go to next line
- Step into - go into the function on this line
- Step out - go to calling function
- Breakpoint - stop execution here, on exception or value change
- Watch - Expressions you want evaluated
- Local variables - visible in program + value
- Integrated Development Environment
Collections
- What is a collection
- Object that groups together various objects
- used to hold similar data items - cards, msg in chatbox
- Arrays are a sort of collections
- What is Java Collections Framework
- group of interfaces and classes for dealing with differing types of collections
- Interfaces – abstract data types
- Implementations – ready made classes
- Methods – static methods that work on collections
- encourages code reuse
- facilitates interoperability
- abstracts complex data structures between easy to understand (common) interfaces
- group of interfaces and classes for dealing with differing types of collections
- Arrays
- Size is fixed when the array is constructed
- You must be able to predict array size
- Items have a fixed index position
- ArrayListS
- Stores stuff in an array (and moves it to a new array if capacity is insufficient)
- Maintains entry order
- Changing a location is cheap [ O(1) ]
- Finding an item is expensive [ O(n) ]
- Getting an item at a specified random location is cheap [ O(1) ]
- Adding stuff at the end is cheap (in most cases, except when copying is needed) [ O(1) ]
- Putting things in the middle or removing things from the middle is expensive [ O(n) ]
- HashMap (hashing)
- Stores key -> value pairs
- Key is hashed
- Hash is used as index into an array, where the value is stored (often in a linked list)
- Finding elements is cheap [ O(1) ]
- Removing of elements is cheap [ O(1) ]
- Memory need is bigger
- Hash key calculation can be expensive
- Collection does not maintain order
- No random access
- Iterating a bit more expensive than arraylists
- HashSet
- same as HashMap only value is stored in key as well
- enforces uniqueness
- TreeMap/Set
- Stores in a tree
- Maintains items in key order
- Adding, removing and finding items has moderate complexity [ O(log n) ]
- Reasonable memory usage
- No random indexed access
- Iterating a bit more expensive than arraylists
- Linked List
- Every element has a link to the next + or prev ele
- Adding an element is cheap [ O(1) ]
- Finding an element is expensive [ O(n) ] needs to look from beginning (on average 1/2 n steps)
- Removing an element anywhere is cheap [ O(2) ]
- Maintains entry order
- LinkedHashMap/Set
- Combine hashmap/set with linked lists
- maintain entry order of adding items to from list
- Computational properties of HashMaps
- Deque - Double ended queue
- New in jdk 1.6 / Java 6
- Like array list, but instead of a window starting at index 0 of the array, maintains a sliding window over the array.
- Cheap adding/removing entries at beginning of list
- A little more expensive because of the index
- In general a very efficient data type
- What is a collection
Object Orientation
- References and pointers
- pointer is a data type that contains the address of some data in memory
- To use the pointed to values, the language must provide indirection operators
- A pointer must point to a valid location. Either allocated (new) or pre-existing
- A reference is a language feature that makes abstracts pointer indirection and hides the pointer
- In Java all Objects are used through references. Pointers are not available
- What is OO?
- A programming paradigm (approach to...)
- combination of a number of programming concepts into 1
- solution particularly well suited to certain problems
- Not a silver bullet / panacea
- What makes up OO?
- Data structure
- Create a new kind of "data" that is built out of constituent components
- Members can be contained, or be references to structures
- Membership can logically be
- Containment - indistinguishable part, same lifetime
- Ownership - the outer object is responsible for the lifetime of the object, and handling access to it
- Reference - the outer object keeps a link to the object but has no responsibility in its lifetime
- Modularisation
- Code visibility
- Code reuse
- Abstraction (Abstract datatypes)
- Data structure
- What is a Struct
- Defines a "sequential" layout of values
- Allows treating as parts
- Element name is offset into memory
- Data / machine oriented
- Members are contained in the "in-memory" layout of the type
- Containment implies ownership
- By default members are public
- Structs vs Classes
- Java Objects are always used by reference (no containment).
- Use of other objects can have the intent of reference, ownership or containment
- Modularisation
- Modularisation is breaking up code into parts
- Plain use of methods/functions is not modularisation
- module should have some sort of coherency
- Makes it easier to find and edit parts of the system.
- Code Reuse
- Good prog reuses code
- less code = less complex
- reuse = code faster
- reuse = effort into better code
- reuse = changes in 1 place
- Ways
- Inheritance - allows a class to use the implementation in it's ancestor.
- Generics, allow limited variation on type constraints only (mainly help correctness)
- Temp, allow variations preventing copy,paste
- ctrl c,v,+ edit = same (bad)
- Function implementing an algorithm (Collections.sort)
- Abstract Data Types
- Abstract - "theoretical rather than physical or concrete"
- in prog - the what from the how
- Comp Science concept
- Specifying a data (and its corresponding functions) type purely by its external properties
- Allows to reason about something that holds (is true) for all possible implementations
- Use in implementation ensures implementation independence
- Uses
- If your algorithm works on an ADT it works on all types implementing it (code reuse)
- Allows for multiple implementations with different strengths (change has local impact on code)
- Allow context-dependent use of specific implementation (don't return an empty ArrayList, but Collections.emptyList)
- Separate function from implementation
- Interface
- Users should always read documentation for the "hidden" contract
- Only specifies an abstract data type
- Specifies a particular contract that classes can implement, and users can expect.
- Non-visible parts should be documented
- Parts of the contract are not visible in code
- Inheritance
- Java = public relationship
- class = interface
- In memory, an instance is like a structure where the first member is a contained, anonymous version of the parent
- Private members allow hiding implementation from children.
- Protected allows access by children, but not by users.
- Final protects agains inheritance. Final classes can't be inherited. Final members can't be overridden
- Abstract classes (and methods)
- Fully abstract class is an interface (e.g. C++ has no interface concept)
- Some implementations are provided either for convenience, or to enforce behaviour.
- Abstract methods provide a contract, but no implementation
- Abstract classes miss implementation for some methods, and are thus designed for extension
- Polymorphism
- Technique to run different code based on type of an object at run time
- Each object maintains a reference to it's actual type (set at creation time).
- When calling a method, instead of going to the address of that method, look the method address up in the class (in C++ vtable).
- Different classes can point to different implementations for the same method name
- Depends on exact method signature match.
- Depends on exact method signature match.
- @Override annotation conveys intention to compiler that verifies the intention
- References and pointers
Informações
- Descrição
- Mapa Mental sobre Core Concepts, criado por Bhavit Chhatralia em 22-05-2014.
- Criado por
- Bhavit Chhatralia
- Visualizações
- 64
- Avaliação