You are on page 1of 9

TEMPLATE FOR ASSESSMENTS

1. Read Guidelines – in case of any doubt check with your mentor.


2. The final submission will have to be in soft copy in MS word as per template shared below.
3. Use Calibri font size 9
4. Keep Questions short and crisp. Word count should not exceed 20 words for questions
and 8 words for options.
5. In the last row – mention the correct option as a) or b)
6. The Blooms level has been fixed – so please design question accordingly.
7. The rows heights have been fixed, so that the table size is not changed. If you have any
problem, use this link to learn how to fix it YouTube
Insert the exact details within the < >

<CO, IF>: <22412>: < Java Programming >: < Basic Syntactical Constructs in Java >: <LO1>: <Assessments>:
<Formative>

<Yogita Jore>

Assessment Type: Formative Assessments: Embedded questions in video

Set 1: Question No 1 Set 1: Question No 2 Set 1: Question No 3

___ is the extension of java source file. Bytecode is the instruction set for _____ is the extension of Bytecode file.
_______.

Recall/ Remembering Understanding Application

a) .exe a) Class file a) .exe

b) .cmd b) Java Virtual Machine b) .cmd

c) .class c) complier c) .class

d) .java d) interpreter d) .java

Ans: <.java> Ans: < Java Virtual Machine > Ans: <.class>
Set 2: Question No 1 Set 2: Question No 2 Set 2: Question No 3

Identify the incorrect Java features. _____tool is used to find and fix bugs in _______ of the following option leads to
the Java programs. the portability and security of Java.

Recall/ Remembering Understanding Application

a) Dynamic a) JRE b) Bytecode is executed by JVM

b) robust b) JVM b) The applet makes the Java code secure


and portable

c) Use of pointers c) JDB c) Use of exception handling

d) Multithreading d) JAVA d) Dynamic binding between objects

Ans: < Use of pointers > Ans: <JDB> Ans: < Bytecode is executed by JVM >
Set 2: Question No 1 Set 2: Question No 2 Set 2: Question No 3

______of keywords is used to make a ______ of the following is a valid Identify the stored value in the object obj
class. declaration of an object of class Box. in following lines of Java code.

box obj;

Recall/ Remembering Understanding Application

a) class a) Box obj = new Box(); a) Memory address of allocated memory


of object

b) struct b) Box obj = new Box; b) NULL

c) int c) obj = new Box(); c) Any arbitrary pointer

d) pakage d) new Box obj; d) Garbage

Ans: < class > Ans: <Box obj = new Box();> Ans: < NULL>
Assessment Type: Summative: End of LO: in LMS

Summative: Q 1 Summative: Q 2 Summative: Q 3 Summative: Q 4 Summative: Q 5

______ component is ______ of the following ____ number of Identify the statement _____ component is
used to compile, debug tool is used to generate threads can be is true about java. responsible for
and execute java API documentation in executed at a time. converting bytecode
program. HTML format from doc into machine specific
comments in source code.
code.

Recall/ Remembering Understanding Application Understanding Application

a) JVM a) javap tool a) Only one thread a) Platform a) JVM


independent
programming language

b) JDK b) javaw command b) Multiple threads b) Platform dependent b) JDK


programming language

c) JIT c) Javadoc tool c) Only main (main() c) Code dependent c) JIT


method) thread programming language

d) JRE d) javah command d) Two threads d) Sequence dependent d) JRE


programming language

Ans: < JDK > Ans: < Javadoc tool > Ans: < Multiple threads Ans: < Platform Ans: < JVM >
> independent
programming language
>
Assessment Type: Practice Worksheets: End of CO: in LMS/ downloadable PDF

A. List and explain the java components?


Java Components: Java Development kit (JDK):
 The byte code The Java Development Kit comes with a collection of
 Java Development Kit (JDK) tools that are used for developing and running Java
 Java Virtual Machine (JVM) programs.
The Byte Code:  Javac (Java compiler)
Java bytecode is the instruction set for the Java Virtual  Java (Java interpreter)
Machine. It acts similar to an assembler which is an alias  Appletviewer (view java applet)
representation of a C++ code. As soon as a java program is  Javah (C header files)
compiled, java bytecode is generated. Java bytecode is the  Javap (Java disassembler)
machine code in the form of a .class file. With the help of  Jdb (java debugger)
java bytecode, we achieve platform independence in java.
When we write a program in Java, firstly, the compiler  Javadoc (java document for creating HTML
compiles that program and a bytecode is generated for that documents)
piece of code. When we wish to run this .class file on any
other platform, we can do so. After the first compilation, the Java Virtual Machine:
bytecode generated is now run by the Java Virtual Machine  It is a specification that provides runtime
and not the processor in consideration. This essentially environment in which java bytecode can be
means that we only need to have basic java installation on executed.
any platforms that we want to run our code on. Resources  JVMs are available for many hardware and
required to run the bytecode are made available by the Java software platforms (i.e. JVM is platform
Virtual Machine, which calls the processor to allocate the dependent).
required resources.  The JVM performs following operation:
o Loads code
o Verifies code
o Executes code
o Provides runtime environment
B. List and explain the features of java? Java is Multithreaded and Interactive language:
(Write any 4 features for 4 Marks) Multithreading means a single program having
different threads executing independently at the same
Ans: time. Java supports multithreaded programs. Multiple
Java is Compiled and Interpreted language: threads execute instructions according to the program
Java is a two stage system: In a first stage java compiler code in a process or a program. Multithreading works
translates source code into byte code instructions. Byte the similar way as multiple processes run on one
codes are not machine instructions. In a second stage, Java computer.  This design feature allows developers to
interpreter generates machine code that can be directly construct smoothly running interactive applications.
executed by the machine. The two steps of compilation and
interpretation allow for extensive code checking and Java is Familiar, Simple and Small language:
improved security. Java is designed to be easy to learn. If you understand
the basic concept of OOP java would be easy to
master. There are various features that make the java
as a simple language. Programs are easy to write and
debug because java does not use the pointers
explicitly. It is much harder to write the java programs
that can crash the system but we cannot say about the
other programming languages. Java provides the bug
Java is Platform-Independent and Portable language: free system due to the strong memory management. It
The feature “Write-once-run-anywhere” (known as the also has the automatic memory allocation and
Platform independent) states that programs written on one deallocation system. It also eliminates operator
platform can run on any platform provided the platform must overloading and multiple inheritance. Java uses many
have the JVM. Java programs can be easily moved from one Constructs of C and C++ and therefore Java code
computer system to another, anywhere and anytime. "looks like a C++" code. Thus Java is Simplified version
Changes and upgrades in operating systems, processors and of C++.
system resources will not force any changes in Java programs.
Due to this reason Java has become a popular language for Java is High Performance language:
programming on Internet. We can download a Java applet Interpretation of byte codes slowed performance in
from remote computer onto our local system via Internet and early versions, but advanced virtual machines with
execute it locally. adaptive and just-in-time compilation and other
techniques now typically provide performance up to
50% to 100% the speed of C++ programs.

Java is Dynamic:
By connecting to the Internet, a user immediately has
access to thousands of programs and other computers.
During the execution of a program, Java can
dynamically load classes that it requires either from
the local hard drive, from another computer on the
local area network or from a computer somewhere on
the Internet.
Java is an Object Oriented Language:
Everything in java is an object. All program code and data Java is Robust and Secure language:
reside within objects and classes. Java comes with an Java provides many safeguards to ensure reliable code.
extensive set of classes, arranged in packages that can use in Java has the strong memory allocation and automatic
our programs by inheritance. As the languages like Objective garbage collection mechanism. It provides the
C, C++ fulfils the four characteristics (Inheritance, powerful exception handling and type checking
Encapsulation, Polymorphism and Dynamic Binding) yet mechanism as compared to other programming
they are not fully object oriented languages because they are languages. Compiler checks the program whether
structured as well as Object Oriented Languages. But in case there are any errors and interpreter checks any run
of java, it is a fully Object Oriented Language because object time errors and makes the system secure from crash.
is at the outer most level of data structure in java. No stand- All of the above features make the java language
alone methods, constants, and variables are there in java. robust.
Everything in java is object even the primitive data types can With Java secure feature it enables to develop virus-
also be converted into object by using the wrapper class. free, tamper-free systems used in internet. The
absence of pointers in Java ensures that programs
Java is Distributed language: cannot gain access to memory locations without
Java is designed for the distributed environment of the proper authorization. Authentication techniques are
internet. The widely used protocols like HTTP and FTP are based on public-key encryption.
developed in java. Internet programmers can call functions on
these protocols and can get access the files from any remote
machine on the internet rather than writing codes on their
C. Java is not 100% object oriented language. Justify D. Explain the way to declared object and
class in java?
Ans: According to this assumption, there are several reasons Ans:
why Java is not a 100% Object Oriented Programming Declaring Class:
Language: Class is a user defined data type. Once a new data type
1) Primitive data types (int, char, floats, etc.) are not is defined using a class, it can be used to create objects
an object and couldn’t be defined as an object, of that type. A class is a template for an object and
neither a class. It is clear enough, because primitive object is an instance of a class. Classes create objects
data don’t have any ability/characteristic such as and objects use methods to communicate between
inheritance or polymorphism. So, we can say that them.
Java can be defined as not fully OOP supported Syntax:
language, since it’s allowed a non-object-oriented class classname [ extends superclassname]
thing to exist. int, float, etc. primitive data types are {
not objects. But java implemented Wrapper classes [ fields declaration; ]
for these primitive types to make them in to object [ methods declaration; ]
types. }
2) Multiple-inheritance through classes is not Example:
possible: As same as the operator overloading, class rectangle
multiple inheritance is also an (ad-hoc) abilities. It {
does support multiple inheritances directly, instead int length, width; //declaration of variables
of that we can use interfaces, and with the help of void getdata(int x, int y)
interface implicitly we can use multiple //definition of method
inheritances. { length = x;
3) Availability of static methods and variables: Since width = y;
this ability exists in Java, which allows developers to }
invoke a method without instantiating any object Rules for defining classes:
like breaking rules of encapsulation.  Everything inside the square brackets is optional.
4) Operator overloading is not possible in java:  No semicolon after closing curly bracket.
Except “+” operator which can be used in two  Classname and superclassname are any valid java
different operations (addition operation and identifiers.
concatenation of string), there is no possibilities in  The keyword extends indicates that the
Java to do an operator-overloading. Since, this is a properties of the superclassname class are
kind of polymorphism ability (specific for operators) extended to the classname class. This concept is
we also could say that Java isn’t 100% OOP known as inheritance.
Language.  The data or variables defined within a class are
called instance variables.
 Collectively the methods and variables defined
within class are called members of the class.

Object:
It is a basic unit of Object-Oriented Programming and
represents the real life entities.  A typical Java program
creates many objects, which as you know, interact by
invoking methods.
Initializing an object:
Classes provide constructor methods to initialize a new
object of that type. A class may provide multiple
constructors to perform different kinds of initialization
on new objects.
For example:
Rectangle rect1=new Rectangle (10, 20);
E. Explain the steps to execute java code?

Ans:
Compilation and Execution of Java Program
1. Create a program using any text editor (use notepad editor
in Windows Operating System). Open notepad and enter/edit
the following program.
class Test
{
public static void main(String args[])
{
System.out.println(“Hello! ”);
System.out.println(“Welcome to the world
of java ”);
System.out.println(“Let us learn java ”);
}
}

2. Save this program in a file called “Test.java”.


The name of file must be same as main class name.
Here main class name is Test so save this program in
“Test.java” file.
This file is called as source file.
All java source files should have extension .java.
Note that if program contains multiple classes the file name
must be the classname of the class containing the main
method, i.e. main class name.

3. Locate/store Test.java file in the bin directory of java


compiler.

4. Close notepad and go to dos prompt.

5. Go to bin directory.

6. Compile the program using javac tool of JDK as follows


C:\jdk\bin\ javac Test.java
If errors are there then listing of errors will be displayed and
to correct the errors again open the source file using notepad
and correct the program otherwise javac creates “Test.class”
file containing the byte code of the program.

7. Run the program using the java interpreter as follows: -


C:\jdk\bin\java Test

Thus we will get the following output


Hello!
Welcome to the world of java
Let us learn java

You might also like