Found 34494 Articles for Programming

How to execute a Python file in Python shell?

Rajendra Dharmkar
Updated on 03-Aug-2023 11:21:15

6K+ Views

Venturing further into the realm of Python programming, you'll undoubtedly encounter scenarios where executing a Python file from within the Python shell becomes essential. This capability endows you with the power to test, run, and interact with your Python scripts seamlessly without exiting the Python environment. Within this article, we shall discuss some distinct methods to execute Python files within the Python shell, each offering its unique functionalities and adaptability, facilitating seamless interaction with your Python scripts. As a Python coding expert, I would walk you through each method with step-by-step explanations and examples in a lucid style that is ... Read More

What are variable length (Dynamic) Arrays in Java?

Srinivas Gorla
Updated on 19-Feb-2020 12:12:03

4K+ Views

In Java, Arrays are of fixed size. The size of the array will be decided at the time of creation. But if you still want to create Arrays of variable length you can do that using collections like array list.Exampleimport java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class AddingItemsDynamically {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter the size of the array :: ");       int size = sc.nextInt();       String myArray[] = new String[size];       System.out.println("Enter elements of the array (Strings) :: ");       for(int i=0; i

How to create a generic array in java?

Abhinanda Shri
Updated on 30-Jul-2019 22:30:20

172 Views

No, we can’t create generic arrays in java.

How to add items to an array in java dynamically?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:20

9K+ Views

Since the size of an array is fixed you cannot add elements to it dynamically. But, if you still want to do it then, Convert the array to ArrayList object.Add the required element to the array list.Convert the Array list to array.Exampleimport java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class AddingItemsDynamically {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter the size of the array :: ");       int size = sc.nextInt();       String myArray[] = new String[size];       System.out.println("Enter elements of the array ... Read More

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

774 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

328 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.

Advertisements