Java Related Question
What is applet?
Ans-> Applet is a small
application especially utility program performing one or a few simple functions.
Java through internet is applet.
Applet life circle
Init->start->paint->stop->destroy.
Difference between java and C++
Ans->Java use compiler and
interpreter both. On the other hand, C++ execute the program using only a compiler.
C++ compiler compile the code into machine language but in java source code
compile to convert bytecode which is an intermediate layer. C++ execute faster
than java. C++ support pointer but java did not support pointer. Sometime pointer
can create memory fault that is why pointer is not included in java programming
language. Java is multithreaded but C++ does not support multithreaded. Java is
environment independent that’s means you don’t need to change your code for
deferent CPU. Java is not multiple inheritance but C++ support multiple inheritance.
Java and C++ both OOPL. Java allocate and deallocate memory automatically.
Source code-> compiler-> machine language (c++)
Source code0->compiler->bytecode->JVM (interpreter)->machine
language (Java)
Java can work with low power.
What is the main goal of java??
The goal of java is writing once, run anywhere, anytime,
forever
The C++ language should strive for simplicity to reduce the
complexity burden on reading, understanding, and writing code. The behavior of
code should be easily understood, especially by those unfamiliar with the
software system
why file name have to be same as class file in java??
Ans-> When we compile java file it create class file with class name. That is why it is a good habit to use same name into file and class.
How to execute java code?
Command:
Javac example.java
// source code to bite code where javac is a compiler
Java example
// bite code to machine code where java is an interpreter
what is whitespace in java??
white space is related with indentation. In java white space means tab, space and newline that's make code look beautiful and understandable.
Identifiers
Identifier means the name of java component that use to identify class, method and variable.
example:
- name_of_class
- name_of_variable
- name_of_method
Literals:
A constant value in Java is created by using a literal representation of it. For example,
here are some literals:
100 98.6 'X' "This is a test"
Left to right, the first literal specifies an integer, the next is a floating-point value, the third
is a character constant, and the last is a string. A literal can be used anywhere a value of
its type is allowed.
- 1-> integer literal 4 byte
- 1.2 -> float literal 4 byte
- 'a'->character literal 2 byte
- "Fardin"->string literal
- true ->boolean 1 byte
Separators
In Java, there are a few characters that are used as separators. The most commonly
used separator in Java is the semicolon. As you have seen, it is used to terminate
statements. The separators are shown in the following table: () {} ; []
How many keyword use in java??
There are 48 keyword use in java. List of 48 keyword in java :
abstract ,const, Finally ,int ,Public, this, boolean ,continue ,Float ,interface, Return ,throw, break,, default, For, long,Short ,throws ,byte ,do, Goto, native, Static, transient, case ,double, If ,new Strictfp ,try,catch ,else, Implements ,package ,Super, void ,char, extends ,Import, private ,Switch, volatile, class, final ,Instanceof ,protected ,Synchronized, while
The keywords const and goto are reserved but not used. In the early days of Java,
several other keywords were reserved for possible future use. However, the current
specification for Java only defines the keywords shown in Table 2-1.
In addition to the keywords, Java reserves the following: true, false, and null. These are
values defined by Java. You may not use these words for the names of variables, classes,
and so on.
Paradigm:
Java is a strongly typed programming language. If you come from a C or C++ background, keep in mind that Java is more strictly
typed than either language. For example, in C/C++ you can assign a floating-point
value to an integer. In Java, you cannot. Also, in C there is not necessarily strong
type-checking between a parameter and an argument. In Java, there is. You might
find Java's strong type-checking a bit tedious at first. But remember, in the long run
it will help reduce the possibility of errors in your code
How many data type use java?
java use 8 simple data type. They are short, byte, long, char, Boolean, float, double.
short is a signed 16-bit type. It has a range from –32,768 to 32,767. It is probably the
least-used Java type, since it is defined as having its high byte first (called big-endian
format). This type is mostly applicable to 16-bit computers, which are becoming
- 38 -
increasingly scarce.
what is endian?
In computing, endianness is the order or sequence of bytes of a word of digital data in computer memory.
we will find two type of endian in computer architecture. one called big endian and another one is called little endian. if MSB(most significant bit) store fast its called big endian . one the other hand if LSB(least significant bit ) store fast its called little endian. Most of modern CPU that use x86 architecture fallow little endian. Ex. intel, AMD , apple bionic chip.
Java implements the standard (IEEE–754) set of floating-point types and operators
is char data type in java same as c/c++?
char data type in java is not same as c/c++. In c/c++ char is integer type 8 bit. But in java char is Unicode with 16 bit. Its range 0 to 65536. But in c/c++ char range is 0-127. c/c++ which follow ascii code. Remember that ascii code also included in Unicode. The ASCII character set occupies the first 127
values in the Unicode character set. For this reason, all the "old tricks" that you have
used with characters in the past will work in Java, too.
Integer literal In java:
In java integer literal are three type. They are decimal, octal, hexadecimal. Normal decimal numbers cannot have a
leading zero. Thus, the seemingly valid value 09 will produce an error from the compiler,
since 9 is outside of octal's 0 to 7 range. A more common base for numbers used by
programmers is hexadecimal, which matches cleanly with modulo 8 word sizes, such as
8, 16, 32, and 64 bits. You signify a hexadecimal constant with a leading zero-x, (0x or
0X). The range of a hexadecimal digit is 0 to 15, so A through F (or a through f ) are
substituted for 10 through 15.
Integer literals create an int value, which in Java is a 32-bit integer value. Since Java is
strongly typed, you might be wondering how it is possible to assign an integer literal to
one of Java's other integer types, such as byte or long, without causing a type mismatch
error. Fortunately, such situations are easily handled. When a literal value is assigned to
a byte or short variable, no error is generated if the literal value is within the range of the
target type. Also, an integer literal can always be assigned to a long variable. However,
to specify a long literal, you will need to explicitly tell the compiler that the literal value is
of type long. You do this by appending an upper- or lowercase L to the literal. For
example, 0x7ffffffffffffffL or 9223372036854775807L is the largest long.
No comments