Jim Lynch Codes
  • Blog
  • About Jim

Writings about one coder's stories & experiences.

Java Interview Tips

7/25/2016

0 Comments

 

Java complexities - The legendary Big O Cheatsheet

Here's a great explanation of the difference between space complexity and time cplexity:

What do you mean by space complexity?
Space complexity is a measure of the amount of working storage an algorithm needs. That means how much memory, in the worst case, is needed at any point in the algorithm. As with time complexity, we're mostly concerned with how the space needs grow, in big-Oh terms, as the size N of the input problem grows.

Time complexity i usually the thing we care about in computer science. 

Ask good questions; easy questions for the person in the interview to answer that show you are interested and curious about the job and the company:
- Array - has access time complexity O(1) 

http://theknowledge.me.uk/mywiki/concepts/Big%28O%29%20for%20Java%20Collections.html
  • ArrayList is fast at accessing elements and slow at adding and removing elements
  • LinkedList is slow at accessing elements and fast at adding and removing elements.
Merge Sort- "The divide and conquer algorithm". Watch gif on wikipedia:

In general use ArrayList over LinkedList because it's fast for accessing a random element. 

Sorting Algorithms

Quick Sort-
Merge Sort- 
​Heap Sort


Search Algorithms

Binary Search - Time complexity of log n to search.

Java Buzzwords

Here's a nice video explaining these concepts a little more: 
​https://www.youtube.com/watch?v=0xcgzUdTO5M


Coupling - measures how much you need to change other classes after changing one class (minimize coupling as much as possible) 
Cohesion - a measure of whether a class's responsibilities form a meaningful unit. Keep in mind the single responsibility rule.
Inner Classes - Useful if you want to restrict the scope of a class. In general, it's not good practice to use inner classes. 

Inner Classes - Constructor chaining - When a subclass constructor is run, it will automatically call "super();". You can explicitly set it and pass in parameters (useful when superclass constructor takes parameters).
Copy Constructor - a constructor of a class which accepts the same class as a parameter in its constructor.
Assert - let's you use unit testing code right in your application!
Reflection - Gives you details about particular implementation of a particular class, eg. how many methods or private, public, etc. Gives you details about the class interface. Use the ".class" property.
Collection - A base interface in collections framework. Gives you the ability to add a remove values to a group.
Set - an interface that is the same as Collection except that it must contain unique values
List - Also extends Collection, Position is important, an interface where everything is in order, allows duplicates.
Queue - Stores a list of values in a way that you can easily get the first and last values.
Map - Does NOT extend the collections interface. Uses key-value pairs.
HashSet -  neither ordered nor sorted, iterates in random order, uses "hashcode" 
LinkedHashSet - ordered, but unsorted, just stores things in the order of insertion.
TreeSet - Elements get saved in a SORTED order (not in order of insertion)
ArrayList - Implements random access, insertion and deletion are slower compared to linkedlist.
LinkedList - elements are "linked forward and backward" to each other. Ideal choice for stack or queue. Iteration is slower than ArrayList, but fast insertion / deletion


- objects are pass by reference, primitives svalue
- String is immutable
- StringBuffer is not immutable but is sychronized
- final: cannot change the value and cannot be overridden / extended
- Interfaces only contin the method signature, not the body of the function
- Abstract Classes are Nouns (AbstractClassExample) while interfaces are usually action words (runnable, flyable).

​- collections - has a lot of utility methods like sort, minimum, maximum
- binary search
- reverse
- shuffle - random order
- minimum, maximum
- replace
Collections Class has a lot of static methods for using on things that implement the collections interface. 
- 

0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    ​Author

    Picture
    The posts on this site are written and maintained by Jim Lynch. About Jim...
    Picture
    Follow @JimLynchCodes
    Follow @JimLynchCodes

    Categories

    All
    Actionscript 3
    Angular
    AngularJS
    Automated Testing
    AWS Lambda
    Behavior Driven Development
    Blockchain
    Blogging
    Business Building
    C#
    C / C++
    ClojureScript / Clojure
    Coding
    Community Service
    CS Philosophy
    Css / Scss
    Dev Ops
    Firebase
    Fitness
    Flash
    Front End
    Functional Programming
    Git
    Go Lang
    Haskell
    Illustrations
    Investing
    Java
    Javascript
    Lean
    Life
    Linux
    Logic Pro
    Music
    Node.js
    Planning
    Productivity
    Professionalism
    Python
    React
    Redux / Ngrx
    Refactoring
    Reusable Components
    Rust
    Security
    Serverless
    Shell Scripting
    Swift
    Test Driven Development
    Things
    TypeScript
    Useful Sites
    Useful Tools
    Video
    Website Development
    WebStorm
    Writing

    Archives

    March 2023
    August 2021
    February 2021
    January 2021
    October 2020
    September 2020
    May 2020
    April 2020
    February 2020
    January 2020
    December 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015

    RSS Feed

  • Blog
  • About Jim
JimLynchCodes © 2023