Skip to main content

Posts

Showing posts from 2018

Java String & String Pool

👱 String variables are stored in “constant string pool”. Once the string reference changes the old value that exists in the “constant string pool”, it cannot be erased. Example: String name = “book”; Constant string pool . If the name value has changed from “book” to “pen”. Constant string pool Then the older value retains in the constant string pool. Basically, string is a sequence of characters but it’s not a primitive type. When we create a string in java, it actually creates an object of type String. String is the immutable object which means that it cannot be changed once it is created. String is the only class where operator overloading is supported in Java. We can concat two strings using the + operator. For example "a"+"b"="ab". Java provides two useful classes for String manipulation – StringBuffer and StringBuilder. String Buffer: Here string values are stored in a stack. If the values are changed then the new va...

Java Collections Framework – Interface, List, Queue, Sets, Maps

💁 The collection is a framework that is designed to store the objects and manipulate the design to store the objects. Collections are used to perform the following operations: Searching Sorting Manipulation Insertion Deletion A group of objects is known as collections.   All the classes and interfaces for collecting are available in Java utile package. Given below are the Classes and Interfaces that are available in Collections: Interfaces: Collection List Set Map Sorted Set Sorted Map Queue Classes: Lists: Array List Vector Linked List Sets: Hash set Linked Hash Set Tree Set Maps: HashMap Hash Table TreeMap Linked Hashed Map Queue: Priority Queue Ordered and Sorted in collections:-  Ordered: It means the values that are stored in a collection is based on the values that are added to the collection. So we can iterate the values from the collection in a specific order. Sorted: Sorting mechanism can be applied inter...

GOLANG INTERVIEW QUESTIONS & ANSWERS

Question 1. What Are The Benefits Of Using Go Programming? Answer : Support for environment adopting patterns similar to dynamic languages. For example type inference (x := 0 is valid declaration of a variable x of type int). Compilation time is fast. InBuilt concurrency support: light-weight processes (via goroutines), channels, select statement. Conciseness, Simplicity, and Safety. Support for Interfaces and Type embdding. Production of statically linked native binaries without external dependencies. Question 2 . Does Go Support Type Inheritance? Answer : No support for type inheritance. Question 3. Does Go Support Operator Overloading? Answer : No support for operator overloading. Question 4 . Does Go Support Method Overloading? Answer : No support for method overloading. Question 5 . Does Go Support Pointer Arithmetics? Answer : No support for pointer arithmetic. Question 6 . Does Go Support Generic Programming? Answer :  No support for generic ...

Sliding Window Maximum (Maximum of all subarrays of size k) Using Golang

Given an array and an integer k, find the maximum for each and every contiguous subarray of size k. Examples : Input : arr[] = {1, 2, 3, 1, 4, 5, 2, 3, 6} k = 3 Output : 3 3 4 5 5 5 6 package main import "fmt" var n int func main() { k := 3 s := []int{1, 2, 3, 1, 4, 5, 2, 3, 6} n = k slidingWindowMaximum(s, 0, k) } func slidingWindowMaximum(arr []int, i int, k int) { //Check Array size greater then k or not ! if len(arr) < k { return } // Find Max Value in Sub Arrays max := 0 for ; i < k; i++ { //Find Max Value max = findmax(max, arr[i]) } //Print Max Sub Arrays Element fmt.Print(max, " ") //Find in next Sub Arrays in Max Call function slidingWindowMaximum(arr, i-n+1, k+1) } func findmax(a int, b int) int { if a < b { return b } else { return a } }

MVC pattern with user permission management API base framework in Go (Golang)

om_admin om_admin is a lightweight MVC pattern with control roles management API base framework in Go (Golang) for building fast, scalable and robust database-driven web applications. Features: Postgres, MySQL, SQLite and Foundation database support Modular (you can choose which components to use) Middleware support. All compatible Middleware works out of the box Gopher spirit (write golang, use all the golang libraries you like) Lightweight. Only MVC Multiple configuration files support (currently json, yaml, toml and hcl) Overview om is a lightweight MVC framework. It is based on the principles of simplicity, relevance and elegance. Simplicity. The design is simple, easy to understand, and doesn't introduce many layers between you and the standard library. It is a goal of the project that users should be able to understand the whole framework in a single day. Relevance. om doesn't assume anything. We focus on things that matter, this way we are able to ensure ...

Golang oAuth2 Google Example for Web and API

Introduction 👉 The oAuth2 protocol has almost become a standard for securing websites and API services. Developers no longer need to store and manage userIDs and passwords for their users. Offloading the authentication to OAuth2 providers such as Google, Facebook, Linkedin, Github keeps the authentication with username and password, within those providers rather than passing through the developer’s application. This reduces the risk that an application will leak user credentials and puts more control in the user's hands on for managing authentication with their accounts. I wanted to provide this capability in my own apps and went looking for a pattern to use in Go. Typically when I’m on a hunt like this I find bits and pieces that I stitch together into a reference pattern. For this oAuth pattern most of the result I found referenced back to a couple limited examples on the google site. Then it happened, I stumbled on a fantastic write-up and sample app that covers every main po...