Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Java Articles
Page 304 of 450
Export Preferences to XML file in Java
In order to export preferences to an XML file in Java, we need to use the exportSubtree() method. This method emits an XML document showing all of the preferences contained in this node and all of its descendants. This XML document provides an offline backup of the subtree rooted at the node.Declaration − The java.util.prefs.Preferences.exportSubtree method is declared as follows −public abstract void exportSubtree(OutputStream os) throws IOException, BackingStoreExceptionLet us see a program to export preferences to an XML file in Java −import java.io.FileOutputStream; import java.util.prefs.Preferences; public class Example { public static void main(String args[]) throws Exception { Preferences ...
Read MoreMoving a file from one directory to another using Java
We can use Files.move() API to move file from one directory to another. Following is the syntax of the move method.public static Path move(Path source, Path target, CopyOption... options) throws IOExceptionWheresource − Source path of file to be movedtarget − Target path of file to be movedoptions − options like REPLACE_EXISTING, ATOMIC_MOVEExampleimport java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Tester { public static void main(String[] args) { //move file from D:/temp/test.txt to D:/temp1/test.txt //make sure that temp1 folder exists moveFile("D:/temp/test.txt", "D:/temp1/test.txt"); } private static void moveFile(String ...
Read MoreObject Serialization with inheritance in Java
In Serialization when inheritance is introduced then on the basis of superclass and subclass certain cases have been defined which make the understanding of Serialization in each case much simpler. The fundamental rules which should be followed are as below.1. When super class is implements Serializable interface and subclass is not.In this case the object of subclass get serialized by default when superclass get serialize, even if subclass doesn't implements Serializable interface.Examplepublic class TestSerialization { public static void main(String[] args) throws IOException, ClassNotFoundException { B obj = new B(); FileOutputStream fos = new ...
Read MorePOJI in Java
POJI is an acronym for Plain Old Java Interface which corresponds to a Java standard interface which means that these interfaces are in the context of providing services in JEE. For example, OSGI service is offered through POJI in JEEIn other terms we can say that POJI is an ordinary interface without any specialty that is not inherited from any of the technology API specific interfaces or framework interfaces.Exampleinterface myCustomInterface { public void myMethod(); } interface mySecondCustomInterface extends myCustomInterface { public void mySecondMethod(); }Both interfaces would be called as POJI as they do not inherit any technology specific ...
Read MorePOJO vs Java Beans
As we know that in Java POJO refers to the Plain old Java object.POJO and Bean class in Java shares some common features which are as follows −Both classes must be public i.e accessible to all.Properties or variables defined in both classes must be private i.e. can't be accessed directly.Both classes must have default constructor i.e no argument constructor.Public Getter and Setter must be present in both the classes in order to access the variables/properties.The only difference between both the classes is Java make java beans objects serialized so that the state of a bean class could be preserved in ...
Read MorePrimitive Wrapper Classes are Immutable in Java
In Java Immutable class is a class which once created and it's contents can not be changed.On same concept Immutable objects are the objects whose state can not be changed once constructed.Wrapper classes are made to be immutable due to following advantages −Since the state of the immutable objects can not be changed once they are created they are automatically synchronized.Immutable objects are automatically thread-safe, the overhead caused due to use of synchronisation is avoided.Once created the state of the wrapper class immutable object can not be changed so there is no possibility of them getting into an inconsistent state.The ...
Read MoreEuler’s Totient function for all numbers smaller than or equal to n in java
Following is a program to get the result of Euler’s Totient function for all numbers smaller than or equal to n when n is given.Programimport java.util.Scanner; public class EulerTotient { public static int gcd(int a,int b){ int i, hcf = 0; for(i = 1; i
Read MoreEuler’s Totient function for all numbers smaller than or equal to n in java
Following is a program to get the result of Euler’s Totient function for all numbers smaller than or equal to n when n is given.Programimport java.util.Scanner; public class EulerTotient { public static int gcd(int a,int b){ int i, hcf = 0; for(i = 1; i
Read MoreEuler’s criterion in java
According to Euler’s criterion a square root of n under modulo p exists if and only if a number num exists such that num%p is equal to n%p.Programimport java.util.Scanner; public class EulersCriterion { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter n value :"); int n = sc.nextInt(); System.out.println("Enter p value :"); int p = sc.nextInt(); n = n % p; int flag = 0; for ...
Read MoreEuler’s criterion in java
According to Euler’s criterion a square root of n under modulo p exists if and only if a number num exists such that num%p is equal to n%p.Programimport java.util.Scanner; public class EulersCriterion { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter n value :"); int n = sc.nextInt(); System.out.println("Enter p value :"); int p = sc.nextInt(); n = n % p; int flag = 0; for ...
Read More