Chandu yadav has Published 1163 Articles

instanceof operator vs isInstance method in java

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 15:18:19

240 Views

isInstance method is equivalent to instanceof operator. The method is used in case of objects are created at runtime using reflection. General practice says if type is to be checked at runtime then use isInstance method otherwise instanceof operator can be used. See the example below −Example Live Demopublic class Tester{ ... Read More

Implement Runnable vs Extend Thread in Java

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 15:04:27

1K+ Views

We can create Thread by either by implementing a runnable interface or by extending Thread class. Below are the detailed steps of using both ways to create Thread.Create a Thread by Implementing a Runnable InterfaceIf your class is intended to be executed as a thread then you can achieve this ... Read More

Set the navigation bar to stay at the top of the web page with CSS

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 14:55:13

200 Views

To set the navigation bar at top, use position: fixed property, with top property.You can try to run the following code to implement a menu that stays on the top, ExampleLive Demo                    ul {             ... Read More

How to prevent Reflection to break a Singleton Class Pattern?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 14:43:37

681 Views

A Singleton pattern states that a class can have a single instance and multiple instances are not permitted to be created. For this purpose, we make the constructor of the class a private and return a instance via a static method. But using reflection, we can still create multiple instance ... Read More

How do we access elements from the two-dimensional array in C#?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 14:23:36

3K+ Views

A 2-dimensional array can be thought of as a table, which has x number of rows and y number of columns.An element in 2-dimensional array is accessed by using the subscripts. That is, row index and column index of the array.int x = a[1, 1]; Console.WriteLine(x);Let us see an example ... Read More

How to sort one-dimensional array in ascending order using non-static method?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 14:20:04

1K+ Views

Set the unsorted array first.int[] list = {87, 45, 56, 22, 84, 65};Now use a nested for loop to sort the list, which is passed to a function.for(int i=0; i< arr.Length; i++) {    for(int j=i+1; j=arr[j]) {          temp=arr[j];          arr[j]=arr[i];     ... Read More

How to use WriteLine() method of Console class in C#?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 14:13:17

256 Views

WriteLine() is a method of the Console class defined in the System namespaceThis statement causes the message "Welcome!" to be displayed on the screen as shown below −Example Live Demousing System; namespace Demo {    class Test {       static void Main(string[] args) {          Console.WriteLine("Welcome!"); ... Read More

How to workaround Objects vs arrays in JavaScript for key/value pairs?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 13:21:48

126 Views

Store it like the following −var players = {    600 : 'Sachin',    300 : 'Brad', };For key/ value pairs, we have used the above solution, since we wanted a one-to-one. We did this to use the key as a lookup key. You can also add more values like ... Read More

What's the best way to detect a 'touch screen' device using JavaScript?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 13:08:10

507 Views

The best way to detect a ‘touch screen’ device, is to work around to see whether the touch methods are present within the document model or not.function checkTouchDevice() {    return 'ontouchstart' in document.documentElement; }Here, you can also use it to detect mobile or desktop, like the following −if (checkTouchDevice()) ... Read More

How to sort a list in C#?

Chandu yadav

Chandu yadav

Updated on 23-Jun-2020 12:46:20

156 Views

Set a list with some values. Here, we have a list of strings.var cars = new List() {"Mercedes", "Audi", "Jaguar" };To sort, simply use Sort() method.cars.Sort();The following is an example showing how to sort a list in C#.Example Live Demousing System; using System.Collections.Generic; public class Program {    public static void ... Read More

Advertisements