Java is a high-level platform independent object-oriented
programming language.
Father of java is James Gosling.
Java was introduced in the year 1990 in Sun Microsystem to
develop internet.
applications.
Java's first version (i.e., Beta version) was released in the
year 1995.
Java 1.0 was released in the year 1996.
There are different types of applications:
1. Stand Alone Application: The applications which don’t
require external connectivity are Stand Alone Application.
2. Web Applications: The applications which requires external
connectivity are Web Applications.
Java has different editions based on type of app to
develop:
1.Java SE: Java Standard Edition: is used to develop stand
alone app Core Java.
2.Java EE: Java Enterprise Edition: used to develop web
applications Advanced Java.
3.Java ME: Java Micro Edition: used to develop drivers,app for
mobile.
4.Java Fx: Java Special Effects: used to develop graphics.
Words to remember:
Source Code: The code which is written by the developer by
following.
proper set of syntax of language in a system is called as
source code.
In java, the source code is in High Level Language.
The source code is understandable only by the human.
Hence, it should converted to machine understandable language.
Whenever a source is written by the developer, there is a
chance of errors in
the source code.
The error can be-->Not maintaining the proper syntax
(grammar/rule) of language.
To get to know about that error, we must go through the
program at least once, still then there may be some error
which would have been ignored.
So, to overcome the problems as mentioned above, we must
compile the source code.
Q1. Why should we compile source code?
Answer:
i)Source code is HLL, and system doesn’t understand HLL. It
understands only LLL.
ii)There may be errors in the source code. (mainly syntax
errors)
Q2. How do we compile source code?
Answer: By using translator software.
In java we use java compiler as translator software.
Compiler:
i. It is a translator software.
ii. It translates HLL into LLL.
iii. In java, the compiler is responsible to convert source
code to byte code.
Speciality of java compiler:
1. It checks whether the provided source file is available in
the directory or not. If the file is not available, then
compiler will generate error message in console. If the file
is found, then compiler will go for next step.
2. It checks the syntax error in the program inside source
file. If error is found, then compiler will throw error and
generate a message related to error information. If there is
no error, then compiler will generate.
a .class file in which compiler will load the byte code.
iv. In java, the compiler is named as 'javac'.
Byte Code:
- It is the intermediate code for any OS.
- It is Low level in nature.
- It is available inside '.class file' generated by the
compiler.
Note: '.class file' name is always same as class name declared
in source code. It’s a instruction set, which contains 256
instructions.
The instructions are menemonics which looks like assembly
language commands.
==============================================================
=====================
Interpreter:
It is a translating software used to convert Byte Code to
Native Code as per the platform where it is installed.
Java interpreter is also known as JVM (Java Virtual Machine).
Because it acts as machine which translates byte code to
native code, but it doesn’t exist in physical form.
It’s a software. In java technology the interpreter
application name is 'java'.
Compilation: It’s the phase of compiling the source code.
Interpretation/Execution: Phase of generating result from
program.
Type Extension: It tells about the type of file.e.g:
.docx --> ms-word document
.txt --> text file
.jpg --> image file
.mp3 --> audio file
. java --> java source code file
. class --> java byte code file.
Platform: It’s an environment where an app executes.
It’s a combination of H/W + OS.
Platform Independent:
Platform Dependent:
Features of Java: mainly its open source i.e., its free of
cost to use java to develop applications.
Till Java 10 it was completely free of cost but, from Java 11
onwards it’s both open source as well as licensed.
Now we have:
i. Open JDK
ii.Oracle JDK
1.Simple: Its easy and simple to learn and develop projects.
Because all the concepts used in java are simple as the
syntaxes used in java are easy to learn.
It doesn’t use lots of confusing concepts such as Pointers
(used in C), multiple inheritance(C++) etc. And above to all,
it has lots predefined libraries due to which
development of project becomes faster and easy.
2. Secure: There is a special feature inbuilt i.e., Byte Code
Verifier in JVM.
Its responsibility is to check whether the code contains any
malicious code or not. If it finds anything suspicious then the
code is not allowed to be exceuted.Due to this the system is
safe.
It also provides access modifier 'private' , which when used
with an element, the element will not be allowed to access
outside the class.
3.Object Oriented: Java is a class-based program which
means every program will be written by starting the program
with class as the programs in java are basically for
representing real world objects in programming world. And it’s
possible using class. A class represents the blueprint of
objects.
4.Byte Coded: Java programs are compiled to achieve
platform independent type apps.
5.Interpreted: Byte codes are generally dependent on the
current OS, but interpreter takes it and generates native code
for OS to perform action on commands present in Byte codes.
AS like java other PL are also interpreted PL. Such as
C#.NET, python, JavaScript, PHP etc.
6.Portable (Platform Independent): Application of java
developed in one platform can work in other platforms also. We
don’t have to rewrite the complete source code, we just need
the byte code to be shared.
7.MultiThreaded: It supports to develop applications which
can handle multiple tasks parallelly at a time. In java each
task can have its separate thread to complete its execution
independent of any other tasks.
8.Robust(Strong): It has a fail safe system, which means
whenever an abnormal or unexpected condition is arised then
the program terminates only after saving the given data and
there is no loss of data. C is not type checked, but java is
strictly type checked. You can't have loss of data.
Exception handling will support in making the application
continue the execution even after any exception may arise.
9.High Performance: Java program execution is faster
because of multithreading and a special feature from Java 1.3
i.e JIT Compiler.
10.Distributed: We can develop applications which can be
accessible through worldwide remotely.
It have special technologies such as :
RMI, XML,EJB,WebServices,REST API,JSONs.....to be
continued in Adv.java.
11.Dynamic: We can add new features to application without
affecting the old features.
Because of OOP concepts:
1. inheritance
2. encapsulation
3. abstraction
4. polymorphism.
E.g. Mobile Phone can read any SIM. But GSM Mobiles don’t.
ATM machines read other bank ATM's.
PAYTM earlier had only recharge options but now it has got
more features.
12.Architecture Neutral: Whatever result you get in one
platform the same you can get in another
platform also (memory size is fixed for all OS and
processors).
In C 'int' has different size from one OS to another OS.
but in java its always same in all OS.
13. Garbage Collected: It manages the memory by clearing the
unused objects.
We dont have to destroy objects they are automatically
destroyed by JVM
by using one of its resource called as GC.
Q1.Which feature is necessary in a technology to
develop Internet Applications?
Answer: Technology must have characteristic of developing
platform independent
application.
Q2. How did Java achieve platform independent
feature?
Answer: By allowing to shift the Machine Language from
compilation phase to
execution phase by the help of generating bytecodes.JVM
converts the bytecode into current OS understandable machine
language.
Q3. Java is platform dependent or independent?
Answer: Independent
Q4. JVM is platform dependent or independent?
Answer: Dependent because for every OS we have separate JVM.
Q5. What are the types of Java software?
Asnwer: Java software is divided into two types:
1. JDK:it has both compiler and JVM
2. JRE:it has only JVM
JDK and JRE both are principle products of Java.
Q6. Can we execute a java program using using lower
version JVM than compiler version?
Answer: No.
Q7. What type of applications can be developed using
Java?
Answer: We can develop following applications:
1. Desktop Applications
2. Web Applications
3. Enterprise Applications
4. Interoperable Applications
5. Mobile Applications
6. Gaming Applications
7. Automation Testing Applications
8. iOT, Cloud Computing, Big Data Hadoop Applications
9. Data Science & Data Analytics Applications
10. ML, Deep Learning, AI
Q1.What is an identifier in Java?
Answer: An identifier in Java is a name given to a variable, method,
class, package, or other program elements. It acts as a unique
identifier within the scope it is defined.
Q2.What are the rules for naming identifiers in Java?
Answer:
a). Identifiers must begin with a letter (A-Z or a-z), dollar sign ($),
or underscore (_).
b). After the first character, identifiers can contain letters, digits
(0-9),
dollar signs ($), or underscores (_).
c). Identifiers cannot be Java keywords.
d). Identifiers are case-sensitive.
e). There is no maximum limit on the length of an identifier.
Q3. Can identifiers start with a digit in Java?
Answer: No, identifiers cannot start with a digit in Java.
Q4. Can Java keywords be used as identifiers?
No, Java keywords cannot be used as identifiers.
Q5. What is the maximum length of an identifier in
Java?
Answer: There is no maximum limit on the length of an identifier in
Java.
Q6. Can identifiers contain spaces in Java?
Answer: No, identifiers cannot contain spaces in Java.
Q7. What is the significance of case sensitivity in
Java identifiers?
Answer: Java identifiers are case-sensitive, meaning variableName,
VariableName, and variablename are treated as three different
identifiers.
Q8. Is it a good practice to use underscores in Java
identifiers?
Answer: It’s a common convention in Java to use underscores in variable
names
for better readability (e.g., my_variable). However, it's not
mandatory.
Q9. Can Java identifiers contain special characters
like @ or $?
Answer: Yes, Java identifiers can contain the dollar sign ($) and
underscore (_), but they cannot contain other special characters like
@.
Q10.How would you choose meaningful identifiers for
variables, methods, and classes in Java?
Answer:
a). Use descriptive names that convey the purpose or meaning of the
variable, method, or class.
b). Follow camelCase convention for variables and methods
(e.g., myVariable, calculateArea()).
c). Use PascalCase convention for class names (e.g., MyClass).
d).Avoid using abbreviations or overly short names.
e). Choose consistent naming conventions throughout the project.
Q11.Explain the concept of camelCase and its
relevance in Java identifiers.
Answer: CamelCase is a naming convention where compound words are
joined together, and each word in the middle (after the first) begins
with a capital letter. It's commonly used in Java for naming variables
and methods for better readability and clarity.
Q12.What are the conventions for naming constants in
Java identifiers?
Answer: Constants in Java are typically named using all uppercase
letters, with words separated by underscores (e.g., MAX_SIZE, PI).
Q13.Can identifiers in Java be composed entirely of
underscores?
Answer: Yes, identifiers in Java can be composed entirely of
underscores, but it's not a common practice and might not be very
meaningful.
Q14.Are there any naming conventions to follow when
naming packages in Java?
Answer: Package names in Java are typically in lowercase letters to
differentiate them from classes and other identifiers. They often
follow the reverse domain name convention .
(e.g. com.example.packageName).
Q15.How would you differentiate between local
variables, instance variables, and class variables in
terms of naming conventions?
Answer:
Local variables are typically named using camelCase.
Instance variables often start with a lowercase letter and use
camelCase.
Class variables (also known as static variables) are typically named in
uppercase with underscores separating words.
Q16.Is it acceptable to use non-English characters in
Java identifiers?
Answer: While Java allows Unicode characters in identifiers, it's
generally not recommended to use non-English characters as it might
reduce code portability and readability.
Q17.What is the difference between a legal identifier
and a valid identifier in Java?
Answer: A legal identifier follows the syntax rules defined for
identifiers in Java but may not necessarily make sense or be
meaningful. A valid identifier is both legal and meaningful in the
context it's used.
Q18.How do you handle naming conflicts in Java when
dealing with multiple libraries or modules?
Answer: Use fully qualified names to specify which class or method
you're referring to. Use import statements wisely to avoid ambiguity.
Rename conflicting identifiers to make them unique within the scope.
Q19.Are there any restrictions on using reserved
words as part of an identifier in Java?
Answer: Yes, reserved words (keywords) cannot be used as identifiers in
Java.
Q20.Can identifiers contain Unicode characters in
Java?
Answer: Yes, Java allows identifiers to contain Unicode characters,
but it's recommended to stick to ASCII characters for better
portability and readability.
Q21.What is a class?
Answer: It is a keyword.
It represents blueprint of objects/classification of objects.
It acts as a data type because we can create variables using class.
If we use a class to create a variable, then the variable is used to
refer to an object. And the variable will be termed as Reference
Variable. It is a type of non-primitive data type.
Note: Every java program is started with a keyword class.
Important Interview Question:
Q22. What is the use of data types?
Answer: We create variables using data types and data types tells
system about:
a. size of memory allocated to variable.
b. no. of values to be stored in variable.
c. type of value to be stored in variable.
d. range of value to be stored in variable.
Q23. Why main method is declared as static?
Answer: JVM can access it directly. There is no need of creating object
to access it.
Q24.In java total reserve keyword.
Answer: abstract, continue, for, new switch, Assert, default goto package
synchronized, Boolean , do if, private, this, break , double, implement
protected, throw, byte, else, import, public, throws, case,
enuinstanceof, return, transient, catch, extends, int, short, try, char
final, interface, static, void ,class ,finally ,long ,strictfp ,volatile
const ,float ,native ,super, while.
_(underscore)
-------------------------------------------------------
Note:
Since Java 9, the underscore character is a reserved keyword and can't
be used as an identifier. or variable name.
------------------------------------------------------
* goto is not in use
* const is not in use
Upto JDK 8, there were 50 keywords but from JDK 9 its 51.
Because of underscore added into the list of keywords.