Showing posts with label java theory. Show all posts
Showing posts with label java theory. Show all posts

Tuesday, 31 October 2017

java important question



                    Question 08:
What is the result of 25 / 4? How would you rewrite the expression if you wished the result to be a floating-point number?

Ans:
          The result is 6
        If write 25 .0/ 4 then result in floating point =6.25

java important theory problems



Question 06:
                 Find the largest and smallest byte, short, int, long, float, and double. Which
of these data types requires the least amount of memory?
Ans:
The largest is double.
The smallest is byte.
The hierarchy is:  byte, short,
Question 07:
 Show the result of the following remainders.
56 % 6
78 % -4
-34 % 5
-34 % -5
5 % 1
1 % 5
Ans
56 % 6 = 2
78 % -4 = -2
-34 % 5 = -4
-34 % -5 = -4
5 % 1      =0
1 % 5        =1

java important theory problems



Question 03:
Which of the following identifiers are valid? Which are Java keywords?
miles, Test, a++, ––a, 4#R, $4, #44, apps
class, public, int, x, y, radius
Ans:
      The valid identifier are miles, Test, $4, apps, x, y, radius.
    Java keywords are int class public.
Question 04:
Identify and fix the errors in the following code:
 public class Test {
 public static void main(String[] args) {
 int i = k + 2;
 System.out.println(i);
 }
 }
Ans:
      A variable must be declared before it use variable k is not declared
Error in int i=k+2;   k is not declared.
Question 05:
 What are the benefits of using constants? Declare an int constant SIZE with value 20.
Ans:
 01 It is used for multiple times I  the program
02  Its value can be changed at single location
03 It make easy to understand the program

java theory problems



Question 01
  Identify and fix the errors in the following code:
 public class Test {
 public void main(string[] args) {
 double i = 50.0;
 double k = i + 50.0;
 double j = k + 1;
 System.out.println("j is " + j + " and
 k is " + k);
 }
}
Ans  Errors
01 String letter must be capital.
02 In main function there is an error no write static class
02  The output statement must be written as when write in two lines System.out.println("j is " + j + " and"
         + " k is " + k);
Question 02
Are there any performance differences between the following two import statements?
import java.util.Scanner;
import java.util.*;
Ans:
 Scanner is the class of java.util package.import java.util.Scanner is used for specific class.
But import java.util.*; is used to access all the classes of java.util package.