Next Topic Inheritance-Method Overriding-Abstract Classes Verses Interfaces
1. Explain the features of Java?
Ans:
Java has many advanced features when compared to other programming languages.
Compiled and Interpreted: 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 that is running the Java program. We can thus say that 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 upgrades in operating systems, processors and system resources will not force any changes in Java programs. This is the reason why Java has become a popular language for programming on Internet.
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. Java comes with an extensive set of classes, arranged in packages, that we can use in our programs by inheritance. 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 and run time checking for data types and errors. It provides automatic garbage-collection. Java also allows exception handling to catch runtime errors. Java systems not only verify all memory access but also ensure that no viruses are communicated with an applet. The absence of pointers in Java ensures that programs cannot gain access to memory locations without proper authorization.
Distributed: Java is designed as a distributed language for creating applications on networks. It has the ability to share both data and programs. Java applications can open and access remote objects on Internet. This enables multiple programmers at remote locations to collaborate and work together on a single project.
Simple, Small and Familiar: Java is a small and simple language. Familiarity is another important feature of Java. To make the language look familiar to the existing programmers, it was modeled on C and C++ languages. Java uses many constructs of C and C++ and therefore, Java code "looks like a C++" code. In fact, Java is a simplified version of C++. Multithreaded and Interactive: Multithreaded means handling multiple tasks simultaneously.
Java supports multithreaded programs; This means that we need not wait for the application to finish one task before beginning another. For example, we can listen to an audio clip while scrolling a page and at the same time download an applet from a distant computer.
High Performance: Java architecture is designed to reduce overheads during runtime. Further, the incorporation of multithreading enhances the overall execution speed of Java programs.
Dynamic and Extensible: Java is a dynamic language. Java is capable of dynamically linking in new class libraries, methods, and objects. Java programs support functions written in other languages such as C and C++. These functions are known as native methods. This facility enables the programmers to use the efficient functions available in these languages.
2.What are the steps involved in developing a Java Program?
Ans:
Implementation of a Java application program involves a series of steps. They include:
1. Creating the program
2. Compiling the program
3. Running the program
Creating the Program: We can create a program using any text editor like notepad. But, we need to make sure that the program name should be saved with the extension “.java”. Advisably, the name of the program should match with the name of the public class or a class that has main() method.
Example: assumed that the program name is “Test.java”
class Test
{
public static void main(String as[])
{
System.out.println(“Java Program”);
}
}
Compiling the program: Java program involves two steps for its execution: one compilation and the other execution. We use “javac” tool to compile java program. This yields byte code file whose extension is “.class”. This is an intermediate file and not directly executable.
Syntax: javac Test.java
Running the Program: Now, java program is interpreted by the tool “java” which as an interpreter. This is different for different machines. This tool generates executable code for the machine in use. Thus one can view the output of the java program.
Syntax: java Test The complete steps to run a java program are listed below:
1. Type the program in the DOS editor or notepad. Save the file with a .java extension.
2. The file name should be the same (advisably) as the class, which has the main method.
3. To compile the program, using javac compiler, type the following on the command line: Example: javac Test.java
4. After compilation, run the program using the Java interpreter.
Example: java Test
5. The program output will be displayed on the command line.
3.What are the different data types in Java?
Ans:
Data-type:
Data-type specifies what type of value a variable can store. It also specifies its size. Every variable in Java has a data-type. Java language is rich in its data types. The categories of different data-types are shown below. The two main types are Primitive and non-primitive types.
1. Integer type: An integer type of variables can hold integer constants. Java supports four types of integer data types. They are byte, short, int and long. The following table shows size in bytes and range of values each data type can represent. Integer can be converted to long type by typing ‘L’ after them.
No comments:
Post a Comment