Sample Questions Best site for GRE, LSAT, SAT, GMAT, TOEFL, CCNA, CCSA and interview sample questions  

Technical Sample Questions : C |  C++ |  Oracle |  Java | Unix |  Operating Systems |  Data Structure

Java Sample Questions ›› Java questions

Technical General Java Sample Questions

  1. What is aggregation?

    Answer: It is a special type of composition.If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation.

  2. Can you instantiate the Math class?

    Answer: You cant instantiate the math class.All the methods in this class are static.And the constructor is not public.

  3. What is singleton?

    Answer: It is one of the design pattern.This falls in the creational pattern of the design pattern.There will be only one instance for that entire JVM.You can achieve this by having the private constructor in the class.For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton getInstance() { return s; } // all non static methods }

  4. What is DriverManager?

    Answer: The basic service to manage set of JDBC drivers.

  5. Suppose that temperature measurements were made on each day of 1999 in each of 100 cities.The measurements have been stored in an array

    int[][]temps=newint[100][365];

    where temps[c][d] holds the measurement for city number c on the dth day of the year.Write a code segment that will print out the average temperature, over the course of the whole year, for each city.The average temperature for a city can be obtained by adding up all 365 measurements for that city and dividing the answer by 365.0.

    Answer: A pseudocode outline of the answer is

    For each city {
    Add up all the temperatures for that city
    Divide the total by 365 and print the answer
    }
    Adding up all the temperatures for a given city itself requires a for loop, so the code segment looks like this:

    for (int city = 0; city < 100; city++) {
    int total = 0;
    for (int day = 0; day < 365; day++)
    total = total + temps[city][day];
    double avg = total / 365.0;
    System.out.println("Average temp for city number " + city + " is " + avg);
    }

  6. Suppose that a class, Employee, is defined as follows: class Employee {
    String lastName;
    String firstName;
    double hourlyWage;
    int yearsWithCompany;
    }
    Suppose that data about 100 employees is already stored in an array:

    Employee[] employeeData = new
    Employee[100];
    Write a code segment that will output the first name, last name, and hourly wage of each employee who has been with the company for 20 years or more.

    Answer: The code segment is as follows:

    for (int i=0; i < 100; i++) {
    if ( employeeData[i].yearsWithCompany >= 20 )
    System.out.println(employeeData[i].firstName + " " + employeeData[i].lastName + ": " + employeeData[i].hourlyWage);
    }

  7. Suppose that A has been declared and initialized with the statement

    double[] A = new double[20];

    And suppose that A has already been filled with 20 values.Write a program segment that will find the average of all the non-zero numbers in the array.(The average is the sum of the numbers, divided by the number of numbers.Note that you will have to count the number of non-zero entries in the array.) Declare any variables that you use.

    Answer: int nonzeroCt = 0;
    double total = 0;
    double average;
    for (int i = 0; i < 20; i++) {
    if (A[i] != 0) {
    total += A[i];
    nonzeroCt++;
    }
    }
    if (nonzeroCt > 0)
    average = total / nonzeroCt;
    else
    average = 0;

  8. What does it mean to say that a program is robust?

    Answer: A robust program is one that can handle errors and other unexpected conditions in some reasonable way.This means that the program must anticipate possible errors and respond to them if they occur.

  9. Why do programming languages require that variables be declared before they are used? What does this have to do with correctness and robustness?

    Answer: It's a little inconvenient to have to declare every variable before it is used, but its much safer.If the compiler would accept undeclared variables, then it would also accept misspelled names and treat them as valid variables.This can easily lead to incorrect programs.When variables must be declared, the unintentional creation of a variable is simply impossible, and a whole class of possible bugs is avoided.

  10. What is "Double.NaN"?

    Answer: Double.NaN is a special value of type double.(It is defined as a public static member variable of the standard class, Double.) It is used to represent the result of an undefined operation on real numbers.For example, if you divide a number of type double by zero, the result will be Double.NaN.

« Previous || Next »

Java Sample Question Number: 1-10| 11-20| 21-30| 31-40| 41-50| 51-60| 61-70| 71-80| 81-90| 91-100| 101-110| 111-120| 121-130| 131-140| 141-150| 151-160| 161-170| 171-180| 181-190| 191-200| 201-210| 211-220| 221-230| 231-240| 241-250| 251-260| 261-270| 271-280| 281-290| 291-300| 301-310| 311-320| 321-330
Sample Test Questions
GRE Sample Questions
CAT Sample Questions
GMAT Sample Questions
TOEFL Sample Questions
ACT Sample Questions
SAT Sample Questions
LSAT Sample Questions
PSAT Sample Questions
MCAT Sample Questions
PMP Sample Questions
GED Sample Questions
ECDL Sample Questions
DMV Sample Questions
CCNA Sample Questions
MCSE Sample Questions
Network+ Sample Questions
A+ Sample Questions
Technical Sample Questions
WASL Sample Questions
CISA Sample Questions

Other Sample Questions
Sample Interview Questions
Sample Teacher Interview Questions
Sample Citizenship Questions
Accuplacer Sample Questions
Science Bowl sample Questions
Driving Test Sample Questions
Sample Survey Questions Sample Essay Questions
Sample Behavioral Interview Questions

Copyright © 2004-2013, Best BSQ. All Rights Reserved.