Skip to content

Instantly share code, notes, and snippets.

@vikasverma787
vikasverma787 / Bitwise operator
Created April 30, 2018 11:17
Bitwise operator
Count Bit Set
package com.algo.bits;
import java.io.*;
class countSetBits
{
/* Function to get no of set
bits in binary representation
of positive integer n */
static int countSetBits(int n)
@vikasverma787
vikasverma787 / Java Lock Example
Last active March 17, 2018 08:50
Java Lock Example Reentrant Lock
Lock : This is the base interface for Lock API. It provides all the features of synchronized keyword with additional ways to create
different Conditions for locking, providing timeout for thread to wait for lock. methods are lock(),unlock(),tryLock(),newCondition()
Condition: Condition objects are similar to Object wait-notify model with additional feature to create different sets of wait.
A Condition object is always created by Lock object. Some of the important methods are await() that is similar to wait() and signal(),
signalAll() that is similar to notify() and notifyAll() methods.
Benefits :
synchronization blocks or methods can cover only one method whereas we can acquire the lock in one method and release it in another method
with Lock API.
Control plane, Data Plane, Management Plane
FCAPS :
a). Fault (alarma), b). configure(Loopback,OSPF,RSVP,MPLS_TE) 3). Accounting(no of packets send recieve) 4). Performance (failed packets)
5). Security
SONET DWDM :
Dense wavelength division multiplexing (DWDM) is a fiber-optic transmission technique that employs light wavelengths to transmit data parallel
-by-bit or serial-by-character.
--------------------------------------------------------------
In the java.util.concurrent package there are three interfaces:
Executor — Used to submit a new task.
ExecutorService — A subinterface of Executor that adds methods to manage lifecycle of threads used to run the submitted
tasks and methods to produce a Future to get a result from an asynchronous computation.
ScheduledExecutorService — A subinterface of ExecutorService, to execute commands periodically or after a given delay.
---------------------------------------------------------------
*** How to Create an Executor ***
To create an Executor it is possible to use the factory Executors class.
Most common methods are used to create:
@vikasverma787
vikasverma787 / One to one hibernate relationship
Created February 25, 2018 08:20
One to one hibernate relationship
1 -------------> 1
Stock Stock_Daily_Record
@OneToOne(fetch = FetchType.LAZY, mappedBy = "stock", @OneToOne(fetch = FetchType.LAZY)
cascade = CascadeType.ALL) @PrimaryKeyJoinColumn
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@vikasverma787
vikasverma787 / One to many relationship hibernate
Created February 17, 2018 17:53
One to many relationship hibernate
1 -------> many
Stock -------> Stock_Daily_Record
@OneToMany(fetch = FetchType.LAZY, mappedBy = "stock") -------> @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "STOCK_ID", nullable = false)
package com.mkyong.stock;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
@vikasverma787
vikasverma787 / Rest API
Last active February 17, 2018 16:28
Rest API
* Representational State Transfer uses HTTP protocol for data communication developed by Roy Fielding.
* Everything is Resource (REST uses various representations to represent a resource like Text, JSON and XML)
* RESTful web services are light weight, highly scalable and maintainable.
* Http methods : GET, PUT, POST, DELETE, OPTIONS
* PUT used to create a new resource and POST used to update the existing resource
* OPTIONS used to get the list of supported operations on a resource.
* A web service is a collection of open protocols and standards used for exchanging data between applications or systems. Software applications written in various programming languages and running on various platforms can use web services to exchange data over computer networks.
Ex:--------------
we will create UserService.java, User.java,UserDao.java files under the com.tutorialspoint package.
* Inheritance 2. Polymorphism 3. Abstraction 4. Encaptulation
* Polymorphism --> Method OverLoading Method Overriding
* Method Overriding Rules:
a). public private protected modifier
class Parent
{
protected Parent get() throws IOException
{
return null;
}
@vikasverma787
vikasverma787 / ForkJoinPool Example
Created January 21, 2018 07:04
ForkJoinPool Example
/*
ForkJoinPool methods :
getActiveThreadCount(), getParallelism(), getPoolSize(), invoke(ForkJoinTask fjt), getRunningThreadCount()
RecursiveTask has method compute
Code:
*/
package com.thread.fork;
@vikasverma787
vikasverma787 / Memory Analyzer WeakHashMap
Created January 20, 2018 11:46
Memory Analyzer WeakHashMap
save Heap dump using jconsole :
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\vikas.verma1>cd workspace\demo
C:\Users\vikas.verma1\workspace\demo>
C:\Users\vikas.verma1\workspace\demo>cd src