Found 346 Articles for Java Programming

Executing C# code in Linux

Ajay yadav
Updated on 05-Jan-2021 06:38:26

4K+ Views

The .NET centric applications are meant to windows operating system up till now, but now Microsoft has introduced a new cross-platform application called Mono which enables the execution of the application developed under the .NET platform in Linux environment by giving an impression in such a way that as if we are running Linux package rather than executing .exe file.MonoMono is an open-source utility that allows the developer to execute .NET centric applications on other platforms such as Mac or Linux as it provides an installation package for Windows platform to compile and execute .NET assemblies on Windows OS without ever ... Read More

Where objects, methods and variables are stored in memory in Java?

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

3K+ Views

There are five main memory areas which are used to various Java elements. Following is the list of the same. Class Area - This area contains the static members of the class. Method Area - This area contains the method definition and executable code. Heap Area - This area contains the objects which are dynamically allocated/deallocated. if an object is no more referenced by any live reference it is deallocated. Stack Area - This area contains the local variables. Pool Area - Contains immutable objects like string.

volatile Keyword in Java

Chandu yadav
Updated on 23-Jun-2020 15:30:10

5K+ Views

The volatile modifier is used to let the JVM know that a thread accessing the variable must always merge its own private copy of the variable with the master copy in the memory.Accessing a volatile variable synchronizes all the cached copied of the variables in the main memory. Volatile can only be applied to instance variables, which are of type object or private. A volatile object reference can be null.Examplepublic class MyRunnable implements Runnable {    private volatile boolean active;    public void run() {       active = true;       while (active) {       }    }    public void stop() {       active = false;    } }

synchronized Keyword in Java

Ankith Reddy
Updated on 23-Jun-2020 15:32:55

2K+ Views

When we start two or more threads within a program, there may be a situation when multiple threads try to access the same resource and finally they can produce unforeseen result due to concurrency issues. For example, if multiple threads try to write within a same file then they may corrupt the data because one of the threads can override data or while one thread is opening the same file at the same time another thread might be closing the same file.So there is a need to synchronize the action of multiple threads and make sure that only one thread ... Read More

Java program to check string as palindrome

Arjun Thakur
Updated on 23-Jun-2020 15:21:47

3K+ Views

A string is Palindrome if position of each character remain same in case even string is reversed.For example 'MADAM' is a palidrome string as position of each character remain same even if string 'MADAM' is reversed.Now in order to identify a string as palindrome or not we can use library method approach and also without library method approach.But if we want to check if "Madam" is palindrome or not , it will show us that it is not a palindrome because of the upper case of first letter.Example - Without library method. Live Demopublic class Palindrome {    public static void ... Read More

Java program to check occurrence of each vowel in String

Chandu yadav
Updated on 23-Jun-2020 15:22:32

2K+ Views

To count occurence of vowels in a string again use Map utility of java as used in calculating occurence of each character in string.Put each vowel as key in Map and put initial value as 1 for each key.Now compare each character with key of map if a character matches with a key then increase its corresponding value by 1.Examplepublic class OccurenceVowel {    public static void main(String[] args) {       String str = "AEAIOG";       LinkedHashMap hMap = new LinkedHashMap();       hMap.put('A', 0);       hMap.put('E', 0);       hMap.put('I', 0);       hMap.put('O', 0);       hMap.put('U', 0);       for (int i = 0; i

ListIterator in Java

Arjun Thakur
Updated on 23-Jun-2020 15:23:49

284 Views

The java.util.LinkedList.listIterator(int index) method returns a list-iterator of the elements in this list (in proper sequence), starting at the specified position in the list.DeclarationFollowing is the declaration for java.util.LinkedList.listIterator() methodpublic ListIterator listIterator(int index)Parametersindex − index of the first element to be returned from the list-iteratorReturn ValueThis method returns a ListIterator of the elements in this list (in proper sequence), starting at the specified position in the listExceptionIndexOutOfBoundsException − if the index is out of rangeExampleThe following example shows the usage of java.util.LinkedList.listIterator() method.Example Live Demopackage com.tutorialspoint; import java.util.*; public class LinkedListDemo {    public static void main(String[] args) { ... Read More

Java 8 Optional Class

Chandu yadav
Updated on 23-Jun-2020 15:24:33

231 Views

Optional is a container object used to contain not-null objects. Optional object is used to represent null with absent value. This class has various utility methods to facilitate code to handle values as 'available' or 'not available' instead of checking null values. It is introduced in Java 8 and is similar to what Optional is in Guava.Class DeclarationFollowing is the declaration for java.util.Optional class −public final class Optional extends ObjectClass MethodSr.No.Method & Description1static Optional empty()Returns an empty Optional instance.2boolean equals(Object obj)Indicates whether some other object is "equal to" this Optional.3Optional filter(PredicateRead More

Java instanceof and its applications

Ankith Reddy
Updated on 23-Jun-2020 15:25:56

404 Views

instanceof operator is used to check the type of object passed. Following rules explain the usage of instanceof operator in Java.instanceof operator returns true for the object if checked against its class type.instanceof operator returns false for the object if checked against its type which is not in its hierarchy.instanceof operator returns true for the child object if checked against parent object type.instanceof operator returns true for the complete object hierarchy up to the Object class.instanceof operator returns false for the null value.instanceof operator returns false for the parent object if checked against child object type.Following example showcases the above ... Read More

Jagged Array in Java

Chandu yadav
Updated on 23-Jun-2020 15:28:13

3K+ Views

Jagged array is a multidimensional array where member arrays are of different size. For example, we can create a 2D array where first array is of 3 elements, and is of 4 elements. Following is the example demonstrating the concept of jagged array.Example Live Demopublic class Tester {    public static void main(String[] args){       int[][] twoDimenArray = new int[2][];       //first row has 3 columns       twoDimenArray[0] = new int[3];       //second row has 4 columns       twoDimenArray[1] = new int[4];       int counter = ... Read More

Advertisements