Java Theory - Java Basics
Java Theory - Java Basics
1. What is Java?
Ans.
Java is a simple and powerful high level, object oriented programming language. Java originated at Sun
Microsystems, Inc. in 1991. It was developed to provide a platform-independent programming language.
1
Faster execution of control statements as Slower execution of control statements as
compared to the interpreter. compared to the compiler.
Detected errors in the program get displayed Detected errors in the program get displayed
after the entire program is read by compiler. after each instruction read by the interpreter.
Example: C++, Java. Example. Python, PHP.
5. What are advantages of object oriented programming? / Why is Java called as Object
Oriented Language?
Ans. Unlike procedural languages, in Java we can create objects, which offer many
advantages:
Objects are created on real world entities.
Complex systems of real world can be converted into software solutions.
Objects can be easily reused in other programs due to its re-usability feature.
Objected oriented programs focuses the developer to do extensive planning which will
reduces programming flaws and better design.
Software maintenance of the object oriented program is easier than as compared with
structured oriented programming.
2
8. What is JVM?
Ans. The java run-time system which translates or interprets byte code into machine code is
known as Java Virtual Machine (JVM) or java Interpreter.
A JVM can either interpret the bytecode one instruction at a time or the bytecode can
be compiled further for the real microprocessor using what is called a just-in-time
compiler.
The JVM must be implemented on a particular platform before compiled programs can
run on that platform.
3
9. What is JDK?
Ans.
JDK is a kit(or package) which includes two things i) Development Tools(to provide an
environment to develop your java programs) and ii) JRE (to execute your java program).
4
BlueJ is an integrated development environment (IDE) for the Java programming language, developed
mainly for educational purposes, but also suitable for small-scale software development.
It has a built in editor
Interactive interface to create and test objects
Ability to run applications
1. What are comments? What are different types of comments found in the program?
Ans. • Comments are descriptions that are added to the program to make code easier to
understand.
• Compiler ignores the comments
Type Syntax Usage
Single-line // comment All characters after the // up to the end of the line
are ignored.
Multiline /* comment */ All characters between /* and */ are ignored.
Documenting /** Comment The JDK javadoc tool uses doc comments when
(Doc) */ preparing automatically generated documentation.
Comment
13. What are different types of errors you find in your program?
Ans. Syntax errors:
Errors occurring when you violate a syntax rule.
Caught during compile time
E.g. forgetting to terminate program statement with ;
Logical errors:
Also called design errors or bugs which escape compilation
Occurs when logic of the program is incorrect.
Can be fixed by testing & debugging the program
E.g. PI = 31.4;
5
Run-time errors:
Occur when we ask the computer to do something it considers to be illegal.
In these cases Java throws exception
E.g. dividing by zero