Syed Javed has Published 26 Articles

What are the methods of an array object in JavaScript?

Syed Javed

Syed Javed

Updated on 18-Jun-2020 06:46:54

128 Views

The Array object lets you store multiple values in a single variable. It stores a fixed-size sequential collection of elements of the same type.Here is a list of some of the methods of the Array object:S.NoMethod & Description       1concat()Returns a new array comprised of this array joined with ... Read More

Local variables in Java

Syed Javed

Syed Javed

Updated on 12-Mar-2020 12:14:34

1K+ Views

Local variables are declared in methods, constructors, or blocks.Local variables are created when the method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor, or block.Access modifiers cannot be used for local variables.Local variables are visible only within the declared method, constructor, ... Read More

How is down-casting possible in Java?

Syed Javed

Syed Javed

Updated on 12-Mar-2020 10:34:57

99 Views

Yes, a variable can be downcast to its lower range substitute by casting. It may lead to data loss although. See the example below −ExampleLive Demopublic class Tester {      public static void main(String[] args) {       int a = 300;         byte b = (byte)a;         System.out.println(b);    }   }OutputIt will print output as −44

How to use for each loop through an array in Java?

Syed Javed

Syed Javed

Updated on 12-Mar-2020 10:20:25

236 Views

JDK 1.5 introduced a new for loop known as foreach loop or enhanced for loop, which enables you to traverse the complete array sequentially without using an index variable.ExampleLive Demopublic class ArrayUsingForEach {    public static void main(String[] args) {       double[] myList = {1.9, 2.9, 3.4, 3.5};       for (double element: myList) {          System.out.println(element);       }    } }Output1.9 2.9 3.4 3.5

3 ways to initialize an object in Java

Syed Javed

Syed Javed

Updated on 06-Mar-2020 06:09:29

6K+ Views

Consider a class Tester which has implemented Cloneable interface. Now you can initialize an object using following three ways −1. Using new keyword.Tester tester1 = new Tester();2. Using Class.forName() methodTester tester4 = (Tester)Class.forName("Tester").newInstance();3. Using clone method.Tester tester2 = tester1.clone();

Advantages of naming conventions in Java

Syed Javed

Syed Javed

Updated on 06-Mar-2020 05:38:32

310 Views

Following the the best practices while declaring a variable.  These best practices maintains code readability, understandability as project code size increases.Variables names should be short or long enough as per the scope. For example, loop counter variable, i is fine whereas employee as loop variable.Specific words should not be used ... Read More

How to convert an input stream to byte array in java?

Syed Javed

Syed Javed

Updated on 06-Mar-2020 05:07:10

904 Views

The InputStream class in Java provides read() method. This method accepts a byte array and it reads the contents of the input stream to the given byte array.ExampleLive Demoimport java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; public class StreamToByteArray {     public static void main(String args[]) throws IOException{       ... Read More

Java program to subtract two matrices.

Syed Javed

Syed Javed

Updated on 05-Mar-2020 12:37:40

561 Views

Following is the required program.ExampleLive Demopublic class Tester {    public static void main(String args[]) {       //matrix 1       int a[][] = { { 1, 3, 4 }, { 2, 4, 3 }, { 3, 4, 5 } };       //matrix 2   ... Read More

Infinite while loop in Java

Syed Javed

Syed Javed

Updated on 27-Feb-2020 05:25:01

434 Views

Yes. Following while loop is a valid statement and causes an infinite loop.while(true);

Print Hello World without semicolon in C++

Syed Javed

Syed Javed

Updated on 11-Feb-2020 06:57:23

908 Views

There are multiple ways to write a C++ program without semicolons. Note that doing this is very bad practice and should never be used in real code. This is presented just as informational content. The easiest way to write a C++ Program without Semicolons is using if statements. Almost all ... Read More

Advertisements