Following are the notable differences between HashMap and ConcurrentHashMap classes in Java. HashMapConcurrentHashMapSynchronizedHashMap is not synchronized.ConcurrentHashMap is synchronized.Thread SafeHashMap is not thread safe.ConcurrentHashMap is thread safe.Iterator typeHashMap iterator is fail-fast and ArrayList throws ConcurrentModificationException if concurrent modification happens during iteration.ConcurrentHashMap is fail-safe and it will never throw ConcurrentModificationException during iteration.Null valuesHashMap allows key and value to be null.ConcurrentHashMap does not allow null key/value. It will throw NullPointerException.PerformanceHashMap is faster.ConcurrentHashMap is slower than HashMap.Since Java Version1.21.5Exampleimport java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; public class Tester { public static void main(String[] args) { List arrayList = new ArrayList(); ... Read More
Token is the smallest element of a program. Let us learn about identifiers and keywords in C# that are tokens −KeywordsKeywords are reserved words predefined to the C# compiler. These keywords cannot be used as identifiers. However, if you want to use these keywords as identifiers, you may prefix the keyword with the @ character.The following are some of the reserved keywords in C# −abstractAsBaseboolBreakbytecasecatchcharcheckedclassConstcontinuedecimaldefaultdelegateDodoubleElseenumeventexplicitexternFalsefinallyFixedfloatforforeachgotoIfimplicitInin (generic modifier)intinterfaceinternalIslockLongnamespacenewnullobjectoperatoroutout (generic modifier)overrideparamsIdentifiersAn identifier is a name used to identify a class, variable, function, or any other user-defined item. The basic rules for naming classes in C# are as follows −A name must begin ... Read More
To get the octal equivalent of a decimal in C# −Firstly, for the decimal value use a while loop and store the remainder in the array set for octal. Here we found the mod 8 of them in the array.After that, divide the number by 8 −while (dec != 0) { oct[i] = dec % 8; dec = dec / 8; i++; }Let us see the complete code. Here, our decimal number is 12 −Exampleusing System; namespace Demo { class Program { static void Main(string[] args) { ... Read More
Type safe in C# wouldn’t allow an object to sneak into other object’s memory. Let us see an example to understand the concept of −Examplepublic class One { public int Prop{ get; set;} } public class Two { public int Prop{get;set;} public int Prop1{get;set;} }Let’s say I have an object Class One −One ob = new One();Now you won’t be able to cast your object ob to the second class i.e. class Two. If you will cast it then a compile time error will arise because of the Type Safe feature in C#.
Transpose of a matrix flips the matrix over its diagonal and this brings the row elements on the column and column elements on the row.For example −Matrix before Transpose: 123 456 789 Matrix after Transpose: 147 258 369Let us see an example in C# to achieve transpose of a matrix −Exampleusing System; public class Demo { public static void Main() { int i, j, m, n; int[, ] arr1 = new int[30, 30]; int[, ] arr2 = new int[30, 30]; Console.Write("Enter the number of ... Read More
The following is an example showing how to display some of the escape characters in C# −Exampleusing System; using System.Collections.Generic; class Demo { static void Main() { Console.WriteLine("Warning!" + '\u0007'); Console.WriteLine("Test \t Demo Text"); Console.WriteLine("This is it!This is on the next line!"); } }For the complete list of escape sequences in C# −Escape characterDescriptionPattern\aMatches a bell character, \u0007.\a\bIn a character class, matches a backspace, \u0008.[\b]{3, }\tMatches a tab, \u0009.(\w+)\t\rMatches a carriage return, \u000D. (\r is not equivalent to the newline character, .)\r(\w+)\vMatches a vertical tab, ... Read More
The following are the hidden or lesser known useful features of C# −Lambda ExpressionsA lambda expression in C# describes a pattern. It has the token => in an expression context. This is called goes to operator and used when a lambda expression is declared.NullablesC# provides a special data types, the nullable types, to which you can assign normal range of values as well as null values. The following is the syntax − ? = null;Null Coalescing OperatorThe null coalescing operator is used with the nullable value types and reference types. It is used for converting an operand to the ... Read More
System.Array implements interfaces, like ICloneable, IList, ICollection, and IEnumerable, etc. The ICloneable interface creates a copy of the existing object i.e a clone.Let us see learn about the ICloneable interface. It only has a Clone() methods because it creates a new object that is a copy of the current instance.The following is an example showing how to perform cloning using ICloneable interface −Exampleusing System; class Car : ICloneable { int width; public Car(int width) { this.width = width; } public object Clone() { return new Car(this.width); ... Read More
To provide properties to other components, the extender provider is used. Let’s consider an example of a TooTtip component.You add the component to a form. This sets a ToolTip property to every control. The same property is not under the attacked PropertyGrid control.myTooltip1.SetToolTip(btn1, "This is ToolTip!");Let us see how to implement extender provider component −Firstly, define a component −public class MyExtender : IExtenderProvider {...}IExtenderProvider definition −public interface IExtenderProvider { bool newExtend(object extendeNew); }Now you need to implement the newExtend method. This is done to return true for every related component or control.
Punctuators are used in C# as special symbols to a group or divide the code. It includes −] () {}, ; * = #For example, = gets included in a class or even while declaring a variable. Statement ends with a semi-colon −int a = 10;In a class, the braces are used −class Demo { }While declaring a dictionary −var d = new Dictionary(5);It is also used while declaring and initializing a list −List myList = new List() { "mammals", "reptiles", "amphibians" };
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP