Java_Conventions_Primitives Flashcards

1
Q

Is Java case sensitive? Does Class names can all be lowercase?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What standard of casing used in Java?

A
  • Variables and methods use lower camel casing.​
int dog;
    int myDog; 
    void run(){ } 
    void sitThere() { }
  • Package names are conventionally in all lowercase.
package com.src.javapractice
package org.apache.maven.reactor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the identifiers in Java?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are some valid identifiers in Java?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How is JavaDoc comments used?

A
  • Javadoc is a tool that creates documentation for the classes that are implemented in applications.
  • Example:
/**
 * This is a Javadoc comment example
 * @author Keerthi Dadige
 */
public class Car {
    //Initialization block
    {
        color = "Red";
    }
    //static initialization block
    static {
        //color = "Yellow"; // Illegal as non-static variable
        //printDescription(); // Illegal as non-static method
        setCarCount(3);
    }
    String color;
    String type;
    int serialNumber;
    //Static Variable declaration
    static int carCount;
// Constructors
// User defined default constructor
// Compiler will not create a default constructor in this case
Car() {
    carCount++; // Static variable increment
    serialNumber = carCount;
    color = "Blue";
} ~~~

/**
 * User defined Car constructor
 * @param color
 * @param type
 */
Car(String color, String type){
    this();
    this.color = color;
    this.type = type;
} ~~~
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the different types of Primitive data types in Java?

A
// Example below are 8 primitive data types in Java 
public class PrimitiveDataTypes {
    byte b;
    short s;
    int i;
    long l;
    char ch;
    float f;
    double d;
    boolean bool;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain boolean data type in java with an example:

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain Character data type in java with example.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain the Integer data type in Java with an example.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Some primitive literal rules.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Some more primitive literal rules

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How are underscores used in numeric literals, give an example?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is Casting in Java?

A
  • There are two types of conversions in java:
  • Narrowing conversion
  • Widening conversion
/**
         * Casting
         */
        int x2 = 200;
        // Narrowing conversion. As byte is smaller size than int
        // it cannot handle size greater than its primitive size.
        // Below is an example of casting with int to (byte) type

        byte b2 = (byte) x2;
        System.out.println("byte value: " + b2);// Prints invalid value
    int xInt = 200;
    // Widening conversion from smaller primitive to Larger.
    long xLong = xInt; // works without any need of explicit Casting
    System.out.println("Long value: " + xLong); ~~~ ~~~
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the BigInteger and BigDecimal classes in Java? Explain

A
  • There may be cases where we need to work with an Integer or decimal number that is larger or smaller than it can be handled using primitives long or double.
  • Java provides BigInteger and BigDecimal classes to handle cases as above.
  • Please refer below notes for more details:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How are arithmetics performed on BigInteger and BigDecimal in Java?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why are the BigInteger and BigDecimal classes needed in Java?

A
17
Q

Which Java package have BigInteger and BigDecmal classes?

A

java.math package