![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 9326 Articles for Object Oriented Programming
![Sravani S](https://www.tutorialspoint.com/assets/profiles/13538/profile/60_67753-1512711355.jpg)
444 Views
To avoid hard coding you can read the size of the array from the user using command line arguments of the reader classes like Scanner. Then using this value create an array:Exampleimport java.util.Arrays; import java.util.Scanner; public class PopulatingAnArray { public static void main(String args[]) { System.out.println("Enter the required size of the array :: "); Scanner s = new Scanner(System.in); int size = s.nextInt(); int myArray[] = new int [size]; System.out.println("Enter the elements of the array one by one "); for(int i=0; i
![V Jyothi](https://www.tutorialspoint.com/assets/profiles/13530/profile/60_77592-1512648869.jpg)
6K+ Views
To find the intersection of two arrays in java use two loops. The outer loop is to iterate the elements of the first array whereas, the second loop is to iterate the elements of the second array. Within the second loop compare the elements of the two arrays:ExampleLive Demopublic class IntersectionOfTwoArrays { public static void main(String args[]) { int myArray1[] = {23, 36, 96, 78, 55}; int myArray2[] = {78, 45, 19, 73, 55}; System.out.println("Intersection of the two arrays ::"); for(int i = 0; i
![vanithasree](https://www.tutorialspoint.com/assets/profiles/13547/profile/60_85216-1512542720.jpg)
570 Views
While writing the name of the constants it is suggested to write all the letters in upper case. If constant contains more than one word they should be separated by underscore (_). Example Live Demo public class ConstantsTest { public static final int MIN_VALUE = 22; public static final int MAX_VALUE = 222; public static void main(String args[]) { System.out.println("Value of the constant MIN_VALUE: "+MIN_VALUE); System.out.println("Value of the constant MAX_VALUE: "+MAX_VALUE); } } Output Value of the constant MIN_VALUE: 22 Value of the constant MAX_VALUE: 222
![Priya Pallavi](https://www.tutorialspoint.com/assets/profiles/13562/profile/60_91320-1512544134.jpg)
6K+ Views
To read data from user create a scanner class. Read the size of the array to be created from the user using nextInt() method. Create an array with the specified size. In the loop read the values from the user and store in the array created above.Exampleimport java.util.Arrays; import java.util.Scanner; public class PopulatingAnArray { public static void main(String args[]) { System.out.println("Enter the required size of the array :: "); Scanner s = new Scanner(System.in); int size = s.nextInt(); int myArray[] = new int [size]; ... Read More
![radhakrishna](https://www.tutorialspoint.com/assets/profiles/13544/profile/60_40618-1512640354.jpg)
792 Views
While choosing a package name you need to keep the following points in mind. The name of the package should be in small letters. It is suggested to start the name of the package with the top level domain level followed by sub domains, ex: com.example.tutorialspoint. Example You can declare a package as in. package com.mypackage.tutorialspoint; Public class Sample { Public static void main(String args[]) { System.out.println("Welcome to Tutorialspoint"); } } Executing a package You need to compile the file with packages using –d ... Read More
![Nikitha N](https://www.tutorialspoint.com/assets/profiles/13558/profile/60_76068-1512713229.jpg)
606 Views
The openStream() method of the URL class opens a connection and returns an InputStream. Using this stream, you can you read contents from that connection.Exampleimport java.io.InputStream; import java.net.URL; import java.util.Scanner; public class ReadingURL { public static void main(String args[]) throws Exception { URL url = new URL("http://www.tutorialspoint.com/"); InputStream inputStream = url.openStream(); Scanner s = new Scanner(inputStream); while(s.hasNext()) { System.out.println(s.nextLine()); } } }OutputLearn CouchDB Learn DB2 Learn DocumentDB SQL Learn DocumentDB Learn DynamoDB Learn H2 Database Learn HSQLDB Learn IMS DB …………………………………………………………………………………………. ………………………………………………………………………………………………… ………………………………………………………………………………………………
![mkotla](https://www.tutorialspoint.com/assets/profiles/13540/profile/60_41073-1512640012.jpg)
540 Views
While writing an interface/class names you need to keep the following points in mind. First letter of the interface/class name should be capital and remaining letters should be small (mixed case). interface Sample Likewise, first letter of each word in the name should be capital an remaining letters should be small. interface MYInterface Keeping interface names simple and descriptive is suggestable. Better not to use acronyms while writing interface/class names. Example Live Demo interface MyInterface { void sample(); void demo(); } ... Read More