mcharugundla
10/17/2017 - 11:54 AM

JAVA commands


byte - 8 bits
short - 16 bits
int - 32 bits
long - 64bits
float - 32 bits
double - 64bits
If we want to find the negative value of a signed number then, we should first 
take the signed positive number and have to do the 2's complement to get the negative number.

Type casting:3 types
Implicit casting
Explicit casting

Implicit : If we want to store a byte number which is (8 bits) in to an int number, 
the JVM automatically expands the width to 32 bits.
eg: byte x = 2; // 8 bits
  int y = x; // 32 bits

Explicit: If we ant to store the int number in to a smaller size byte or short, 
then we have to explicitly mention that. JVM will not convert automatically.
eg: int x = 6; 32 bits
  byte y = (byte) 6; 8 bits
  when we do this, we may expect differnt answers based on the number of bits, signed and unsigned.
Public - It can be accessible across instances(objects). The value can be modified.
Private - It can be accessible across instance(objects) but the value cannot be modified.
These can be accessed by only methods.
Final - this keyword tells you that value can be assigned only once.
Static - This keyword let us know that this variable is a class level variable 
and can be accessed even without an instance.
CONSTANT - If we cant to create any contansts you should be represent variable in 
all UPPERCASE letters and words seperated by underscore.

Access level modifiers:
Top level - public or package-private
At member level - Public, private, protected,or package-private

Public - it is an access modifier which tell us when specified infront of class 
or the member that it can be accessed anywhere meaning inside the class, 
outside of the class(package), or inside of a subclass of another package, or anywhere in the world.

Private: it is an access modifier which when specified lets us know that the member
can be accessed with in the own class.

Protected- the member can be accessed with in its own class, with in the package
and subclass of another package.

package-private : if no modifier is specified then it is called package-private modifier 
and can be accessed with in its own class, and in the package that class is present.

Constructor : is a method that will run when you instantiate class.Again instantiation happens 
when you create the new instance of the class using new keyword.
A constructor is a great place to stick required information about initial set 
up of the object.

Abstraction: is aprocess of hiding the unnecessary deatils/implementation details 
from the consumers/customers and showing them what they need.
In other words,it tells us what the object does and hides how it does.

Overloading: Multiple methods with same name but different paramater list is called overloading.
Old way :
      for(initialization; termination; increment)

New Way: for each
    for (Element e : elements) {
    doSomething(e);
}
// -> Single comments
/* --- */ Multiple comments
console.printf -- for writing output (package java.io, module - console)
console.readLine -> for reading input(package java.io, module - console)
primitive data types uses double equals
string objects uses equals method
string object refernces uses double equals.




String a; ---> a is of type string
String[] a; a is of type array