Category Archives: Programming Reference

Programming Nirvana (Journey From Novice to Expert)

  • Inspired by 5 stages of Dreyfus Model of Skill Acquisition.
  • Novices, Advanced Beginner, Competent, Proficient, Expert
  • Step 1 : Learning to write codes less than 10 lines, but inclusive good logic. Gave me a good practice to set my hands on Java without using Google or any IDE. Writing logic of a method without bothering about the execution of a fully functional program. Also Test cases teaches the faults in the logic. The site takes away the burden of setting/installing Java or any other IDE’s. In short :

It teaches Thinking in Java

Taking Baby Steps CodingBat.

  • Step 2 : Learning to write fully functional programs (with 3 to 4 classes), with object creation, keeping in mind when to use static etc. JAVA 101 type assignments, which gives a clue of how the language is used to solve problems. A brief overview on OOP.
    • Assignment 1 :(Based on) Class String, Keyboard input, Console output
    • Assignment 2 : Defining Classes and methods, Encapsulation, boolean if & switch
    • Assignment 3 : Loops and Math. Random(), Objects and References (equals, toString())
    • Assignment 4 : Constructors, Static variables & methods, Overloading
    • Assignment 5 : Aggregation, exceptions
    • Assignment 6 : File Handling and Arrays
  • Step 3 : Learning Object Oriented Concepts (Later)
  • Step 4: Practice of elementary concepts of Collections from BJP

Strings, Arrays uses for loop as cursor

Arralylist, LinkedList, Vector and Stack uses ListIterator (most powerful Cursor)

All Collections use Iterator as Cursor

 

D&C/Greedy/Dynamic

The Divide and Conquer Approach

  1. Divide the problem into Subproblems that are smaller instances of the same problem.
  2. Conquer the subproblem by solving them recursively. Use “base case” for the simplest subproblem. (Recursion is bottom up)
  3. Combine the solutions to the subproblems into the solution for the original problem.

Divide and Conquer usually generates brand-new problem at each step of recursion.

Elements of Dynamic Programming

For any optimization Problem, to be considered for the Dynamic Programming Problem, TWO key elements are needed.

  1. Optimal substructure : Problem exhibits optimal substructure, and optimal solution is built from optimal solutions to subproblem.
  2. Overlapping subproblems : space of subproblems must be small. The total number of distinct subproblems is polynomial in the input size.

Dynamic programming algorithm typically take advantage of overlapping subproblem by solving each subproblem once and then storing the solution in a table where it can be looked up when needed.

A bottom-up dynamic-programming algorithm usually outperforms the corresponding top-down memoized algorithm by a constant factor, because the bottom-up algorithm has no overhead for recursion and less overhead for maintaining the table.

Elements of Greedy Strategy

A greedy algorithm makes choice that seems best at the moment.

This heuristic strategy does not always produce an optimal solution but sometimes it does.

  1. Determine the optimal substructure of the problem.
  2. Develop a recursive solution.
  3. Show that if we make the greedy choice, then only one subproblem remains.
  4. Prove that it is always safe to make the greedy choice. (Steps 3 and 4 can occur in either order.)
  5. Develop a recursive algorithm that implements the greedy strategy.
  6. Convert the recursive algorithm to an iterative algorithm.

Git (for Projects)

Place .gitignore file in the project’s root directory. (It can be version-ed). The .git/info/exclude can be configured to ignore personal project settings. The .git folder carries settings adjusted for the local user.

git config credential.helper store
git push -u origin master
Username:
Password:

Git will then not ask for username and password again and again.

The GIT Primer

Pulling a fresh Project from a repository first time

git fetch (to sync the project between different machines)

 

Create a file -> Add the file to staging area by commit –> modify the file and  add the file to staging area commit and –> Push

git clone https://nitinc@bitbucket.org/nitinc/eclipseinitialtest.git (for HTTPS…easier and more intuitive!!)

git log (shows all committed logs…AFTER CLONING)
git branch (showed only master…not r2….SEE)

DO GLOBAL GIT SETTINGS (for commits to recognize you)
git config –global user.name “Nitin Chaurasia VM”
git config –global user.email nitinc@bgsu.edu
git config –global color.ui tru

Networking

  • Switch –> Firewall –> Router –> Modem ———->INTERNET!!
  • Switch has Wireless Access Points (WAP) to allow wireless devices to be connected to it, and various computers are connected physically through wires to the switch.
  • Physical v/s Logical connection -> within a switch we can have logical connection.
  • Speed –> 12Mbps = 1.5 MBps (vendors talk in terms of bits to make it look bigger, divide by 8 and check)

The Modem

converts the signals into

OO Concepts

Class : Abstract Definition of something that has (attributes and Actions – AA)

  • attributes (variables, properties or state)
  • actions (methods)

Object : A specific instance of a class.

4 Concepts

Encapsulation: is Hiding Data

  • by declaring the attributes (variables) private and
  • using accessors (getters) and mutators (setters) methods to access them.
  • both getters and setters are public.

Abstraction : 

 “An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of object and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer.” — G. Booch,

  • providing only essential information to the outside world and hiding their background details

Inheritance  : 

 

Polymorphism : 

Polymorphism means one name, many forms.  Polymorphism manifests itself by having multiple methods all with the same name, but slighty different functionality

Serialization

“serializable” means converting an instance of a class (an object) into a format where it can be written to disk, or transmitted over a network.

“Deserialization” is the opposite – reading data from the disk to create an object.

In Java it is an interface that if implemented in a class, means that it can automatically be serialized and deserialized by the different serializers.

.gitignore

# IntelliJ Ignore file

.idea/
*.iml
*.iws
out/
*.DS_Store
#The .gitignore for the Android Project developed on Eclipse

# Macintosh files
.DS_Store

# generated files (except .apk)
bin/
!bin/*.apk 
gen/
libs/

# Eclipse project files
.classpath
.settings
.project
project.properties

# built application files
!*.apk
# files for the dex VM
*.dex

# Java class files
*.class


# Proguard folder generated by Eclipse
proguard-project.txt
proguard/

lint.xml