2021 Java
2021 Java
Java is a highly readable and user-friendly programming language, especially when compared to
machine languages. It uses a compiler to convert its human-readable source code into
bytecode, which is an intermediate form of code. This bytecode is then executed by the Java
Virtual Machine (JVM), which translates it into machine language specific to the operating
system being used. Since there are different JVM implementations for different operating
systems, the same Java source code can be run on multiple platforms without modification.
This is how Java achieves its platform-independent nature, allowing developers to "write once,
run anywhere.”
b) i) Which of the following statements can use to create objects of above classes in Java. (Mention
the numbers)
(a), (b),(d)
ii) What is the suitable keyword to fill the blank if you can use to call the Parent class constructor?
super()
c) List down the three different variable types in Java and describe each of them using an example.
Boolean can only two different value one is true and other is false.
Byte is the smallest numeric data type that can hold values -128 to 127
Float is used for storing decimal point values with a precision of up to 7 digits and occupies 4 bytes of
memory.
To get comprehensive idea about software artifacts by looking at in many different views.
ii) Choose the correct statements related to parts of class diagrams in below.
2)
iii) Describe the difference between Structural Modelling and Behavioral Modelling providing
examples for each type.
Behavioral Modelling (Activity diagram, state machine diagram, use case diagram)
• It represents the behavior of a system, which describes the functioning of the system.
iv)
Write a java method called sumOfDigits that accepts an integer array as a parameter and returns the
sum of all the values in the array.
Student() {
Student(String name) {
this.name = name;
}
ArithmeticException
ii) Rewrite the above code suggesting a way to handle that exception.
public class Demo {
public static void main(String[] args) {
try {
int a = 20, b = 0;
int c = a / b;
System.out.println("Result = " + c);
} catch (ArithmeticException e) {
e.printStackTrace();
}
}
}
iii) Explain the use of throw and throws keywords in exception handling with examples.
throw and throws both keywords use to counter runtime exceptions throw keyword us in a code block
or inside a method while throws use in method declaration .
public void divide(int a, int b) throws ArithmeticException {
if (b==0){
throw new ArithmeticException("can't divide by zero");
}
System.out.println(a/b);
}
Object Serialization is the process of converting an object in Java into a format (specifically, a byte
stream) that can be easily saved to a file or sent over a network. Later, this byte stream can be
converted back into the original object, a process known as deserialization.
ii) Given below is the equation to find the surface area of a circle.
A=πr2
double area
b. Write a Java program to read the radius (r) value from console input and print the result in
proper manner.
public static final double PI = 3.141;
double radius = 0.0;
public static void areaCalc(double radius) {
radius = 5.0;
double area = PI * radius * radius;
System.out.println("The area of the circle with radius " + radius + " is:
" + area);
}
b) i) Describe the difference between Centralized and Distributed version controlling systems.
CVCS has a single main repository while DVCS can have copy of main repository for everyone
CVCS has limited access to commit history (only for central server) while DVCS has full access to commit
history
CVCS has more complex merging and branching process while DCVS has flexible merging and branching
facilities.