0% found this document useful (0 votes)
4 views

Assignment No.1 Core Java (1)

The document provides an introduction to the Java programming environment, detailing its characteristics such as being object-oriented, architecture-neutral, and secure. It also covers essential tools like javac for compiling Java code, jdb for debugging, and the JavaDoc tool for generating documentation. Each tool's functionality and usage, including command syntax and options, are explained to assist users in building and managing Java applications.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment No.1 Core Java (1)

The document provides an introduction to the Java programming environment, detailing its characteristics such as being object-oriented, architecture-neutral, and secure. It also covers essential tools like javac for compiling Java code, jdb for debugging, and the JavaDoc tool for generating documentation. Each tool's functionality and usage, including command syntax and options, are explained to assist users in building and managing Java applications.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Assignment No.

1 Core Java
Aim :- Introduction to Java Enviornment, javac, jdb
and javadoc.
What is the Java Programming Environment?
Java is a recently developed, concurrent, class-based, object-oriented programming
and runtime environment, consisting of:

• A programming language
• An API specification
• A virtual machine specification

Java has the following characteristics:

• Object oriented - Java provides the basic object technology of C++ with some
enhancements and some deletions.
• Architecture neutral - Java source code is compiled into architecture-
independent object code. The object code is interpreted by a Java Virtual
Machine (JVM) on the target architecture.
• Portable - Java implements additional portability standards. For example, ints
are always 32-bit, 2's-complemented integers. User interfaces are built through
an abstract window system that is readily implemented in Solaris and other
operating environments.
• Distributed - Java contains extensive TCP/IP networking facilities. Library
routines support protocols such as HyperText Transfer Protocol (HTTP) and
file transfer protocol (FTP).
• Robust - Both the Java compiler and the Java interpreter provide extensive
error checking. Java manages all dynamic memory, checks array bounds, and
other exceptions.
• Secure - Features of C and C++ that often result in illegal memory accesses are
not in the Java language. The interpreter also applies several tests to the
compiled code to check for illegal code. After these tests, the compiled code
causes no operand stack over- or underflows, performs no illegal data
conversions, performs only legal object field accesses, and all opcode
parameter types are verified as legal.
• High performance - Compilation of programs to an architecture independent
machine-like language, results in a small efficient interpreter of Java programs.
The Java environment also compiles the Java bytecode into native machine
code at runtime.
• Multithreaded - Multithreading is built into the Java language. It can improve
interactive performance by allowing operations, such as loading an image, to be
performed while continuing to process user actions.
• Dynamic - Java does not link invoked modules until runtime.
• Simple - Java is similar to C++, but with most of the more complex features of
C and C++ removed.

Java does not provide:

o Programmer-controlled dynamic memory


o Pointer arithmetic
o struct
o typedefs
o #define

Javac - the Compiler


You can use the foundation JDK tools and commands to create and build applications.
The following sections describe the tools and commands that you can use to create and
build applications:

Introducing javac
javac - read Java class and interface definitions and compile them into bytecode and
class files

javac [options] [sourcefiles]


Copy
options Command-line options.

sourcefiles One or more source files to be compiled (such as MyClass.java) or processed


for annotations (such as MyPackage.MyClass).
Description
The javac command reads class and interface definitions, written in the Java
programming language, and compiles them into bytecode class files.
The javac command can also process annotations in Java source files and classes.

A launcher environment variable, JDK_JAVAC_OPTIONS, was introduced in JDK 9 that


prepended its content to the command line to javac.

There are two ways to pass source code file names to javac:

• For a few source files, you can list the file names on the command line.
• For a few source files, you can use the @filename option on the javac command
line to include a file that lists the source file names.

Source code file names must have .java suffixes, class file names must have .class suffixes,
and both source and class files must have root names that identify the class. For
example, a class called MyClass would be written in a source file called MyClass.java:

class MyClass {
public static void main(String[] args) {
System.out.println("this is my class");
}
}
Copy
and compiled into a bytecode class file called MyClass.class:

javac MyClass.java
Copy
MyClass.java
MyClass.class
Copy
Inner class definitions produce additional class files. These class files have names that
combine the inner and outer class names, such as MyClass$MyInnerClass.class.

You should arrange the source files in a directory tree that reflects their package tree.
For example:
• Linux and macOS: If all of your source files are in /workspace, then put the source
code for com.mysoft.mypack.MyClass in /workspace/com/mysoft/mypack/MyClass.java.
• Windows: If all of your source files are in \workspace, then put the source code
for com.mysoft.mypack.MyClass in \workspace\com\mysoft\mypack\MyClass.java.

By default, the compiler puts each class file in the same directory as its source file. You
can specify a separate destination directory with the -d option described in Standard
Options.

What Is jdb ?
You use the jdb command and its options to find and fix bugs in Java platform
programs.
Synopsis
Copy
jdb [options] [classname] [arguments]
options
This represents the jdb command-line options. See Options for the jdb
command.
classname

This represents the name of the main class to debug.


arguments
This represents the arguments that are passed to the main() method of
the class.

Description
The Java Debugger (JDB) is a simple command-line debugger for Java classes.
The jdb command and its options call the JDB. The jdb command demonstrates
the Java Platform Debugger Architecture and provides inspection and
debugging of a local or remote JVM.

Start a JDB Session


There are many ways to start a JDB session. The most frequently used way is
to have the JDB launch a new JVM with the main class of the application to be
debugged. Do this by substituting the jdb command for the java command in
the command line. For example, if your application's main class is MyClass, then
use the following command to debug it under the JDB:
Copy
jdb MyClass
When started this way, the jdb command calls a second JVM with the specified
parameters, loads the specified class, and stops the JVM before executing that
class's first instruction.
Another way to use the jdb command is by attaching it to a JVM that’s already
running. Syntax for starting a JVM to which the jdb command attaches when
the JVM is running is as follows. This loads in-process debugging libraries and
specifies the kind of connection to be made.
Copy
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n MyClass
You can then attach the jdb command to the JVM with the following command:
Copy
jdb -attach 8000

8000 is the address of the running JVM.

The MyClass argument isn’t specified in the jdb command line in this case
because the jdb command is connecting to an existing JVM instead of
launching a new JVM.
There are many other ways to connect the debugger to a JVM, and all of them
are supported by the jdb command. The Java Platform Debugger Architecture
has additional documentation on these connection options.

Breakpoints
Breakpoints can be set in the JDB at line numbers or at the first instruction of a
method, for example:

• The command stop at MyClass:22 sets a breakpoint at the first instruction for
line 22 of the source file containing MyClass.
• The command stop in java.lang.String.length sets a breakpoint at the beginning
of the method java.lang.String.length.
• The command stop in MyClass.<clinit> uses <clinit> to identify the static
initialization code for MyClass.
When a method is overloaded, you must also specify its argument types so
that the proper method can be selected for a breakpoint. For
example, MyClass.myMethod(int,java.lang.String) or MyClass.myMethod().
The clear command removes breakpoints using the following syntax: clear
MyClass:45. Using the clear or stop command with no argument displays a list of all
breakpoints currently set. The cont command continues execution.

Stepping
The step command advances execution to the next line whether it’s in the
current stack frame or a called method. The next command advances execution
to the next line in the current stack frame.

Options for the jdb command


When you use the jdb command instead of the java command on the command
line, the jdb command accepts many of the same options as the java command.
The following options are accepted by the jdb command:
-help

Displays a help message.


-sourcepath dir1:dir2:...

Uses the specified path to search for source files in the specified path. If
this option is not specified, then use the default path of dot (.).
-attach address

Attaches the debugger to a running JVM with the default connection


mechanism.
-listen address

Waits for a running JVM to connect to the specified address with a


standard connector.
-listenany
Waits for a running JVM to connect at any available address using a
standard connector.
-launch
Starts the debugged application immediately upon startup of
the jdb command. The -launch option removes the need for
the run command. The debugged application is launched and then
stopped just before the initial application class is loaded. At that point,
you can set any necessary breakpoints and use the cont command to
continue execution.
-listconnectors

Lists the connectors available in this JVM.


-connect connector-name:name1=value1....

Connects to the target JVM with the named connector and listed
argument values.
-dbgtrace [flags]
Prints information for debugging the jdb command.
-tclient

Runs the application in the Java HotSpot VM client.


-tserver

Runs the application in the Java HotSpot VM server.


-Joption
Passes option to the JVM, where option is one of the options described on
the reference page for the Java application launcher. For example, -J-
Xms48m sets the startup memory to 48 MB. See Overview of Java Options.

The following options are forwarded to the debuggee process:

-v -verbose[:class|gc|jni]

Turns on the verbose mode.


-Dname=value

Sets a system property.


-classpath dir

Lists directories separated by colons in which to look for classes.


-X option

A nonstandard target JVM option.

Other options are supported to provide alternate mechanisms for connecting


the debugger to the JVM that it’s to debug.

What is JavaDoc tool and how to use it?


Last Updated : 01 Nov, 2023

JavaDoc tool is a document generator tool in Java programming
language for generating standard documentation in HTML format. It
generates API documentation. It parses the declarations ad documentation in
a set of source file describing classes, methods, constructors, and fields.
Before using JavaDoc tool, you must include JavaDoc comments
/**………………..*/ providing information about classes, methods, and
constructors, etc. For creating a good and understandable document API for
any java file you must write better comments for every class, method,
constructor.

The JavaDoc comments is different from the normal comments because of


the extra asterisk at the beginning of the comment. It may contain the HTML
tags as well.
// Single-Line Comment

/*
* Multiple-Line comment
*/

/**
* JavaDoc comment
*/
By writing a number of comments, it does not affect the performance of the
Java program as all the comments are removed at compile time.
JavaDoc Format: –
It has two parts: – a description which is followed by block tags.
Some Integrated Development Environments (IDE) automatically generate
the JavaDoc file like NetBeans, IntelliJ IDEA, Eclipse, etc.

Generation of JavaDoc: –
To create a JavaDoc you do not need to compile the java file. To create the
Java documentation API, you need to write Javadoc followed by file name.
javadoc file_name or javadoc package_name
After successful execution of the above command, a number of HTML files
will be created, open the file named index to see all the information about
classes.

JavaDoc Tags

Tag Parameter Description

@author author_name Describes an author

provide information about method parameter or the input it


@param description
takes

@see reference generate a link to other element of the document

@version version-name provide version of the class, interface or enum.

@return description provide the return value

You might also like