Tuesday, December 10, 2019

Getting Started with Go

Advantages of Go

1. Code runs fast.
2. Garbage Collection.
3. Simpler Objects.
4. Concurrency is efficient.

Software Translation
- Machine language:CPU instructions represented in binary
- Assembly language:CPU instructions with mnemonics
-> Easier to read
-> Equivalent to machine language.
- High-level language:Commonly used language(C,C++,Java,Python,Go,etc.)
-> Much easier to use.
All language must be translated into the machine language of processor.

Compiled Vs Interpreted

Compilation:
-translate instructioins once before running the code
-> C,C++,Java(partially)
-> Translation occurs every execution
-> Requires an interpreter
Efficiency vs Easy-of-use
-compiled code is fast
-Interpreters make coding easier
->Manage memory automatically
-> Infer variable types
-Go is a good compromise

Garbase Collection
- Automatic memory management
-> Where should memory be allocated?
-> when can memory be deallocated?

-Manual memory management is hard:
-> deallocate too early,false memory accesses.
-> deallocate too late, wasted memory.

-Go includes garbage collection
-> Typically only done by interpreters

OOP
-organize your code through encapsulation
-group together data and functions which are related
-user-defined type which is specific to an application

-Performance limits:
-Moore's law used to help performance.
-> Number of transistors doubles every 18 months.
-More transistors used to lead to higher clock frequencies
-Poer/temperature constraints limit clock frequencies now.

-Parallelism:
-Number of cores still increases over time.
-Multiple tasks may be performed at the same time on different cores.
-Difficulties with parallelism
-> When do tasks start/stop?
-> What if one task needs data from another task?
-> Do task conflict in memory?

-Concurrency is the management of multiple tasks at the same time.
-Key requirement for large systems
-Concurent programming enables parallelism
-> mangement of task execution
-> communication between tasks
-> syncronization between tasks

Concurency in Go
-Goroutines:->concurrent tasks
-Channels:->to communicate between tasks
-Select:-> to enable task synchronization

Directory hierarchy:
src->contain source code files
pkg->contains packages libraries
bin->contains executables

but not forced.

Go Tools
go build - compile the program
- create and executable
- .ext...et.
go doc - print documentation for package.
go fmt - formats source code files.
go get - download packages and install them
go run - compiles .go files and run the executable
go test - runs tests using files ending in _test.go

Friday, November 1, 2019

Pushing a new project directory to BitBucket Repository first time.

Pushing a new project in bitbucket first time:
Follow this : 
https://ommune.com/kb/pushing-a-new-project-directory-
to-bitbucket-repository/

OR :: 
Locally, change to the root directory of your existing source.

1. Initialize the directory under source control.

     git init

2. Add the existing files to the repository.

    git add .

3. Commit the files.

   git commit -m "message"

4. Log into Bitbucket.
5. Create a new repository.
6. Locate the Repository setup page.
7. Choose I have an existing project.
8. Follow the directions in the pane for your repository.

   cd /path/to/my/repo

   git remote add origin https://your-username@bitbucket.org/
       developers/repository-name.git

   git branch --set-upstream-to=origin/master
   git push -u origin --all 

Note::: If following problem arises.. 

if said refusing to merge unrelated-histories while doing pull

then 

git pull origin branchname --allow-unrelated-histories
git pull --allow-unrelated-histories

then do as mentioned.

Sunday, October 27, 2019

Interface Versus Abstract Class

- Interface are stateless(no instance fields.).
- Interface provide behavior, not state.
- Abstract classes provide behavior and state.

Lamda Expressions Versus Anonymous Classes


  • Lamdas are more succinct.  
  • Lamdas do not create additional class files.  
  • Not every occurrence of lamda crates a new object.  
  • On the other hand:     
         - Lamdas only work for FIs
         - Anonymous classes can have state(That is, fields)

   

Wednesday, August 21, 2019

Restore database in PostgreSQL when getting error unsupported version (1.13) in file header

I encountered this problem on pgadmin III and was able to fix it by switcing from pgadmin location to the PostgreSQL binaries location:

In pgadmin :
In Windows 
File menu > Options > Binary Paths, then changed "PG bin path" to postgresql/9.x/bin instead of ProgramFiles/pgadmin.

In Linux do similar process and locate the location of PostgreSQL binaries location and point there instead of pgadmin.

Restore worked fine afterwards.

Thursday, October 11, 2018

Benefits of final keyword in Java

The final keyword is used to restrict the user, any field that we never expect to be changed (be that a primitive value, or a reference to an object, whether or not that particular object is itself immutable or not), should generally be declared as a final variable. We are always allowed to initialize a final variables and the compiler makes sure that we can do it only once.

Example : Making a collection reference variable final means only reference can not be changed but you can add, remove or change object inside collection.
For example:
private final List loans = new ArrayList();
loans.add(“home loan”); //valid
loans.add("personal loan"); //valid
loans = new Vector(); //not valid

The final keyword helps in making a variable unmodifiable after the initialization. Once the identity of a final object reference is set, it can still change its state, but not its identity (that is, you can not re-point the object reference to some other object).
Note that variable declared using final keyword should not be called as constants. Because when an array is declared as final, then the state of the object stored in the array can be modified. In this case, we need to make it immutable in order not to allow modifications to it.
final keyword can be used in the following contexts.
1) Declaring the Variable as final
If we declare the variable as final, then we cannot change the value of it (It will be constant).
If the final variable that have no value assigned at the time of declaration, then it is called blank final variable or uninitialized final variable and it can be initialized in the constructor only. The blank final variable can also be a static which will be initialized only in the static block.
Example :-

2) Declaring the Parameter as final
If we declare any parameter as final, then we cannot change the value of it.
Example :-

3) Declaring the Method as final
If we declare any method as final, then we cannot override it.
Example :-

4) Declaring the Class as final
If we declare any class as final, then we cannot extend it, means we can use the class as a Base Class Functionality.
Example :-
1
2
3
final class Student
{

Monday, September 3, 2018

Docker concepts


- Docker is changing how applications are deployed by simplifying the overall application delivery experience. It increases your ability to deliver software more rapidly, and provides a common platform for dev and ops to collaborate. It also maximizes efficiency by integrating seamlessly with existing tool chains.

Docker is a platform for developers and sysadmins to develop, deploy, and run applications with containers. The use of Linux containers to deploy applications is called containerization. Containers are not new, but their use for easily deploying applications is.
Containerization is increasingly popular because containers are:
  • Flexible: Even the most complex applications can be containerized.
  • Lightweight: Containers leverage and share the host kernel.
  • Interchangeable: You can deploy updates and upgrades on-the-fly.
  • Portable: You can build locally, deploy to the cloud, and run anywhere.
  • Scalable: You can increase and automatically distribute container replicas.
  • Stackable: You can stack services vertically and on-the-fly.

Note: Please go through following link for more information and getting started.
1. https://docs.docker.com/get-started/
2. https://docs.docker.com/get-started/#docker-concepts
3. https://medium.com/travis-on-docker/why-and-how-to-use-docker-for-development-a156c1de3b24


Docker compose:

Typical application have multiple components.
We can run multi container applications with Docker Compose.(database server, application server , caching and messaging server etc...)
Docer compose allow you to run multi container application easily.

- Define and run multicontainer applications.
- Configuration defined in one or more files
   docker-compose.yml (default)
   docker-compose.override.yml (default)
- Mulitiple files specified using -f
- Single command to manage all services
- Great for dev, staging, and CI

--  To bring up all the services, to build all the images, to shut down all the services, that is very convenient.  

SOLID-Design-Principles

SOLID-Design-Principles The SOLID principles are fundamental to designing effective, maintainable, object-oriented systems. Whether you...