Floating point operators and associativity in Java

Fendadis John
Updated on 21-Jun-2020 14:24:45

369 Views

Following programs shows the float arithmetic can cause dubious result if integer values are used using float variables.Examplepublic class Tester {    public static void main(String[] args) {       float a = 500000000;       float b = -500000000;       float c = 1;       float sumabc1 = a+(b+c);       float sumabc2 =(a+b)+c;       System.out.println("Floating Point Arithmetic");       System.out.println("a + ( b + c ) : " + sumabc1);       System.out.println("(a + b) + c : " + sumabc2);       ... Read More

File Handling in Java using FileReader and FileWriter

Rishi Raj
Updated on 21-Jun-2020 14:23:52

1K+ Views

Java Byte streams are used to perform input and output of 8-bit bytes, whereas Java Character streams are used to perform input and output for 16-bit unicode. Though there are many classes related to character streams but the most frequently used classes are, FileReader and FileWriter. Though internally FileReader uses FileInputStream and FileWriter uses FileOutputStream but here the major difference is that FileReader reads two bytes at a time and FileWriter writes two bytes at a time.Following example, which makes the use of these two classes to copy an input file (having unicode characters) into an output file −Exampleimport java.io.*; ... Read More

What is the SortedList class in C#?

karthikeya Boyini
Updated on 21-Jun-2020 14:23:11

76 Views

A sorted list is a combination of an array and a hash table. It contains a list of items that can be accessed using a key or an index. If you access items using an index, it is an ArrayList, and if you access items using a key, it is a Hashtable. The collection of items is always sorted by the key value.Let us see an example wherein we added 4 key and value pair for SortedList −Exampleusing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {       ... Read More

How to get current URL in JavaScript?

Arnab Chakraborty
Updated on 21-Jun-2020 14:20:51

409 Views

The window.location object can be used to get the current URL.window.location.href returns the href(URL) of the current page.I am using these code in my MVC projet.Example                                          var iid=document.getElementById("dd");         alert(window.location.href);       iid.innerHTML = "URL is" + window.location.href;    

What is the System.Reflection.Module in C#?

Chandu yadav
Updated on 21-Jun-2020 14:18:33

200 Views

The System.Reflection namespace contains classes that allow you to obtain information about the application and to dynamically add types, values, and objects to the application.It has a module constructor that initializes a new instance of the Module class. A module is a portable executable file that has one or more classes and interfaces.Let us see an example of System.Reflection in C# −Exampleusing System; using System.Reflection; [AttributeUsage(AttributeTargets.All)] public class HelpAttribute : System.Attribute {    public readonly string Url;    public string Topic // Topic is a named parameter {       get {          return ... Read More

What is the Stack class in C#?

Samual Sam
Updated on 21-Jun-2020 14:15:25

173 Views

Stack is used when you need a last-in, first-out access of items. When you add an item to the list, it is called pushing the item and when you remove it, it is called popping the item.Let us see an example of the stack class in C# −Firstly, add elements in the Stack.Stack st = new Stack(); st.Push('H'); st.Push('I'); st.Push('J'); st.Push('K'); st.Push('L');Now count the number of elements in the Stack −Console.WriteLine("Count: "+st.Count);Let us see the complete code −Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {   ... Read More

Why we should use whole string in Java regular expression

Arnab Chakraborty
Updated on 21-Jun-2020 14:14:42

793 Views

In Java regex matches() matches the input string against the whole string as it add a ^ and $ at the end of the input string.so it will not match the substring. So for matching substring, you should use find().Exampleimport java.util.regex.*; class PatternMatchingExample {    public static void main(String args[]) {       String content = "aabbcc";       String string = "aa";       Pattern p = Pattern.compile(string);       Matcher m = p.matcher(content);       System.out.println(" 'aa' Match:"+ m.matches());       System.out.println(" 'aa' Match:"+ m.find());    } }Output'aa' Match:false 'aa' Match:true

Final Arrays in Java

Rishi Raj
Updated on 21-Jun-2020 14:07:08

1K+ Views

A final variable can be explicitly initialized only once. A reference variable declared final can never be reassigned to refer to a different object.However, the data within the object can be changed. So, the state of the object can be changed but not the reference. As an array is also an object and it is referred by a reference variable which if set as final then cannot be reassigned. Let's see the examples for further explanation.Examplepublic class Tester {    public static void main(String []args) {           final int[] arr = {1, 2, 3};   ... Read More

Factory method to create Immutable List in Java SE 9

Vikyath Ram
Updated on 21-Jun-2020 14:03:37

152 Views

With Java 9, new factory methods are added to List interface to create immutable instances. These factory methods are convenience factory methods to create a collection in less verbose and in concise way.Old way to create collectionsExampleimport java.util.ArrayList; import java.util.Collections; import java.util.List; public class Tester {    public static void main(String []args) {       List list = new ArrayList();       list.add("A");       list.add("B");       list.add("C");       List readOnlylist = Collections.unmodifiableList(list);       System.out.println(readOnlylist);       try {          readOnlylist.remove(0);       ... Read More

How to create a Dictionary using C#?

karthikeya Boyini
Updated on 21-Jun-2020 14:02:04

147 Views

Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.To create a dictionary, you first need to set it and add the key and values. Here we have added 5 keys with values to a Dictionary. We have set its keys and value type as int.IDictionary d = new Dictionary(); d.Add(1, 44); d.Add(2, 34); d.Add(3, 66); d.Add(4, 47); d.Add(5, 76);The following is the complete code −Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main() {       IDictionary d = new Dictionary();       d.Add(1, 44); ... Read More

Advertisements