Found 9320 Articles for Object Oriented Programming

How to overwrite a specific chunk in a byte array using java?

Abhinaya
Updated on 16-Jun-2020 10:02:01

1K+ Views

Java provides a ByteBuffer class which allows you to wrap an array into a byte buffer using its wrap() method. Once you did that you can replace the contents of the buffer using the position(): To select the starting position and, put(): To replace the data methods:ExampleLive Demoimport java.nio.ByteBuffer; public class OverwriteChunkOfByteArray {    public static void main(String args[]) {       String str = "Hello how are you what are you doing";       byte[] byteArray = str.getBytes();       System.out.println("Contents of the byet array :: ");             for(int i = 0; i

What are the different types of keywords in Java?

varma
Updated on 18-Feb-2020 11:33:18

2K+ Views

Following are the different types of keywords in java—Access modifiers − private, protected, public.Class, method, variable modifiers− abstract, class, extends, final, implements, interface, native, new, static, strictfp, synchronized, transient, volatile.Flow control− break, case, continue, default, do, else, for, if, instanceof, return, switch, while.Package control− import, package.Primitive types− boolean, byte, char, double, float, int, long, short.Error handling− assert, catch, finally, throw, throws, try.Enumeration− enum.Others− super, this, void.Unused− const, goto.

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

440 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

773 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

327 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

172 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

452 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

7K+ 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

577 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

Advertisements