Syed Javed has Published 46 Answers

Advantages of naming conventions in Java

Syed Javed

Syed Javed

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

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

Back references in Java regular expressions

Syed Javed

Syed Javed

Updated on 06-Mar-2020 05:11:48

Capturing groups are a way to treat multiple characters as a single unit. They are created by placing the characters to be grouped inside a set of parentheses. For example, the regular expression (dog) creates a single group containing the letters "d", "o", and "g".Capturing groups are numbered by counting ... Read More

Regex metacharacters in Java Regex

Syed Javed

Syed Javed

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

Metacharacters are characters which are having special meanings in Java regular expression.Following metacharacters are suppored in Java Regular expressions.( ) [ ] { { \ ^ $ | ? * + .

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

Syed Javed

Syed Javed

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

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 add two matrices.

Syed Javed

Syed Javed

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

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

Java program to subtract two matrices.

Syed Javed

Syed Javed

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

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

Java program to print odd and even number from a Java array.

Syed Javed

Syed Javed

Updated on 05-Mar-2020 12:34:02

Following is the required program.ExampleLive Demopublic class Tester {    public static void main(String args[]) {       int a[] = { 11, 22, 55, 66, 31, 24 };       System.out.println("Odd Numbers:");       for (int i = 0; i < a.length; i++) {     ... Read More

Can we override the static method in Java?

Syed Javed

Syed Javed

Updated on 05-Mar-2020 12:32:17

Yes! We can override the static method easily in Java. See the example below.ExampleLive Demopublic class Tester {    public static void main(String[] args) {       display();       display("World!!");    }      private static void display(){       System.out.println("Hello!");    }      private ... Read More

Java default constructor

Syed Javed

Syed Javed

Updated on 05-Mar-2020 12:25:42

Yes! it is supported. A constructor with no arguments is called default constructor. It is used to initialize an object with default values.  exampleLive Demopublic class Tester {      private String message;      public Tester(){       message = "Hello World!";    }      public String getMessage(){ ... Read More

Java copy constructor

Syed Javed

Syed Javed

Updated on 05-Mar-2020 12:22:03

Java has no explicit copy constructor but we can mimic the behaviour. See the following example −ExampleLive Demopublic class Tester {      private String message;      public Tester(String message){       this.message = message;    }    public Tester(Tester tester){       this.message = tester.message;   ... Read More

Advertisements