Java Programming Basics
Java Programming Basics
2. Flexibility An int only allows the An Integer is a wrapper class for int
binary value of an and provides more flexibility in
integer in it, and due comparison to the int.
to which it is provides
less flexibility.
There are no global variables in Java, but there are global classes with public fields. You can
use static import feature of java 5 to make it look almost like global variables.
Example:
5. What is Autoboxing in Java?
6. What is Unboxing in Java?
Autoboxing refers to the conversion of a primitive value into an
object of the corresponding wrapper class is called autoboxing. For
example, converting int to Integer class. The Java compiler applies
autoboxing when a primitive value is:
Passed as a parameter to a method that expects an
object of the corresponding wrapper class.
Assigned to a variable of the corresponding wrapper
class.
Unboxing on the other hand refers to converting an object of a
wrapper type to its corresponding primitive value. For example
conversion of Integer to int. The Java compiler applies to unbox
when an object of a wrapper class is:
Passed as a parameter to a method that expects a
value of the corresponding primitive type.
Assigned to a variable of the corresponding primitive
type.
7. What is Generics in Java?
Generics means parameterized types. The idea is to allow type
(Integer, String, … etc., and user-defined types) to be a parameter
to methods, classes, and interfaces. Using Generics, it is possible to
create classes that work with different data types. An entity such as
class, interface, or method that operates on a parameterized type
is a generic entity.
To create an enum, use the enum keyword (instead of class or interface), and
separate the constants with a comma. Note that they should be in uppercase
letters:
Example
enum Level {
LOW,
MEDIUM,
HIGH
S.
No
. ArrayList Vector
ArrayList is not
1. Vector is synchronized.
synchronized.
ArrayList uses the Iterator A Vector can use the Iterator interface
5. interface to traverse the or Enumeration interface to traverse
elements. the elements.
ArrayList performance is
6 Vector performance is low
high
Multiple threads is
7 only one threads are allowed .
allowed
Base Array ArrayList
It can be single-
It can only be single-
Dimensionality dimensional or
dimensional
multidimensional