Bitsmore360 - Top trends, Tech News, Tips and Tricks

How-to

Recent Post

Top 100+ java coding interview questions and answers

In this article, "Top 100+ Java Coding Interview Questions and Answers," we will see some of the most common questions asked by teachers and interviewers.


Top 100+ java coding interview questions and answers

Top 100+ java coding interview questions and answers






Top 100+ java coding interview questions and answers - Short Answer Question

Java Ques 1: Who is known as father of Java? [Solution Below]
Java Ques 2: Latest version of Java [Solution Below]
Java Ques 3:What is the original name of Java Programming language? [Solution Below]
Java Ques 4: Which component is used to compile execute the java programs? [Solution Below]
Java Ques 5: What is the extension of java program files? [Solution Below]
Java Ques 6: What is the size of float and double in java? [Solution Below]
Java Ques 7: What are Data Types in Java? [Solution Below]
Java Ques 8: What is the meaning of polymorphism in Java? [Solution Below]
Java Ques 9: Which one of the following is not a Java feature? [Solution Below]
1) Object-oriented
2) Use of pointers
3) Dynamic and Extensible
4) Portable

Java Ques 10: Where Java was invented? [Solution Below]
Java Ques 11: What is Immutable object in java? [Solution Below]
Java Ques 12: Write example of immutable class in java [Solution Below]
Java Ques 13: What is Casting in Java? [Solution Below]
Java Ques 14: What is Inheritence in Java? [Solution Below]
Java Ques 15: What do you understand by an instance variable in Java? [Solution Below]
Java Ques 16: What do you understand by a local variable in java? [Solution Below]
Java Ques 17: What is Data Encapsulation in java? [Solution Below]
Java Ques 18: What is Heap memory in java? [Solution Below]
Java Ques 19: What is Stack Memory in java? [Solution Below]
Java Ques 20: What do you mean by wrapper classes in Java? [Solution Below]




Top 100+ java coding interview questions and answers 

Java Ques 1: Java program that accepts two doubles as its command line arguments, multiple these together and display the product. [Solution Below]
Java Ques 2: Java program that accepts one command line argument; display the line of reporting if number is even or odd. [Solution Below]
Java Ques 3: Java program that accepts radius of a circle as its command line argument display the area. [Solution Below]
Java Ques 4: Java program that describes a class person. It should have instance variables to record name, age and salary. [Solution Below]
Java Ques 5: Java program that can count the number of instances created for the class. [Solution Below]
Java Ques 6: Java program that implements method overloading. [Solution Below]
Java Ques 7: Java program that illustrates method overriding. [Solution Below]
Java Ques 8: Java program that creates a package p1. Add some classes in it. [Solution Below]
Java Ques 9: Java program that shows passing object as parameter. [Solution Below]
Java Ques 10: Java program to show that the value of non static variable is not visible to all the instances, and therefore cannot be used to count the number of instances. [Solution Below]


Top 100+ java coding interview questions and answers - Long Answer Question - Pattern Based Questions

Java Ques 1: Java program to print Pascal's Triangle in Java. [Solution Below]
Java Ques 2:  Java program to print Alphabet Pattern. [Solution Below]
Java Ques 3: Java program to print Alphabet Pattern using While Loop. [Solution Below]
Java Ques 4: Java program to print right angle triangle star pattern. [Solution Below]
Java Ques 5: Java program to print inverted right triangle star pattern. [Solution Below]
Java Ques 6: Java program to print pyramid pattern using star. [Solution Below]
Java Ques 7: Java program to print inverted pyramid pattern using star. [Solution Below]
Java Ques 8: Java program to print pyramid pattern using star. [Solution Below]

            *
           **
          ***
         ****
        *****
       ******


Java Ques 9: Java program to print inverted pyramid pattern using star. [Solution Below]

***********
  *********
   *******
    *****
     ***
      *

Java Ques 10: Java program to print the following pattern- [Solution Below]

1
1 0
1 0 1
1 0 1 0
1 0 1 0 1

Java Ques 11: Java program to print the following pattern- [Solution Below]

1   2   3   4
5   6   7   8
9  10 11   12

Java Ques 12: Java program to print the following pattern- [Solution Below]

101010
010101
101010
010101
101010

Java Ques 13: Java program to print the following pattern [Solution Below]

1 2 3 4 5 
6 7 8 9 
10 11 12 
13 14 
15

Java Ques 14: Java program to print the following pattern [Solution Below]

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Java Ques 15: Java program to print the following pattern [Solution Below]

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Java Ques 16: Java program to print the following pattern [Solution Below]

5 4 3 2 1
4 3 2 1
3 2 1
2 1
1

Java Ques 1: Java program to print the following pattern [Solution Below]

1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5



Top 100+ java coding interview questions and answers - Short Answer Question


Java coding interview questions and answers
Q1. Who is known as father of Java?
A.1 James Gosling
Q2. Latest version of Java
A.2 Java 19
Q3. What is the original name of Java Programming language?
A.3 OAK
Q4. Which component is used to compile execute the java programs?
A.4 JDK provides all the components required to compile and execute a Java Program.
Q5. What is the extension of java program files?
A.5 .java extension
Q6. What is the size of float and double in java?
A.6 Float = 32 and double = 64
Q7. What are Data Types in Java?
A.7 A data type is a classification of data. A data type tells the compiler about the kind of value a variable is going to store.
Q8. What is the meaning of polymorphism in Java?
A.8 The word polymorphism is a combination of two greek words "poly" and "morphism" which means many forms. Polymorphism is a concept by which a single action can be performed in different ways.
Q9. Which one of the following is not a Java feature?
1) Object-oriented
2) Use of pointers
3) Dynamic and Extensible
4) Portable

A.9 2 Use of pointers
Q10. Where Java was invented?
A.10 Sun Microsystems
Q11. What is Immutable object in java?
A.11 Objects which cannot be changed after initialization
Q12. Write example of immutable class in java
A.12 String
Q13. What is Casting in Java?
A.13 It is a process to convert one data type to another.
Q14. What is Inheritence in Java?
A.14 Inheritance is a process in which one object acquires the properties of another object.
Q15. What do you understand by an instance variable in Java?
A.15 Instance variables are the variables which can be accessed by all the methods in the class.
Q16. What do you understand by a local variable in java?
A.16 Local variables are the variables present within a block, function, or constructor. Local Variables can be accessed only within the block.
Q17. What is Data Encapsulation in java?
A.17 Data Encapsulation is a concept of hiding the data attributes and their behaviours in a single unit.
Q18. What is Heap memory in java?
A.18 Heap memory is a memory which will be available for use by the java program only when it is required during the runtime of the program.
Q19. What is Stack Memory in java?
A.19 Stack memory is the portion of memory assigned to every individual program.
Q20. What do you mean by wrapper classes in Java?
A.20 The wrapper class helps to convert primitive into object and object into primitive.


Top 100+ java coding interview questions and answers - Long Answer Question - Pattern Based Questions



Java Ques 1: Java program that accepts two doubles as its command line arguments, multiple these together and display the product. 


class q1d{
public static void main(String ab[])
{
int len=ab.length;
System.out.println("array length is"+len);

if(len==0)
{ 
System.out.print("no command line values passed");
}
else {
double a,b,product;
a=Double.parseDouble(ab[0]);
b=Double.parseDouble(ab[1]);
product=a*b;
System.out.println("product  of a and b is: "+product);
}
}
}


Java Ques 1: Java program that accepts two doubles as its command line arguments, multiple these together and display the product. 

Top 100+ java coding interview questions and answers - Long Answer Question - Pattern Based Questions



Java Ques 1 - Java program to print Pascal's Triangle in Java

                1
            1      1
        1     2       1

    1     3       3      1




public class demopascal
{
public static void main(String[] args)
{
int row=5, i, j, space, number;
for(i=0; i<row; i++)
{
for(space=row; space>i; space--)
{
 System.out.print(" ");
}
number=1;
for(j=0; j<=i; j++)
{
System.out.print(number+ " ");
number = number*(i-j)/(j+1);
}
System.out.print("\n");
}
}
}




Java Ques 2: 
Java program to print the following pattern

123456
  23456
    3456
      456
        56
          6



public class demopattern
{
public static void main(String args[])
{
    
System.out.println("Pattern Program \n");
for(int i = 1; i <= 6; i++)
{
for(int j = 6-i; j < 5; j++)
{
System.out.print(" ");
}
for(int k = i; k <= 6; k++)
{
System.out.print(k);
}
System.out.println();
}
}
}





Java Ques 3: 
Java program to print the following pattern


101010
010101
101010
010101
101010
010101




public class demopattern
{
public static void main(String args[])
{

int n;
System.out.println("pattern program \n");
for(int i = 1; i <= 5; i++)
{

if(i%2 == 0)
{
n = 0;
for(int j = 1; j <= 6; j++)
{
System.out.print(n);
n = (n == 0)? 1 : 0;
}
}
else
{
n = 1;
for(int j = 1; j <= 6; j++)
{
System.out.print(n);
n = (n == 0)? 1 : 0;
}
}
System.out.println();
}
}
}




Java Ques 4:  Java program to print Alphabet Pattern


public class Pattern1demo
{
public static void main(String args[])
{
System.out.println("Alphabet pattern \n");
for(int i = 1; i <10; i++)//for printing 5 rows
{
//create local variable with ASCII value of A i.e 65
int ch = 65;
for(int j = 1; j <= i; j++)
{
System.out.print((char)ch);
//casting of int value to char for printing character
ch++;
}
System.out.println();
}
}
}



Java Ques 5: Java program to print Alphabet Pattern using While Loop


public class Pattern1demo
{
public static void main(String args[])
{
System.out.println("Alphabet pattern \n");
int i = 1;
int j = 1;

while(i<10)
{
j=1;  
int ch = 65;

while(j<=i)
{
System.out.print((char)ch);
//casting of int value to char for printing character
ch++;
j++;
}
System.out.println();
i++;

}
}
}



Java Ques 6: Java program to print right angle triangle star pattern.


public class Demo1{
public static void main(String args[]){
int row=5;
for(int i=0; i<row; i++)
{
for(int j=0; j<=i; j++)
{
System.out.print("* ");
}
System.out.println();
}
}
}



Java Ques 7: Java program to print inverted right triangle star pattern.


public class Demo2{
public static void main(String args[]) {
  
for(int i = 5; i > 0; i--) {
/* Prints one row of triangle */
for(int j = i; j > 0; j--) {
System.out.print("* ");
}
/* move to next row */
System.out.print("\n");
}
}
}





Java Ques 8: Java program to print pyramid pattern using star.

            *
           **
          ***
         ****
        *****
       ******

public class Demo3{
public static void main(String args[])
{
int sp,star=0;
int rows=6;
//outer loop for printing rows
for(int i = 1; i <= rows; i++)
{
// print leading space
for(sp = 1; sp <= rows-i; sp++) {
System.out.print(" ");
}// print star
while(star != (2*i - 1)){
System.out.print("*");
star++;
}
star=0;
// move to next row
System.out.print("\n");
}
}
}




Java Ques 9: Java program to print inverted pyramid pattern using star.

***********
  *********
   *******
    *****
     ***
      *

public class Demo4{
public static void main(String args[]){
int rows=6;
int space, star=0;
for(int i = rows;i >= 1; i--)
{// for leading space
for(space = 0; space <= rows-i; space++)
{
System.out.print(" ");
}
//print pattern
star = 0;
while(star != (2*i - 1))
{
System.out.print("*");
star++;
}
System.out.print("\n");
}
}
}


Java Ques 10: Java program to print the following pattern-

    1
    1 0
    1 0 1
    1 0 1 0
    1 0 1 0 1


public class Demo5
{
public static void main(String args[])
{
for(int i = 1; i <= 7; i++)
{
for(int j = 1; j <= i; j++)
{
if(j%2 == 0){
System.out.print(0);
    
}else{System.out.print(1);}


}
System.out.println();
}
}
}





Java Ques 11: Java program to print the following pattern-

    1   2   3   4
    5   6   7   8
    9  10 11 12


public class Demo6
{
public static void main(String args[])
{
for(int i = 1; i <= 12; i++)
{
for(int j = 1; j <= 4; j++)
{
System.out.print("   "+i);
i++;
}
i--;
System.out.println();
}
}
}





Java Ques 12: Java program to print the following pattern-


101010
010101
101010
010101
101010


public class Demo7
{
public static void main(String args[])
{
for(int i = 1; i <= 5; i++)
{
int n;
if(i%2 == 0)
{
n = 0;
for(int j = 1; j <= 5; j++)
{
System.out.print(n);
n = (n == 0)? 1 : 0;
}
}
else
{
n = 1;
for(int j = 1; j <= 6; j++)
{
System.out.print(n);
n = (n == 0)? 1 : 0;
}
}
 System.out.println();
}
}
}


 

Java Ques 13: Java program to print the following pattern

1 2 3 4 5 
6 7 8 9 
10 11 12 
13 14 
15


public class demopattern
{
public static void main(String args[])
{
int t = 1;
System.out.println("pattern program \n");
for(int i = 5; i >= 1; i--)
{
for(int j = 1; j <= i; j++)
{
System.out.print(t++ + " ");
}
System.out.println();
}
}
}

Output:-
Top 100+ java coding interview questions and answers


Java Ques 14: Java program to print the following pattern

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1


public class demopattern
{
public static void main(String[] args) 
{

int rows = 5;
System.out.println("Pattern Program");
for (int i = 1; i <= rows; i++) 
{
for (int j = 1; j <= i; j++) 
{ 
System.out.print(j+" "); 
} 
 System.out.println(); 
} 
//Printing lower half of the pattern 
         
for (int i = rows-1; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}

Output:-

Top 100+ java coding interview questions and answers


Java Ques 15: Java program to print the following pattern

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5


public class demosxcpattern
{
public static void main(String[] args) 
{

int rows = 5;
System.out.println("Pattern Program");
for (int i = 1; i <= rows; i++) 
{
for (int j = 1; j <= i; j++)
{
System.out.print(i+" ");
}
             
System.out.println();
}
}
}

Output:-

Top 100+ java coding interview questions and answers

Java Ques 16: Java program to print the following pattern

5 4 3 2 1
4 3 2 1
3 2 1
2 1
1


public class demopattern
{
public static void main(String[] args) 
{
int rows = 5;
System.out.println("Pattern Program \n");
         
for (int i = rows; i >= 1; i--) 
{
for (int j = i; j >= 1; j--)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}

Output:-
Top 100+ java coding interview questions and answers


Java Ques 1: Java program to print the following pattern

1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5


public class demop
{
public static void main(String[] args) 
{
int rows = 5;
 System.out.println("Pattern Program \n");
//for upper pattern
         
for (int i = rows; i >= 1; i--) 
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
         
//for lower
         
for (int i = 2; i <= rows; i++) 
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}

Output:-
Top 100+ java coding interview questions and answers






Did you find this article helpful? OR Have any doubt, write in the comment section. To learn more about Bitsmore360, check out the rest of our Blog, and visit our Pinterest site and follow us on Instagram.
Read More »

How to make UPI payment without internet - 2022 guide

In this article, we will learn a simple way to make UPI payment without internet - 2022 guide. Have you ever had such a situation? When you are making a payment to a friend or someone else through mobile UPI, and then the internet connection gets interrupted or your internet speed slows down. Your payment could not be done because of this reason. If yes then this article is for you!


make UPI payment without internet - 2022 guide

How to make UPI payment without internet - 2022 guide


Make UPI payment without internet 

  • Setting up UPI payments is quick and easy.
  • To set up UPI payments, you need a mobile number linked to your bank account. On your smartphone, dial *99#.

make UPI payment without internet - 2022 guide


  • Then choose the language you want and then enter your bank name or first 4 letters of your bank IFSC.

make UPI payment without internet - 2022 guide



  • A list of Bank name will be displayed. Select the bank name.
  • Enter a last 6 digits of your debit card with the expiry date separated by single space.
  • Now you have successfully finished setting up of UPI.


For Payment

  1. On your smartphone or feature phone, dial *99#.
  2. Choose from the option displayed.  Press 1 for mobile number or 3 for UPI Id option.
  3. After Selecting UPI ID option. Enter UPI ID of the person you want to send money.
  4. Then Enter the amount.
  5. Enter UPI Pin to confirm.
  6. And you have successfully made the payment using UPI without internet.

UPI 123PAY: 

It is an instant payment system developed for users who use feature phones. It allows people with a feature phone to securely make UPI payments without the internet. 

Following are the steps to make payment:-

  1. On your feature phone, dial any of the given number:-
  2. 080 4516 3666 / 6366 200 200 / 080 4516 3581.
  1. Choose from the option displayed.  
  2. After Selecting UPI ID option. Enter UPI ID of the person you want to send money.
  3. Then Enter the amount.
  4. Enter UPI Pin to confirm.
  5. And you have successfully made the payment using UPI without internet.

For more information: https://www.npci.org.in/what-we-do/99/product-overview
For more information: https://www.npci.org.in/what-we-do/upi-123pay/product-overview
Did you find this article helpful? OR Have any doubt, write in the comment section. To learn more about Bitsmore360, check out the rest of our Blog, and visit our Pinterest site and follow us on Instagram.

Read More »

Java Ques 101: While Loop in Java with examples

In this article, "Java Ques 101: While Loop in Java with examples" we will learn the basics of while loop in Java. We will also see some of the examples of while loops. The loop executes statements repetitively up to a specified number of times. Earlier we've read about the Java for loop. Later we will also differentiate between for and while loops.



Java Ques 101: While Loop in Java with examples



Java While Loop


The Java While loop is a control statement that allows you to repeat a block of code for a specific number of times until the condition is true. It is also known as an iterative statement. It is used when you don't know in advance the number of times the loop should be run.

Syntax:

while(Condition)
{
//Statement 
increment/decrement expression
}


Flow Chart: A flow chart is a diagrammatic representation of an algorithm. It represents the workflow or process in a sequential manner. Given Below is a flow chart of "While loop".





Example: Write a simple program in java to print Hello using While loop.


1
2
3
4
5
6
7
8
9
public class Demo {  
public static void main(String[] args) {  
int i=1;  
while(i<=5){  
System.out.println("Hello");  
i++;  
}  
}  
}  

Output:-




In First Iteration, the value of i will be 1, it is less than 5 so condition becomes true and will execute inner statement. The command System.out.println("Hello") will print hello and change the line. 

In Second Iteration, the value of i will be 2, it is less than 5 so condition becomes true and will execute inner statement. The command System.out.println("Hello") will print hello and change the line.

In Third Iteration, the value of i will be 3, it is less than 5 so condition becomes true and will execute inner statement. The command System.out.println("Hello") will print hello and change the line.

In Fourth Iteration, the value of i will be 4, it is less than 5 so condition becomes true and will execute inner statement. The command System.out.println("Hello") will print hello and change the line. 

In Fifth Iteration, the value of i will be 5, it is less than 5 so condition becomes true and will execute inner statement. The command System.out.println("Hello") will print hello and change the line. As soon as the condition become falls i.e i becomes greater than 6 loop will stop executing the command.


Difference between For Loop and While Loop:



For Loop While Loop
For Loop is used when number of iteration is known in advance. While Loop is used when number of iteration is not known.
For Loop is entry controlled loop. While Loop is entry controlled loop.
For Loop Syntax:

for(Initialization; Test Expression; Update Expression) { //Statement }
While Loop Syntax:

while(Condition) { //Statement increment/decrement expression }
In For Loop initialization of variable can be done inside or outside of Loop. In While Loop initialization of variable is done outside of Loop



Did you find this article helpful? OR Have any doubt, write in the comment section. To learn more about Bitsmore360, check out the rest of our Blog, and visit our Pinterest site and follow us on Instagram.


Read More »