Skip to main content

Posts

Showing posts from December, 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 value repla

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 internally or

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 prog

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 } }