(Cover pg)

__Narinder Kumar_________________________

Registration No:

Ans:- Features of Java:

1) Java is a simple language that can be learned easily, even if you have just
started programmin...
variables, and their methods are declared without any body. In practice, this means
that you can define interfaces which d...
among processes and threads through an OS feature called time slicing.
Processes: A process has a self-contained execution...
Upcoming SlideShare
Loading in...5

MC0078 SMU 2013 Fall session


Published on

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

MC0078 SMU 2013 Fall session

  1. 1. (Cover pg) ASSIGNMENT- FALL 2013 Name: __Narinder Kumar_________________________ Registration No: __511225739_____________________________ Learning Center: __Artex Informatic_________________________ Learning Center Code: __1688__________________________________ Course: __MCA__________________________________ Subject: __ JAVA PROGRAMMING__________________ Semester: ___IV___________________________________ Subject Code: ___MC0078______________________________ Date of submission: ___30 November 2013______________________ Marks awarded: ________________________________________ Directorate of Distance Education Sikkim Manipal University II Floor, Syndicate House Manipal – 576 104 Signature of Coordinator Signature of Center Q1:- List ten features of JAVA Signature of Evaluator
  2. 2. Ans:- Features of Java: 1) Java is a simple language that can be learned easily, even if you have just started programming. 2) A Java programmer need not know the internal of Java. The syntax of Java is similar to C++. Unlike C++, in which the programmer handles memory manipulation, Java handles the required memory manipulations, and thus prevents errors that arise due to improper memory usage. 3) Java defines data as objects with methods that support the objects. Java is purely object-oriented and provides abstraction, encapsulation, inheritance and polymorphism. Even the most basic program has a class. Any code that you write in Java is inside a class. 4) Java is tuned of Web. Java programs can access data across the Web as easily as they access data from a local system. 5) Java is both interpreted and compiled. The code is compiled to a byte code that is binary and platform independent. 6) When you compile a piece of code, all the errors is listed together. You can execute only when all the errors are rectified. An interpreter, on the other hand, verifies the code and executes it line by line. 7) Compilation is the process of converting the code that you type, into a language that the computer understands- machine language. When you compile a program using a compiler, the compiler checks for syntactic errors in code and list all the errors on the screen. 8) Byte code is the result of compiling a Java program. You can execute this code on any platform. In other words, due to the byte code compilation process and interpretation by a browser, Java programs can be executed on a variety of hardware and operating systems. The only requirement is that the system should have a Java-enabled Internet browser. 9) Java forces you to handle unexpected errors. This ensures that Java programs are robust (reliable), and bug free and do not crash. 10) You can create multithreading programs using Java. The core of Java is also multithreaded. Q2:- Write short notes on packages and Interfaces in JAVA Ans:- Packages: In the preceding section, the name of each example class was taken from the same name space. This means that a unique name had to be used for each class to avoid name collisions. After a while, without some way to manage the name space, you could run out of convenient, descriptive names for individual classes. You also need some way to be assured that the name you choose for a class will be reasonably unique and not collide with class names chosen by other programmers. Thankfully, Java provides a mechanism for partitioning the class name space into more manageable chunks. This mechanism is the package. The package is both a naming and a visibility control mechanism. You can define classes inside a package that are not accessible by code outside that package. You can also define class members that are only exposed to other members of the same package. This allows your classes to have intimate knowledge of each other, but not expose that knowledge to the rest of the world. Interface: Using the keyword interface, you can fully abstract a class' interface from its implementation. That is, using interface, you can specify what a class must do, but not how it does it. Interfaces are syntactically similar to classes, but they lack instance
  3. 3. variables, and their methods are declared without any body. In practice, this means that you can define interfaces which don't make assumptions about how they are implemented. Once it is defined, any number of classes can implement an interface. Also, one class can implement any number of interfaces. To implement an interface, a class must create the complete set of methods defined by the interface. However, each class is free to determine the details of its own implementation. By providing the interface keyword, Java allows you to fully utilize the "one interface, multiple methods" aspect of polymorphism. Q3:- What is the difference between errors and exceptions? What are the different types of Exception? Ans:- Definition of an Exception: The term exception denotes an exceptional event. It can be defined as an abnormal event that occurs during program execution and disrupts the normal flow of instruction. Error-handling becomes a necessity when you develop applications that need to take care of unexpected situations. If an above-mentioned situation is encountered, a program may stop working. You cannot afford to have an application stop working or crashing, if the requested file is not present on the disk. Exception Classes: Common Exceptions Java has several predefined exceptions. The most common exceptions that you may encounter are described below. � Arithmetic Exception This exception is thrown when an exceptional arithmetic condition has occurred. For example, a division by zero generates such an exception. � Null Pointer Exception This exception is thrown when an application attempts to use null where an object is required. An object that has not been allocated memory holds a null value. The situations in which an exception is thrown include: a) Using an object without allocating memory for it. b) Calling the methods of a null object. c) Accessing or modifying the attributes of a null object. � ArrayIndexOutOfBounds Exception The exception ArrayIndexOutOfBounds Exception is thrown when an attempt is made to access an array element beyond the index of the array. For example, if you try to access the eleventh element of an array that’s has only ten elements, the exception will be thrown. Q4:- What are the differences between a process and a thread? Ans:- Processes and Threads: In concurrent programming, there are two basic units of execution: processes and threads. In the Java programming language, concurrent programming is mostly concerned with threads. However, processes are also important. A computer system normally has many active processes and threads. This is true even in systems that only have a single execution core, and thus only have one thread actually executing at any given moment. Processing time for a single core is shared
  4. 4. among processes and threads through an OS feature called time slicing. Processes: A process has a self-contained execution environment. A process generally has a complete, private set of basic run-time resources; in particular, each process has its own memory space. Processes are often seen as synonymous with programs or applications. However, what the user sees as a single application may in fact be a set of cooperating processes. To facilitate communication between processes, most operating systems support Inter Process Communication (IPC) resources, such as pipes and sockets. Threads: Threads are sometimes called lightweight processes. Both processes and threads provide an execution environment, but creating a new thread requires fewer resources than creating a new process. Threads exist within a process every process has at least one. Threads share the process's resources, including memory and open files. This makes for efficient, but potentially problematic, communication. Q5:- a) Write Java program to print the address of the study center. b) Write a Java program to find the sum of 1+3+5+…. for 10 terms in the series. Ans:- a) Write Java program to print the address of the study center.