[go: up one dir, main page]

0% found this document useful (0 votes)
3 views11 pages

Java Basic

The document explains key concepts related to Java, including its classification as an Object-Oriented Programming (OOP) language, its platform independence, and the differences between JDK, JRE, and JVM. It also discusses Java's bytecode, the distinction between abstraction and encapsulation, and the reasons for not supporting pointers. Additionally, it covers memory areas allocated by JVM, the Unicode standard, and the creation and execution of JAR files.

Uploaded by

rdipali162
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

Java Basic

The document explains key concepts related to Java, including its classification as an Object-Oriented Programming (OOP) language, its platform independence, and the differences between JDK, JRE, and JVM. It also discusses Java's bytecode, the distinction between abstraction and encapsulation, and the reasons for not supporting pointers. Additionally, it covers memory areas allocated by JVM, the Unicode standard, and the creation and execution of JAR files.

Uploaded by

rdipali162
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

1. Why Java is called an OOP language?

Java is called Object Oriented Programming Language Because Java is a kind of


programming language that uses Object in each of its programs. In each java
program you have to create classes and in the main function of java you have to
create objects of the classes. All concepts like inheritance, modularity, polymorphism,
and encapsulation in coop are supported by java.

2. Why Java is platform independent but C++ not?

3. Why Java is not fully platform independent?


4. What do you mean by platform?
Platform is a hardware or software environment in which a
program runs. Java has its own run time environment known
as JRE(Java Run-time Environment) and Java Virtual
Machine(JVM) which converts Java code to machine code.

5. Why Java is not 100% pure OOP language?


Pure Object Oriented Language or Complete Object Oriented
Language are Fully Object Oriented Language which supports or
have features which treats everything inside program as objects. It
doesn’t support primitive datatype(like int, char, float, bool, etc.).
There are seven qualities to be satisfied for a programming
language to be pure Object Oriented. They are:
1.Encapsulation/Data Hiding
2.Inheritance
3.Polymorphism
4.Abstraction
5.All predefined types are objects
6.All user defined types are objects
7.All operations performed on objects must be only through
methods exposed at the objects.
Example: Smalltalk
Why Java is not a Pure Object Oriented Language?
Java supports property 1, 2, 3, 4 and 6 but fails to support property
5 and 7 given above. Java language is not a Pure Object Oriented
Language as it contain these properties:
6. Differentiate among JDK, JVM and JRE.

Difference between JDK, JRE, and JVM


1. A summary of JVM
2. Java Runtime Environment (JRE)
3. Java Development Kit (JDK)

We must understand the differences between JDK, JRE, and JVM before
proceeding further to Java. See the brief overview of JVM here.

If you want to get the detailed knowledge of Java Virtual Machine, move to
the next page. Firstly, let's see the differences between the JDK, JRE, and
JVM.

JVM
JVM (Java Virtual Machine) is an abstract machine. It is called a virtual
machine because it doesn't physically exist. It is a specification that
provides a runtime environment in which Java bytecode can be executed.
It can also run those programs which are written in other languages and
compiled to Java bytecode.

JVMs are available for many hardware and software platforms. JVM, JRE,
and JDK are platform dependent because the configuration of each OS is
different from each other. However, Java is platform independent. There
are three notions of the JVM: specification, implementation, and instance.

The JVM performs the following main tasks:


o Loads code
o Verifies code
o Executes code
o Provides runtime environment

More Details.
JRE
JRE is an acronym for Java Runtime Environment. It is also written as Java
RTE. The Java Runtime Environment is a set of software tools which are
used for developing Java applications. It is used to provide the runtime
environment. It is the implementation of JVM. It physically exists. It
contains a set of libraries + other files that JVM uses at runtime.

The implementation of JVM is also actively released by other companies


besides Sun Micro Systems.

JDK
JDK is an acronym for Java Development Kit. The Java Development Kit
(JDK) is a software development environment which is used to develop
Java applications and applets. It physically exists. It contains JRE +
development tools.

JDK is an implementation of any one of the below given Java Platforms


released by Oracle Corporation:

o Standard Edition Java Platform


o Enterprise Edition Java Platform
o Micro Edition Java Platform
The JDK contains a private Java Virtual Machine (JVM) and a few other
resources such as an interpreter/loader (java), a compiler (javac), an
archiver (jar), a documentation generator (Javadoc), etc. to complete the
development of a Java Application.

7. What is Byte code?


Byte Code
Byte Code can be defined as an intermediate code generated by
the compiler after the compilation of source code(JAVA Program).
This intermediate code makes Java a platform-independent
language.

8. Why Java is called a compiler-interpreter language?


Java is both a compiled and interpreted programming language.
Because it employs both compilation and interpretation to run
code, it is known as a “compiler-interpreter language.” In order for
the Java Virtual Machine to understand the Java code, it must first
be compiled into an intermediate format called bytecode (JVM). The
bytecode is subsequently interpreted by the JVM and transformed
into hardware-compatible machine code.
9. Difference between Abstraction and Encapsulation in Java.

Abstraction Encapsulation

Abstraction is the process or


While encapsulation is the process or
method of gaining the
method to contain the information.
information.

In abstraction, problems are


While in encapsulation, problems are
solved at the design or
solved at the implementation level.
interface level.

Whereas encapsulation is a method to


Abstraction is the method of
hide the data in a single entity or unit
hiding the unwanted
along with a method to protect
information.
information from outside.

We can implement abstraction Whereas encapsulation can be


using abstract class and implemented using by access modifier
interfaces. i.e. private, protected and public.

In abstraction, implementation While in encapsulation, the data is


complexities are hidden using hidden using methods of getters and
abstract classes and interfaces. setters.

The objects that help to


Whereas the objects that result in
perform abstraction are
encapsulation need not be abstracted.
encapsulated.

Encapsulation hides data and the user


Abstraction provides access to
can not access same directly (data
specific part of data.
hiding.

Abstraction focus is on “what” Encapsulation focus is on “How” it should


should be done. be done.
10. Why Java does not support pointers?
java does not support pointers because of pointers
need so memory spaces at the runtime. to reduce the
usage of memory spaces java does not support
pointers. and also pointers take more time at the run
time.

11. How Java achieves platform independence?

12. Difference between path and classpath in Java?

Path

PATH is an environment variable that is used to find and locate


binary files like “java” and “javac” and to locate needed
executables from the command line or Terminal window. To set the
path, we’re supposed to include or mention JDK_HOME/bin directory
in a PATH environment variable. The PATH can not be overridden
by providing command and PATH is only used by the operation
system(OS) to find binary files.
Syntax
// To set PATH in the window OS.
set PATH=%PATH%;C:\Program Files\Java\JDK1.5.10\bin

// To set PATH in Unix OS


export PATH=${PATH}:/opt/Java/JDK1.5.10/bin

Classpath

Classpath is an environment variable that is used by the application


ClassLoader or system to locate and load the compiled Java
bytecodes stored in the .class file. To set CLASSPATH. the
CLASSPATH can be overridden by adding classpath in the manifest
file and by using a command like set -classpath. the CLASSPATH is
only used by Java ClassLoaders to load class files.
Syntax
// To set CLASSPATH in window OS.
set CLASSPATH=%CLASSPATH%;C:\Program Files\Java\JDK1.5.10\lib

// To set PATH in Unix OS.


export CLASSPATH=${CLASSPATH}:/opt/Java/JDK1.5.10/lib

13. How many types of memory areas are allocated by JVM?

JVM memory can be divided into five different parts :


12

 Class (Method) Area


 Heap
 Stack
 Program Counter Register
 Native Method Stack

14. What is UNICODE? Differentiate it with ASCII code.

Unicode provides a unique way to define every character in every


spoken language of the world by assigning it a unique number. The
Unicode standard is maintained by the Unicode Consortium and
defines more than 1,40,000 characters from more than 150 modern
and historic scripts along with emoji.

ASCII and Unicode are character encoding standards that


are used to represent text in computers. The difference
between ASCII and Unicode is that ASCII covers only 128
characters such as lowercase and uppercase letters, digits,
and punctuation marks. Unicode covers over a million
characters such as letters of different languages,
mathematical symbols, historical scripts, and emoji. Unicode is
the universal standard that can encode text data in any
language.

15. Explain the purposes of different modules of JVM.


16. What is JAR file? How to create and execute JAR file in
Java?

A JAR (Java Archive) is a package file format typically used to


aggregate many Java class files and associated metadata and
resources (text, images, etc.) into one file to distribute application
software or libraries on the Java platform.
In simple words, a JAR file is a file that contains a compressed
version of .class files, audio files, image files, or directories. We can
imagine a .jar file as a zipped file(.zip) that is created by using
WinZip software. Even, WinZip software can be used to extract the
contents of a .jar . So you can use them for tasks such as lossless
data compression, archiving, decompression, and archive
unpacking.
Let us see how to create a .jar file and related commands which
help us to work with .jar files

1.1 Create a JAR file


In order to create a .jar file, we can use jar cf command in the
following ways as discussed below:
Syntax:
jar cf jarfilename inputfiles
Here, cf represents to create the file. For example , assuming our
package pack is available in C:\directory , to convert it into a jar file
into the pack.jar , we can give the command as:
C:\> jar cf pack.jar pack

Running a JAR file


In order to run an application packaged as a JAR file (requires the
Main-class manifest header), the following command can be used
as listed:
Syntax:
C:\>java -jar pack.jar

You might also like