answersLogoWhite

0

📱

Java Programming

The Java programming language was released in 1995 as a core component of the Java platform of Sun Microsystems. It is a general-purpose, class-based, object-oriented language that is widely used in application software and web applications.

5,203 Questions

Object oriented advantages?

nAbility to tackle challenging problems

nImproved communication between users, analysts, designers, and programmers

nIncreased consistency in analysis, design, and programming

nExplicit representation of commonality among system components

nSystem robustness

nReusability of analysis, design, and programming results

What are the advantages of Java programs?

Here we list some of the major benefits that Java can provide for general science and engineering applications:

  • Platform Independence
    Scientists use more types of computers and OS's that most other groups. Code that can be exchanged without requiring rewrites and recompilation saves time and effort.

  • Object Oriented
    Besides the usual benefits from OOP, many scientific programs can benefit from thinking in terms of objects. For example, particles in a scattering simulation are naturally self-contained objects.

  • Threading
    Multi-processing is very useful for many scientific tasks, such as, for example, simulations of phenomena where many processes occur simultaneously.

  • Networking
    Java comes with many networking capabilities that allow one to build distributed systems. Such capabilities can be applied, for example, to remote data taking from sensors.

  • Embedded Applications
    The original Oak language from which Java derived was intended for embedded applications. Platform independence and the other items mentioned above, as well as the adaptability of Java that allows it to work on micro-sized platforms by shedding nonessential code, has made Java very popular for use in embedded devices such as smart cards and cell phones. It can thus also be embedded into sensors, controllers, and other types of engineering and scientific devices. See Chapter 23 for more discussion about this.

  • Distributed Computing
    In chapters 16-20 we will examine how Java can effectively distribute computational power over many systems and use this capability to tackle tough scientific and engineering analysis problems.

  • Interfacing & Enhancing Legacy Code
    Java's strong graphics and networking capabilities can be applied to existing C & Fortran programs. There have been mountains of very important and complex programs, especially for numerically intensive tasks, created over the decades in these languages and it would be too expensive to reprogram them in a different language.

    Java, however, can connect to such programs and bring to them new capabilities. For example, a Java graphical interface can bring enhanced ease of use to a Fortran or C program, which then acts as a computational engine behind the GUI.

    Similarly, Java's networking features can bring far greater accessiblity to these programs.

What is the difference between entry and exit controlled loops - in Java?

while loop and for loop are entry controlled loops as they check looping condition at the entry point.

do while loop is exit controlled loop as it checks looping condition at exit point.

shreeradha@yahoo.com

What is the general syntax of a default constructor?

There is no such thing as 'the general syntax of a default constructor'. A default constructor is one that is generated by the compiler if you don't specify any constructors at all. Semantically speaking, it is public and takes no arguments, but this is not 'syntax'.

What is a downcall?

The term upcall is typically used in the context of using a framework, such as CORBA. When a request is sent from a client application to a server application, the framework is responsible for data marshalling, data transmission, and notification of the recipient that a request has been issued. An upcall is the call into the user code from the framework. This is typically supported through the use of a registered callback function registered either directly by the user, or indirectly through the mechanisms of the framework. An upcall is also called a callback.

What is the difference between Java and Java bean?

Answer

Mostly the java class and the Bean class are similar one.

In Bean class we have getter and setter methods.

Its just a naming convention.

Regards

Santhosh rao


In

http://forums.sun.com/thread.jspa?threadID=526214

Java Beans follow the Bean conventions:

(1) Default, no-arg ctor,
(2) Serializable,
(3) getX()/setX() or isX()/setX() naming convention for read/write access to private data member X,
(4) Can use java.bean.PropertyChangeEvent to notify interested parties when values change.
(5) Can use java.bean.PropertyChangeListener to register for notification when a particular property changes.

"Normal" Java classes aren't required to follow any of these conventions.

There's a great [url=http://java.sun.com/docs/books/tutorial/javabeans/]tutorial[/url] on Java Beans from Sun.

What is the role of a technical support engineer?

The role of a technical support engineer is to plan analyze the program of the each profile plan, as per standard engineering requirements, specification of the project.

What is threading and multi-threading?

Multithreading computers have hardware support to efficiently execute multiple threads. These are distinguished from multiprocessing systems (such as multi-core systems) in that the threads have to share the resources of single core: the computing units, the CPU caches and the translation lookaside buffer (TLB). Where multiprocessing systems include multiple complete processing units, multithreading aims to increase utilization of a single core by leveraging thread-level as well as instruction-level parallelism. As the two techniques are complementary, they are sometimes combined in systems with multiple multithreading CPUs and in CPUs with multiple multithreading cores. Currently only Pentium 4's and i7's can use multithreading.

Answer

The above answer confuses the hardware concept of simultaneous execution with the Operating system concept of threads.

Multi-threading is an Operating System concept, and is independent of any hardware support. Threads (also known as lightweight processes), are a concept where a single program process can have more than one line of execution. A normal process has two portions in memory: its code portion, and its data portion. The code portion is the actual instructions which detail the flow of program, while the data portion are the values that this code flow operates on. You can think of the code portion as filled with algorithms (i.e. X + Y = Z ), and the data portion as containing the values to use in those algorithms (i.e. X = 3, Y = 5, and a place to store the value of Z when it is calculated).

Certain Operating Systems (indeed, practically all modern ones), support the concept of a thread. A thread is a separate line of executing in a process - that is, it shares the code portion of the process with other threads in that process, but has its own unique data. This is useful when a program wants to execute a bunch of similar things on different data. For example: I want to apply a filter algorithm to a bitmap picture. Using threads, the code portion of the process (which contains the algorithms to use) can be shared by several threads, but each thread operates on different data (each pixel in the bitmap).

Multi-threading is the concept of writing a program to be able to execute these multiple lines of executing on different data, all within the context of a single process. Thus, multi-threading requires support from the Operating System, proper system libraries to call the thread-specific functions from, and a program which has been written to use these concepts.

Multiprocessing is also an operating system concept, where the OS has the ability to appear to run multiple processes simultaneously; in reality, what is known as time-slicing provides this illusion. All OSes now have the ability to multi-process. Multiprocessing does not require any special effort on the application programmer's part.

Hyperthreading is a hardware concept, and is what is described in answer #1 above. Operating systems do NOT need to understand hyperthreading to take advantage of it (though, if they do, they can be more efficient). Programs are completely unaware of such hardware features.

Indeed, these days, it is entirely possible to run a multithreaded program on a multiprocessing Operating System, which itself is being run on a hyperthreading CPU.

Multithreading is the ability of an operating system to execute different parts of a program, called threads,simultaneously. The programmer must carefully design the program in such a way that all the threads can run at the same time without interfering with each other.

Answer

Taking a computer job/process, and coding it so the job utilizes multiple resources for execution, this finishing faster.

Example: A machine has 16 processors and the job uses all 16 processors to process.

How do you call an abstract class from main method?

An abstract class cannot have a constructor and hence you cannot invoke the constructor of the class - i.e., you can instantiate an abstract class and hence you cannot call the constructor of an abstract class.

What is finally block in java?

The Finally block in java is used along with the try-catch statements.

The usual structure is

try {

.....

} catch(Exception e){

....

} finally {

.....

}

In the finally block we usually have code that is used to perform clean up activities corresponding to the code in the try block. When an exception occurs in the try block control comes to the catch block and the rest of the code in the try block would not execute. In such cases we may need to have some code that cleans up the objects that we created/used in the try block.

No matter what happens, the code inside the finally block would definitely execute.

The best use of finally block is when we are connecting to the database. In the try block we would have the statements that instantiate the connection, prepared statement, result set etc. If the query fails then all these objects would be left open and the code would continue. So in the finally block we usually nullify these statements so that even in case of an error the unused objects are cleared.

Example:

Connection con;

PreparedStatment PS;

ResultSet rs;

try{

con = ConnectionManager.getConnection();

PS = con.prepareStatement(query);

rs = PS.executyQuery();

......

} catch (Exception e){

e.printStackTrace();

} finally {

con.close();

PS.close();

}

In case of an error the connection & prepared statement objects would remain open if we do not have the finally block.

Tip: Whatever code we have inside the finally block would be run definitely if the try block is invoked. We can even use the finally block to check if the try block was reached and executed. If the try executes then we can rest assured that the finally would also get executed.

What is the difference between class and classes?

Class's = the possessive form of the singular noun class.

Classes' = the possessive form of the plural noun classes.

Examples:

The class's pet frog was called Robert. (one class had a pet frog called Robert)

All of the classes' students were at the assembly. (the students from all classes were at the assembly)

What does the modulus operator in Java do?

It is an binary arithmetic operator which returns the remainder of division operation. It can used in both floating-point values and integer values.

opLeft % opRight where, opLeft is the left operand and opRight is the right operand. This expression is equivalent to the expression opLeft - ((int) (opLeft / opRight) * opRight)

The name of a Java program file must match the name of the class with the extension java?

not exactly..... only If your class is public then the java program name should be the public class name with extension Sample.java >> public class Sample { public static void main(String[] args) { ..... } } NonPublicClass.java class SomeOtherName { ......... }

Benefits of object oriented programming?

1. Testability/Increased Quality (automated testing can increase speed of testing and increase quality) 2. Code re-use (Polymorphism, Generics, Interfaces) 3. Code extensibility 4. Catch errors at compile time rather than at runtime. 5. Maintainability: If designed correctly, any tier of the application can be replaced by another that implements the correct interface(s), and the application will still work (can use multiple user interfaces, can swap out data providers, etc.). 6. Reduces large problems to smaller, more manageable ones. 7. Fits the way the real world works. It is easy to map a real world problem to a solution in OO code.

Difference between classification and prediction?

The decision tree is a classification model, applied to existing data. If you apply it to new data, for which the class is unknown, you also get a prediction of the class. The assumption is that the new data comes from the similar distribution as the data you used to build your decision tree. In many cases this is a correct assumption and that is why you can use the decision tree for building a predictive model.

What are object wrappers?

Wrapper classes are classes that are used to make primitive variables into objects, and to make wrapped objects into primitives. int, boolean, double are all primitive data types and their respective wrapper classes are Integer, Boolean, and Double. Wrapper classes are useful in storing primitive data types in higher level data structures such as Stack<Object>, List<Object>, Queue<Object>, since primitives cannot be directly placed in these data structures they must be boxed in the wrapper classes. But, here's the good news, with the new Java 5.0, there is no need no worry about wrapper classes and boxing and unboxing (unless it's something taught in class), since there is auto-boxing and unboxing, therefore, one can directly "add" primitives to a data structure and let the JVM do the rest.

Difference between highlevel programming language and low level programming language and middle level programming language?

High level programming is drag & drop, easy peasy programming. In the objects you use to create something ( program, graphics). The components are made up of middle level programming. A language that is easier to remember than zeros & one's...which is a low-level language that integrated chips use to work.

Define and give three examples of primitive data types?

A primitive variable can be one of eight types: char, boolean, byte, short, int, long, double, or float. Once a primitive has been declared, its primitive type can never change, although in most cases its value can change. they are used to store values like name, age, salary etc.

Can you overwrite main function in java?

You can not overwrite a static method in Java,and 'main' is a static method.so,you can't overwrite the 'main'.

What do you mean by java?

Core java refers to the core or basic concepts of the Java programming language. Things like encapsulation, inheritance, multi-threading, exception handling and other basic feature of java that comes as part of the Java standard edition forms Core Java

Import statement in java?

import PackageName.SubPackage.ClassName.SubClass;

or

import PackageName.SubPackage.*; \\ this will import any class in the package

note : it's very simple, consider the packages are like folders, as the are.

Difference between inheretance and polymorphism in java?

This can be a confusing topic because one can argue that sharing method attributes between a super or abstract class with a derived class could be described by either Polymorphism or Inheritance. One significant differerence could be illustrated as to when or under what circumstances you would you use one or the other. An ideal instance of using Inheritance would be when you want to create an entirely new class, but wish to borrow a group of existing attributes or methods resident in an existing Abstract or super Class, instead of re-inventing the wheel. If you had an Abstract Class Carnivore and wanted to create a subclass Cat, you could instantly inherit all the methods that were common in Carnivore that applied to Cat without writing new code. Polymorphism could be best applied when you had an existing SubClass that you wanted to modify or add a feature that could borrow a method that existed in a higher class. Take the Cat subclass, which inherited attributes from Carnivore, and you wanted to add the method Stalk, which would generically describe how a carnivore approaches its prey. However its implementation in Cat would detail the stealth it uses that are unique to a Cat.