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

What standard of casing used in Java?
- 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

What are the identifiers in Java?

What are some valid identifiers in Java?

How is JavaDoc comments used?
- 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; } ~~~
What are the different types of Primitive data types in Java?
// 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; }

Explain boolean data type in java with an example:

Explain Character data type in java with example.

Explain the Integer data type in Java with an example.

Some primitive literal rules.

Some more primitive literal rules

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

What is Casting in Java?
- 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); ~~~ ~~~
What are the BigInteger and BigDecimal classes in Java? Explain
- 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 are arithmetics performed on BigInteger and BigDecimal in Java?

Why are the BigInteger and BigDecimal classes needed in Java?

Which Java package have BigInteger and BigDecmal classes?
java.math package