Showing posts with label Interview Question. Show all posts
Showing posts with label Interview Question. Show all posts

List of Contents





Ruby and Ruby on Rails interview questions



Hello friends in this post I will daily add one new interview question related to Ruby or Ruby on Rails so please bookmarked this post because here you will find all the possible interview questions related to Ruby and Ruby on Rails.

Que 1- What is the difference in == and === in Ruby?
Ans: == is used to compare the equality of two object.
Example a = 5, b = 6
puts a == b //output false
puts a == 5 //output true

In other hand === is used to check if given number or character is included in particular range.
Example nums = 1..50
puts nums === 25 //output true
puts nums === 66 //output false

Qus 2- Difference in form.select and select_tag in rails ?
Ans- Here is the syntax of form.select

<%= form.select :topic_id, options_from_collection_for_select(Topic.all, 'id', 'title', @blog.topic_id),{}, {class: "form-control"} %>

Here is the syntax of select_tag

<%= select_tag "blog[topic_id]", options_from_collection_for_select(Topic.all, "id", "title", @blog.topic_id), {class: "form-control"} %>







Java Programs for Practice



Number Based Logical Programs

1. Java program to find perfect numbers


2. Java program to print perfect numbers from 1 to 1000

3. Java program to split number into digits.

4. Java program to swap two array.

5. Java program to find NCR factor of given number.

6. Java program to find generic root.

7. Add two number without using addition operator.

8. Java program to sum digits of a number.

9. Java program to reverse a number.

Number System and Conversion 

1. Java program for multiplication of two binary numbers.

2. Java program for addition of two binary numbers.

3. Java program for binary to hexadecimal conversion.

4. Java program for binary to decimal conversion.

5. Java program for octal to binary conversion.

6. Java program for octal to decimal.

7. Java program to convert decimal to binary number.

8. Java program to convert decimal to octal number.

9. Java program to convert decimal to hexadecimal number.

Series Based Programs

1. Java program to find out the sum of A.P. series.

2. Java program to calculate the sum of GP series.

3. Java program to find out the sum of given H.P. Series.

4. Print Sum of series 1+ (1+2) + (1+2+3).... (1+2+3+....n)

5. Print Sum of Series (1/1^2) + (1/2^2) + (1/3^2)....1/n^2

6. Print sum of series (1/1^3) – (1/2^3) + (1/3^3)....1/n^3

7. Print Series 1, 11, 111, 1111....n terms in Java.

8. Print Series 1, 12, 123, 1234.....n in Java.

9. Print Series 1, -3, 5, -7.....n terms in Java.

10. Print Series 2, -4, 6, -8....n terms in Java

11. Java program to print Tribonacci Series.

12. Java program to print fibonacci series.

String Based Programs

1. Program to find the frequency of one string in another.

2. Java program to remove vowels from a string.

3. Program to remove common characters from two strings.

4. Program to finding Shortest and Longest Words in a String.

5. Java program to reverse a String without using direct method.

6. Java program to input name, middle name and surname of a person and print only the initials.

7. Program to remove duplicates characters from given String.

8. Java program to count the occurrence of any character in given String.

9. Java program to find palindromic substring in a string.

10. Java program to accept a string and print each character of the string along with its ASCII code.

Common Logical Programs

1. Java program to find whether given no. is Armstrong or not.

2. Generate prime numbers between 1 & given number

3. Calculate Factorial of a number using recursion

4. Java program to check Palindrome Number.

5. Java program to calculate the Simple Interest.

6. Java program to show all function of bank and generate account number dyanamically.

7. Java program to find out the HCF and LCF.

8. Java program to test the Prime number.

9. Java program to Demonstrate Type Casting.

10. Find the average, sum, min and max of the N numbers Using user Input in Java.

Servlet Based Programs

1. Write a servlet which accepts client request and display the client requested data on the browser?

2. Write a servlet which accepts product details from html form and stores the product details into database?

3. Develop a flexible servlet that should display the data of the database irrespective driver name, table name and dsn name?

4. Write a servlet which retrieves the data from database?

5. Write a servlet which illustrate the concept of ServletContext?

6. Write a servlet which displays current system date and time?

7. Write a servlet which displays a message “I LOVE MY MOM”?

8. Write a servlet which retrieves the data from database?

JDBC Based Programs

1. Write a java program to create a table through frontend application?

2. Write a java program which illustrates the concept of Batch processing?

3. Write a java program which illustrates the concept of updatable ResultSet?

4. Write a java program which illustrates the concept of scrollable ResultSet?

5. Write a java program which points the data of a table along with its column names?

6. Write a java program which illustrates the concept of resource bundle file or how to develop a flexible jdbc application along with its metadata?

7. Write a java program which illustrates the concept of DatabaseMetaData and ResultSetMetaData?

8. Write a jdbc program to retrieve the data from excel?

9. Write a java program which illustrates the concept of procedure?

10. Write a java program which illustrates the concept of function?

11. Write a java program to retrieve the records from a specified database by accepting input from keyboard?

12. Write a java program to insert a record in dept database by accepting the data from keyboard at runtime using dynamic queries?

13. Write a java program to retrieve the data from emp database?

14. Write a jdbc program which will insert a record in the Student database?

Reflection Based Programs

1. Write a java program which will de-Serializable from the specified file?

2. Write a java program which will save the Serializable sub class object into a file?

3. Write a java program to print fields or data members of a class?

4. Write a java program to obtain constructors of a class?

5. Write a java program to obtain information about methods which are present in a class?

6. Write a java program to print super class hierarchy at a current class which is passed from command prompt?

7. Write a java program to find name of the class and its super class name by passing the class name at runtime?

8. Write a java program to print name of the current class and its super class name?

Logical Programs

1. How can you determine if String has all Unique Characters.?

2. How to reverse a String without using any direct method.?

3 How to convert String to integer without using any direct method in Java.?

4. How to find the missing values from an sorted array.?

5. How to reverse an array without using any built in method and any other array.?

6. How to remove specific character from an String in Java.?

7. How to find the caller of a method in Java.?

8. How to call private method from another class in java.?

Matrix Based Program

1. Addition , Substraction and trace of two Matrix in Java.

2. Find the Transpose of given Matrix in Java.

3. Program for Matrix multiplication in Java.

4. Calculate the Sum of the Elements of each Row & Column of given Matrix in Java.

5. Check if a given Matrix is an Identity (Unit) Matrix or not in Java

6. Find the Frequency of Odd & Even Numbers in the given Matrix in Java

7. Determine if a given Matrix is a Sparse Matrix in Java.

Pyramid Based Programs

1. Write a program to generate a following #'s triangle:



2. Write a program to generate a following @'s triangle:



3. Write a Java program to print the following triangle:




4. Write a Java program to display the following rhombus symbol structure:



5. Write a Java program to display the following number rhombus structure:



6. Write a Java program to print the following number pyramid:





7. Write a Java program to display the following character rhombus structure:



Star pyramid program in java



Star pyramid program in java


Star pyramid program in java


import java.util.Scanner;
public class StarPyramid
{
 public static void main(String[] args) {
  int num;
  Scanner sc = new Scanner(System.in);
  System.out.print("Enter number of row : ");
  num = sc.nextInt();
  for (int r = 1; r <= num; r++) {
   for (int sp = (num - r); sp >= 1; sp--) {
    System.out.print(" ");
   }
   for (int c = 1; c <= (r * 2) - 1; c++) {
    System.out.print("*");
   }
   System.out.println();
  }
 }
}

Output:

Enter number of row : 5

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


BUILD SUCCESSFUL (total time: 2 seconds)


Note: Hello friends, If you have any better solution for this programs then please comment below, I will add your comment as a solution for this programs.

Thanks for visiting my blog.



Character triangle program in Java



Character triangle program in Java


Character triangle program in Java


import java.util.Scanner;
public class CharacterTriangle
{
 public static void main(String[] args) {
  char ch;
  Scanner sc = new Scanner(System.in);
  System.out.print("Enter pyramid character : ");
  ch = sc.next().charAt(0);
  if (ch >= 'a' && ch <= 'z') {
   ch = (char)(ch - 32);
  }
  for (char r = 'A'; r <= ch; r++) {
   for (int sp = r; sp > 'A'; sp--) {
    System.out.print(" ");
   }
   for (char c = r; c <= ch; c++) {
    System.out.print(c);
   }
   for (char c = (char)(ch - 1); r <= c; c--) {
    System.out.print(c);
   }
   System.out.println();
  }
 }
}

Output:

Enter pyramid character : e

ABCDEDCBA
  BCDEDCB
    CDEDC
      DED
        E


BUILD SUCCESSFUL (total time: 2 seconds)


Note: Hello friends, If you have any better solution for this programs then please comment below, I will add your comment as a solution for this programs.

Thanks for visiting my blog.


Reverse number triangle program in Java



Reverse number triangle program in Java


Reverse number triangle program


import java.util.Scanner;
public class NumberTriangle
{
 public static void main(String[] args) {
  int num;
  Scanner sc = new Scanner(System.in);
  System.out.print("Enter number of rows : ");
  num = sc.nextInt();
  for (int r = 1; r <= num; r++) {
   for (int sp = r; sp > 1; sp--) {
    System.out.print(" ");
   }
   for (int c = r; c <= num; c++) {
    System.out.print(c);
   }
   for (int c = (num - 1); c >= r; c--) {
    System.out.print(c);
   }
   System.out.println();
  }
 }
}

Output:

Enter number of rows : 5

123454321
  2345432
    34543
      454
        5


BUILD SUCCESSFUL (total time: 2 seconds)


Note: Hello friends, If you have any better solution for this programs then please comment below, I will add your comment as a solution for this programs.

Thanks for visiting my blog.


Half number pyramid program in Java



Write Half number pyramid program in Java


Half number pyramid program


import java.util.Scanner;
public class HalfNumberPyramid
{
 public static void main(String[] args) {
  int num;
  Scanner sc = new Scanner(System.in);
  System.out.print("Enter number of rows : ");
  num = sc.nextInt();
  for (int r = num; r >= 0; r--) {
   for (int sp = num - r; sp >= 1; sp--) {
    System.out.print(" ");
   }
   for (int c = r; c >= 1; c--) {
    System.out.print(c);
   }
   System.out.println();
  }
 }
}

Output:

Enter number of rows : 5

54321
  4321
    321
      21
        1
     

BUILD SUCCESSFUL (total time: 2 seconds)


Note: Hello friends, If you have any better solution for this programs then please comment below, I will add your comment as a solution for this programs.

Thanks for visiting my blog.


Number pyramid program in Java



Number pyramid program in Java


Number Pyramid Program


import java.util.Scanner;
public class NumberPyramid 
{
 public static void main(String[] args) {
  int num;
  Scanner sc = new Scanner(System.in);
  System.out.print("Enter number of rows : ");
  num = sc.nextInt();
  for (int r = 1; r <= num; r++) {
   for (int sp = num - r; sp >= 1; sp--) {
    System.out.print(" ");
   }
   for (int c = 1; c <= r; c++) {
    System.out.print(" " + r);
   }
   System.out.println();
  }
 }
}

Output:

Enter number of rows : 5

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


BUILD SUCCESSFUL (total time: 2 seconds)


Note: Hello friends, If you have any better solution for this programs then please comment below, I will add your comment as a solution for this programs.

Thanks for visiting my blog.


Number pyramid program in Java



import java.util.Scanner;
public class NumberPyramid
{
 public static void main(String[] args) {
  int num;
  Scanner sc = new Scanner(System.in);
  System.out.print("Enter number of rows : ");
  num = sc.nextInt();
  for (int r = 1; r <= num; r++) {
   for (int sp = num - r; sp >= 1; sp--) {
    System.out.print(" ");
   }
   for (int c = 1; c <= r; c++) {
    System.out.print(" " + c);
   }
   System.out.println();
  }
 }
}

Output:

Enter number of rows : 6

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


BUILD SUCCESSFUL (total time: 2 seconds)


Note: Hello friends, If you have any better solution for this programs then please comment below, I will add your comment as a solution for this programs.

Thanks for visiting my blog.


Star rhombus pattern program in Java



import java.util.Scanner;
public class StarRhombus
{
 public static void main(String[] args) 
 {
  int num;
  Scanner sc = new Scanner(System.in);
  System.out.print("Enter number of rows : ");
  num = sc.nextInt();
  for (int r = 1; r <= num; r++) {
   for (int sp = num - r; sp >= 1; sp--) {
    System.out.print(" ");
   }
   for (int c = 1; c <= (2 * (r - 1)) + 1; c++) {
    System.out.print("*");
   }
   System.out.println();
  }
  for (int r = 1; r <= num; r++) {
   for (int sp = r; sp >= 1; sp--) {
    System.out.print(" ");
   }
   for (int c = 1; c <= (num - r) * 2 - 1; c++) {
    System.out.print("*");
   }
   System.out.println();
  }
 }
}

Output:

Enter number of rows : 5

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

BUILD SUCCESSFUL (total time: 2 seconds)



Note: Hello friends, If you have any better solution for this programs then please comment below, I will add your comment as a solution for this programs.

Thanks for visiting my blog.


Reverse number rhombus pattern program in Java



import java.util.Scanner;
public class ReverseRhombus
{
 public static void main(String[] args) 
 {
  int num;
  Scanner sc = new Scanner(System.in);
  System.out.print("Enter number of rows : ");
  num = sc.nextInt();
  for (int r = 1; r <= num; r++) {
   for (int sp = num - r; sp >= 1; sp--) {
    System.out.print(" ");
   }
   for (int c = r; c >= 1; c--) {
    System.out.print(c);
   }
   for (int c = 2; c <= r; c++) {
    System.out.print(c);
   }
   System.out.println();
  }
  for (int r = 1; r <= num; r++) {
   for (int sp = r; sp >= 1; sp--) {
    System.out.print(" ");
   }
   for (int c = num - r; c >= 1; c--) {
    System.out.print(c);
   }
   for (int c = 2; c <= num - r; c++) {
    System.out.print(c);
   }
   System.out.println();
  }
 }
}

Output:


Enter number of rows : 5


        1

      212
    32123
  4321234
543212345
  4321234
    32123
      212
        1
     

BUILD SUCCESSFUL (total time: 3 seconds)



Note: Hello friends, If you have any better solution for this programs then please comment below, I will add your comment as a solution for this programs.

Thanks for visiting my blog.



Number rhombus pattern program in Java



import java.util.Scanner;
public class NumberRhombus
{
 public static void main(String[] args) {
  int num;
  Scanner sc = new Scanner(System.in);
  System.out.print("Enter number of rows : ");
  num = sc.nextInt();
  for (int r = 1; r <= num; r++) {
   for (int sp = num - r; sp >= 1; sp--) {
    System.out.print(" ");
   }
   for (int c = 1; c <= r; c++) {
    System.out.print(c);
   }
   for (int c = r - 1; c >= 1; c--) {
    System.out.print(c);
   }
   System.out.println();
  }
  for (int r = 1; r <= num; r++) {
   for (int sp = r; sp >= 1; sp--) {
    System.out.print(" ");
   }
   for (int c = 1; c <= num - r; c++) {
    System.out.print(c);
   }
   for (int c = num - r - 1; c >= 1; c--) {
    System.out.print(c);
   }
   System.out.println();
  }
 }
}

Output:

Enter number of rows : 5
        1
      121
    12321
  1234321
123454321
  1234321
    12321
      121
        1
     

BUILD SUCCESSFUL (total time: 2 seconds)



Character rhombus shape program in Java



import java.util.Scanner;
public class CharacterRhombus
{
 public static void main(String[] args) {
  char ch;
  System.out.print("Enter any character : ");
  Scanner sc = new Scanner(System.in);
  ch = sc.next().charAt(0);
  if (ch >= 'a' && ch <= 'z') {
   ch = (char)(ch - 32);
  }
  System.out.println();
  for (char r = 'A'; r <= ch; r++) {
   for (int sp = ch - r; sp >= 1; sp--) {
    System.out.print(" ");
   }
   for (char c = 'A'; c <= r; c++) {
    System.out.print(c);
   }
   for (char c = (char)(r - 1); c >= 'A'; c--) {
    System.out.print(c);
   }
   System.out.println();
  }
  for (char r = 'A';
   'A' <= ch; ch--, r++) {
   for (int sp = r; sp >= 'A'; sp--) {
    System.out.print(" ");
   }
   for (char c = 'A'; c <= ch - 1; c++) {
    System.out.print(c);
   }
   for (char c = (char)(ch - 2); c >= 'A'; c--) {
    System.out.print(c);
   }
   System.out.println();
  }
 }
}

Output:

Enter any character : e

        A
      ABA
    ABCBA
  ABCDCBA
ABCDEDCBA
  ABCDCBA
    ABCBA
      ABA
        A
     

BUILD SUCCESSFUL (total time: 6 seconds)


Note: Hello friends, If you have any better solution for this programs then please comment below, I will add your comment as a solution for this programs.

Thanks for visiting my blog.