0% found this document useful (0 votes)
31 views7 pages

HHHHHHHHHHH

Uploaded by

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

HHHHHHHHHHH

Uploaded by

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

Java programming BCA Dept

Unit-1
Chapter 2
Introduction to Java
2 marks questions:
1. List any four features of Java
Ans:
• Compiled and Interpreted
• Platform-Independent and Portable
• Object-Oriented
• Robust and Secure

2. What is Java Bytecode?


Ans:

All language compilers translate source code into machine code for a
specific computer. Java compiler also does the same thing.Then how does
Java achieve architecture neutrality?The answer is that the Java compiler
produces an intermedia code known as bytecode for a machine that does not
exist. This machine is called the Java Virtual Machine and it exists only
inside the computer memory.

3. What is Java Virtual Machine ?


Ans:
It is a virtual machine that enables a computer to run java programs as well
as programs written in other languages that are also compiled to java
bytecode. It is a program that interprets the intermediate Java byte code and
generates the desired output.

4. Write the meaning of public static void main(String args[])


Ans:
• public: It is an access specifies that declares the main method as
unprotected and therefore making it accessible to all other classes.
• static: The main must always be declared as static since the interpreter
uses this method before any objects are created
• void: It states that the main method does not return any value
String args[] declares a parameter named args, which contains an array of
objects of the class type String.
• Every Java application program must include the main() method. This is
the starting point for the interpreter to begin the execution of the program.

IMJISC MOODLAKATTE KUNDAPURA 1


Java programming BCA Dept

5. Mention two ways of writing comments in Java


Ans:
Java permits both the single line and multi-line comments. The single line
comments begin with // and end at the end of the line. For longer comments, we
can create long multi-line comments by starting with a /* and ending with a */.
Java also uses a third style of comment /**….*/ known as documentation
comment.

Long answer questions:


1. List and explain different features of Java
Ans:
• Compiled and Interpreted
• Platform-Independent and Portable
• Object-Oriented
• Robust and Secure
• Distributed
• Familiar, Simple, and Small
• Multithreaded and Interactive
• High Performance
• Dynamic and Extensible
• Ease of Development
• Scalability and Performance
• Monitoring and Manageability
• Desktop Client
Compiled and Interpreted
A computer language is either compiled or interpreted. Java is a two-stage
system
First, Java compiler translates source code into bytecode instructions. Bytecodes
are not machine instructions and therefore, in the second stage, Java interpreter
generates machine code that can be directly executed by the machine
Java is both a compiled and an interpreted language
Platform Independent and Portable
Java programs can be easily moved from one computer system to another,
anywhere and anytime. Changes and upgrade in operating systems, processors
and system resources will not force any changes in Java programs. Java ensures
portability in 2 ways. First, Java compiler generates bytecode instructions that

IMJISC MOODLAKATTE KUNDAPURA 2


Java programming BCA Dept

can be implemented on any machine. Secondly, the size of the primitive data
types are machine independent
Object-Oriented
Java is a true object-oriented language. Almost everything in Java is an object
All program code and data reside within objects and classes. The object model
in Java is simple and easy to extend
Robust and Secure
Java is a robust language. It provides many safeguards to ensure reliable code
It has strict compile time andruntime checking for data types. It is a garbage
collected language. Java incorporates the concept of exception handling which
captures series errors and eliminates any risk of crashing the system. Java
systems ensure that no viruses re communicated with an applet
Distributed
Java is designed as a distributed language. It has the ability to share both data
and programs
Simple, Small and Familiar
Java is a simple and small language. Many features of C and C++ that are either
redundant or sources of unreliable code are not part of Java. Java does not use
pointer, preprocessor header files, goto statement and many others. It also
eliminates operator overloading and multiple inheritance. Java is modelled on C
and C++ languages. Java uses many constructs of C and C++. Java code looks
like a C++ code. Java is a simplified version of C++
Multithreaded and Interactive
Multithreaded means handling multiple tasks simultaneously. Java supports
multithreaded programs. We need not wait for the application to finish one task
before beginning another. This improves the interactive performance of
graphical applications
High Performance
Java architecture is designed to reduce overheads during runtime. Overall
executions peed of Java programs is good
Dynamic and Extensible
Java is capable of dynamically linking in new class libraries, methods and
objects. Java can also determine the type of class through a query, making it
possible to either dynamically link or abort the program, depending on the
response. Java programs support functions written in other languagessuch as C
and C++. These functions are called native methods. Native methods are linked
dynamically at runtime

IMJISC MOODLAKATTE KUNDAPURA 3


Java programming BCA Dept

Ease of Development
Java 2 Standard Edition (J2SE) 5.0 supports different features. These features
reduce the work of the programmer by shifting the responsibilities to the
compiler
The resulting source code is free from bugs because errors made by the
compiler are less when compared to those made by programmers
Scalability and Performance
Improves the startup time and reduces the amount of memory used in runtime
environment
Monitoring and Manageability
Java supports a number of APIs, such as JVM Monitoring and Management
API to monitor and manage Java applications
Desktop Client
J2SE 5.0 provides enhanced features to meet the requirement and challenges
of the Java desktop users.

2. Explain a simple java program with example


Ans:
Simple java program:
classSampleOne
{ OUTPUT
public static void main(String args[]) Java is better than C++
{
System.out.println("Java is better than C++");
}
}
Class Declaration
The first line class SampleOne declares a class. Java is a true object-oriented
language and therefore, everything must be placed inside a class. class is a
keyword and declares that a new class definition follows. SampleOne is a Java
identifier that specifies the name of the class to be defined
Opening Brace
Every class definition in Java begins with an opening brace “{” and ends with a
matching closing brace “}”. This is similar to C++ construct
The Main Line
The third line public static void main(String args[]) defines a
method named main. This is similar to the main() function in C/C++. Every

IMJISC MOODLAKATTE KUNDAPURA 4


Java programming BCA Dept

Java application program must include the main() method. This is the starting
point for the interpreter to begin the execution of the program. This line
contains other keywords public, static and void
• public: It is an access specifies that declares the main method as
unprotected and therefore making it accessible to all other classes.
• static: The main must always be declared as static since the interpreter
uses this method before any objects are created
• void: It states that the main method does not return any value
String args[] declares a parameter named args, which contains an array of
objects of the class type String
The Output Line
The only executable statement in the program is:
System.out.println("Java is better than C++");
This is similar to the printf() statement of C or cout<<construct of C++. Since
Java is a true object-oriented language, every method must be part of an object.
The println method is a member of the out object, which is a static data
member of System class. This line prints the string Java is better than C++.
The method println always appends a newline character to the end of the string.
This means that any subsequent output will start on a new line. Every Java
statement must end with a semicolon.

3. Explain the java program structure with example.


Ans:

A Java program may contain many classes of which only one class defines a
main method. Classes contain data members and methods. Methods may
contain data type declaration and executable statements. To write a Java
program, we first define classes and then put them together. A Java program
may contain one or more sections

IMJISC MOODLAKATTE KUNDAPURA 5


Java programming BCA Dept

Documentation Section
A documentation section comprises a set of comment lines giving the name of
the program, the author and other details. Comments must explain why and
what of classes and how of algorithms. Java permits both the single line and
multi-line comments. The single line comments begin with // and end at the end
of the line. For longer comments, we can create long multi-line comments by
starting with a /* and ending with a */. Java also uses a third style of comment
/**….*/ known as documentation comment
Package Statement
The first statement allowed in a Java file is a package statement. This statement
declares a package name and informs the compiler that the classes defined here
belongs to this package.
Example: package student;
The package statement is optional
Import Statements
This is similar to the #include statement is C.
Example: import student.test;
This statement instructs the interpreter to load the test class contained in the
package student. Using import statements, we can have access to classes that
are part of other named packages
Interface Statements
An interface is like a class but includes a group of method declaration. This is
also an optional section and is used only when we wish to implement the
multiple inheritance features in the program
Class Definitions
A Java program may contain multiple class definitions. Classes are the primary
and essential elements of a Java program. The number of classes used depends
on the complexity of the problem

IMJISC MOODLAKATTE KUNDAPURA 6


Java programming BCA Dept

Main Method Class


Since every Java program requires a main method as its starting point, this class
is the essential part of a Java program. A simple Java program may contain only
this part. The main method creates objects of various classes and establishes
communications between them. On reaching the end of main, the program
terminates and the control passed back to the operating system.

IMJISC MOODLAKATTE KUNDAPURA 7

You might also like