Found 4348 Articles for Java 8

How to declare Java array with array size dynamically?

Ramu Prasad
Updated on 19-Feb-2020 12:09:26

2K+ Views

To declare array size dynamically read the required integer value from the user using Scanner class and create an array using the given value: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

Is null a keyword in Java?

usharani
Updated on 30-Jul-2019 22:30:20

423 Views

No, null is not a keyword. Though they seem like keywords null, true and, false are considered as literals in Java.

Is main a keyword in Java?

varun
Updated on 30-Jul-2019 22:30:20

750 Views

No, main is not a keyword in Java.

Are ‘this’ and ‘super’ keywords in Java?

Prabhas
Updated on 30-Jul-2019 22:30:20

309 Views

Yes, this and super are keywords in Java. Where ‘this’ is used as a reference of the current object and, ‘super’ is used as a reference to the superclass object.

What does the native in Java stand for?

seetha
Updated on 30-Jul-2019 22:30:20

165 Views

A native method in Java is a method whose implementation is written in other languages such as c and c++.The ‘native’ keyword is used as a method to indicate that it is implemented in another language.

How to define an array size in java without hardcoding?

Sravani S
Updated on 19-Feb-2020 12:08:44

404 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

How to find the intersection of two arrays in java?

V Jyothi
Updated on 16-Jun-2020 09:54:49

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

How do I write constants names in Java?

vanithasree
Updated on 30-Jul-2019 22:30:20

554 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

How to populate an array one value at a time by taking input from user in Java?

Priya Pallavi
Updated on 19-Feb-2020 11:29:27

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

How do I write package names in Java?

radhakrishna
Updated on 30-Jul-2019 22:30:20

751 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

Advertisements