- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34486 Articles for Programming
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
4K+ Views
The factorial of any non-negative integer is basically the product of all the integers that are smaller than or equal to it. The factorial can be obtained using a recursive method.A program that demonstrates this is given as follows:Example Live Demopublic class Demo { public static long fact(long n) { if (n
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
618 Views
The power of a number can be calculated using recursion. Here the number is x and it is raised to power n.A program that demonstrates this is given as follows:Example Live Demopublic class Demo { static double pow(double x, int n) { if (n != 0) return (x * pow(x, n - 1)); else return 1; } public static void main(String[] args) { System.out.println("7 to the power 3 is " + pow(7, 3)); System.out.println("4 to the power 1 ... Read More
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
1K+ Views
The zip code can be validated using the java.util.regex.Pattern.matches() method. This method matches the regular expression for the zip code and the given input zip code and returns true if they match and false otherwise.A program that demonstrates this is given as follows:Example Live Demopublic class Demo { public static void main(String args[]) { String zipCode = "83592-1537"; String regex = "\d{5}(-\d{4})?"; System.out.println("The zip code is: " + zipCode); System.out.println("Is the above zip code valid? " + zipCode.matches(regex)); } }OutputThe zip code is: 83592-1537 Is the above ... Read More
![Jai Janardhan](https://www.tutorialspoint.com/assets/profiles/13513/profile/60_63529-1512538711.jpg)
3K+ Views
The phone number can be validated using the java.util.regex.Pattern.matches() method. This method matches the regular expression for the phone number and the given input phone number and returns true if they match and false otherwise.Note: We are considering a demo number for our example since we cannot use our phone number publicly.A program that demonstrates this is given as follows:Example Live Demopublic class Demo { public static void main(String args[]) { String phoneNumber = "9999999998"; String regex = "(0/91)?[7-9][0-9]{9}"; System.out.println("The phone number is: " + phoneNumber); System.out.println("Is the ... Read More
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
3K+ Views
The import statement can be used to import an entire package or sometimes import certain classes and interfaces inside the package. The import statement is written before the class definition and after the package statement(if there is any). Also, the import statement is optional.A program that demonstrates this in Java is given as follows:Example Live Demoimport java.util.LinkedList; public class Demo { public static void main(String[] args) { LinkedList l = new LinkedList(); l.add("Apple"); l.add("Mango"); l.add("Cherry"); l.add("Orange"); l.add("Pear"); System.out.println("The ... Read More
![Jai Janardhan](https://www.tutorialspoint.com/assets/profiles/13513/profile/60_63529-1512538711.jpg)
533 Views
The default access level is available when no access level is specified. All the classes, data members, methods etc. which have the default access level can only be accessed inside the same package.A program that demonstrates the default access level in Java is given as follows:Example Live Democlass Employee { int empno; String name; void insert(int e, String n) { empno = e; name = n; } void display() { System.out.println("Employee Number: " + empno); System.out.println("Name: " + name); } } public class ... Read More
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
476 Views
A class declaration can contain a String instance and methods to set and get its value in Java.A program that demonstrates this is given as follows:Example Live Democlass Name { private String name; public void setName(String n) { name = n; } public String getName() { return name; } } public class Demo { public static void main(String[] args) { Name n = new Name(); n.setName("John Smith"); System.out.println("The name is: " + n.getName()); } }OutputThe name is: John SmithNow ... Read More
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
303 Views
A single action can be performed in multiple ways using the concept of polymorphism. Run-time polymorphism can be performed by method overriding. The overridden method in this is resolved at compile time.A program that demonstrates run-time polymorphism in Java is given as follows:Example Live Democlass Animal { void sound() { System.out.println("Animal makes sound"); } } class Cat extends Animal { void sound() { System.out.println("Cat Meows"); } } class Dog extends Animal { void sound() { System.out.println("Dog Barks"); } } class Cow extends Animal { void ... Read More
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
362 Views
Sometimes the variable in the subclass may hide the variable in the super class. In that case, the parent class variable can be referred to using the super keyword in Java.A program that demonstrates this is given as follows:Example Live Democlass A { char ch; } class B extends A { char ch; B(char val1, char val2) { super.ch = val1; ch = val2; } void display() { System.out.println("In Superclass, ch = " + super.ch); System.out.println("In subclass, ch = " + ch); } ... Read More
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
1K+ Views
Multilevel inheritance is when a class inherits a class which inherits another class. An example of this is class C inherits class B and class B in turn inherits class A.A program that demonstrates constructors in a Multilevel Hierarchy in Java is given as follows:Example Live Democlass A { A() { System.out.println("This is constructor of class A"); } } class B extends A { B() { System.out.println("This is constructor of class B"); } } class C extends B { C() { System.out.println("This is constructor of class C"); ... Read More