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

What is the difference between single threaded and multithreaded in java?

A single threaded application is one that has only one thread of execution running at any given point of time. Whereas a multi-threaded application can have multiple threads of executing running simultaneously.

Generally in enterprise applications, we need to fetch and load a lot of data before the system starts or initializes. In such cases, we typically spawn multiple threads and let the load operations run in parallel to save time. Lets say you need to fetch 10 different sets of data each of which will run for approximately 1 minute, if you run them all in sequence one by one, your system will load only after 10 minutes. But, if you spawn 10 threads, the system might load in around 2 minutes which is much faster than the single threaded time.

Data abstraction and encapsulation in java?

Abstraction

Abstraction is simplifying complex reality by modelling classes appropriate to the problem, and working at the most appropriate level of inheritance for a given aspect of the problem.

For example, Lassie the Dog may be treated as a Dog much of the time, a Collie when necessary to access Collie-specific attributes or behaviors, and as an Animal (perhaps the parent class of Dog) when counting Timmy's pets.

Abstraction is also achieved through Composition. For example, a class Car would be made up of an Engine, Gearbox, Steering objects, and many more components. To build the Car class, one does not need to know how the different components work internally, but only how to interface with them, i.e., send messages to them, receive messages from them, and perhaps make the different objects composing the class interact with each other.

Encapsulation

Encapsulation conceals the functional details of a class from objects that send messages to it.

For example, the Dog class has a bark() method. The code for the bark() method defines exactly how a bark happens (e.g., by inhale() and then exhale(), at a particular pitch and volume). Timmy, Lassie's friend, however, does not need to know exactly how she barks. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface - those members accessible to that class. The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that are likely to change in future, thereby allowing those changes to be made more easily, that is, without changes to clients. For example, an interface can ensure that puppies can only be added to an object of the class Dog by code in that class. Members are often specified as public, protected or private, determining whether they are available to all classes, sub-classes or only the defining class. Some languages go further: Java uses the default access modifier to restrict access also to classes in the same package, C# and VB.NET reserve some members to classes in the same assembly using keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow one to specify which classes may access any member.

Is the default access specifier same as protected?

A private member of a class can only be accessed by methods of that class.

A protected member of a class can only be accessed by methods of that class and by methods of a derived class of that class.

What is Linear and non linear list in data structure?

Linear : Traversal is linear .. ex: array,linked lists,stacks,queues NoN-linear: Traversal is not linear.. ex:trees,graphs imagine the situation of searching of particular element..in above scenarious..then u will understand easily.. Linear : Traversal is linear .. ex: array,linked lists,stacks,queues NoN-linear: Traversal is not linear.. ex:trees,graphs imagine the situation of searching of particular element..in above scenarious..then u will understand easily.. Linear : Traversal is linear .. ex: array,linked lists,stacks,queues NoN-linear: Traversal is not linear.. ex:trees,graphs imagine the situation of searching of particular element..in above scenarious..then u will understand easily..

How does you set the path of java progrramig?

In Windows:

  • Copy the lib path of the java jdk from where it is installed.
  • Open command promt.
  • Type the following command.

set CLASSPATH=

Example:

C:\>set classpath=C:\Java\jdk1.6.0_03\lib

What do you get when you compile a java program?

The java interpreter or JVM (Java Virtual Machine) is not able to execute the java source code for a program. The java source code first needs to be compiled into bytecode that can be processed by JVM.

Producing bytecode make the program platform independent as each platform has its own JVM. It is also possible to directly write bytecode, bypassing the need to compile, but that would be tedious job and also not good for security purpose as the compiler checks for various errors in a program.

What keyword is used to declare a named constant?

Constant in Java refers to a fixed value that doesn’t change during the execution of a program. The value of constants appears right in a program. It is also known as Literals. We use the constants to create values that assign to variables. Constants can make our program easy to read and understood by others.

Java does not directly support the constant. To define a variable as a constant, We use the “Static” and “Final” Keywords before declaring a variable.

Hope this helps. Thank you

How do you reverse the order of the elements in the array?

Start by pointing to each end of the array. Work your way towards the middle of the array, swapping elements as you go. When the pointers meet or pass each other, the array is completely reversed.

Why is java often termed as a platform?

The word "platform" in this context refers to the environment - the combination of hardware and software - on which a program runs. For example, some programs are designed to work specifically on Intel processors, and on the Microsoft Windows operating system. In the case of Java, programs written in Java are designed to work on a special program called the Java Virtual Machine (JVM) - this would be the platform. Since JVM programs have been created for many operating systems and processors, programs written in the Java language can run on many operating systems as well. You might say that it is "multiplatform", but you might also say that the "platform" is the JVM.

Note that in this case "platform" does NOT refer to the Java programming language, but specifically to the JVM.

Documentation of Hostel management system?

There are a lot of commercial packages that do this; use Google to locate the vendors.

What are the capitalized keywords in java?

public static String capitalizeString(String string) {

char[] chars = string.toLowerCase().toCharArray();

boolean found = false;

for (int i = 0; i < chars.length; i++) {

if (!found && Character.isLetter(chars[i])) {

chars[i] = Character.toUpperCase(chars[i]);

found = true;

} else if (Character.isWhitespace(chars[i]) chars[i]=='.' chars[i]=='\'') { // You can add other chars here

found = false;

}

}

return String.valueOf(chars);

}

How are string variables stored?

Typically as null-terminated character arrays. However, some languages use the first element of the array to store the length of the string rather than a null-terminator to mark the end of the string.

What is a jar file in java?

The Java.io.File class is an abstract representation of file and directory pathnames. Following are the important points about File:

  • Instances may or may not denote an actual file-system object such as a file or a directory. If it does denote such an object then that object resides in a partition. A partition is an operating system-specific portion of storage for a file system.

  • A file system may implement restrictions to certain operations on the actual file-system object, such as reading, writing, and executing. These restrictions are collectively known as access permissions.

  • Instances of the File class are immutable; that is, once created, the abstract pathname represented by a File object will never change.

Difference between array and pointers in c plus plus?

A pointer is simply a variable that can store a memory address and has the same purpose in both languages. The only real difference is that C++ pointers can point at objects (instances of a class) and indirectly invoke their methods, whereas pointers in C (which is not object oriented) cannot.

What are the uses of logical operators in Java?

Logical Operators are those that are used for doing logical operations. There are a total of 6 logical operators (&, |, ^, !, &&, and ‖)

Of the six logical operators listed above, three of them (&, |, and ^) can also be used as "bitwise" operators.

There are two non-short-circuit logical operators.

• & non-short-circuit AND

• | non-short-circuit OR

There are two short-circuit logical operators

• && short-circuit AND

• short-circuit OR

What is the array of 9?

it's to do with the structure of cilia and microtubules

How does virtual function support run time polymorphism?

Virtual functions are used to suport runtime polymorphism.In C++,if we have inheritance and we have overridden functions in the inherited classes,we can declare a base class pointer and make it to point to the objects of derived classes.When we give a keyword virtual to the base class functions,the compiler will no do static binding,so during runtime ,the base class pointer can be used to call the functions of the derived classes.Thus virtual functions support dynamic polymorphism.

How constructor called?

You cannot invoke a constructor explicitly. It will get invoked implicitly when you call the new keyword on the class to create an object of the class.

Ex:

private ClassExample obj = new ClassExample();

here this new keyword usage on the ClassExample class will invoke the constructor of this class and create an object of that class.

What are the IDEs for Java?

Yes. There are many IDE's available for developing java programs/applications. Some are: 1. Eclipse 2. Net Beans 3. IBM WSAD - Websphere Studio Application Developer 4. IBM RAD - Rational Application Developer Etc..

Can you program micro-controllers using Java language?

its like c programming on pic microcontroller...

[EDIT 7/31/2012]

Well, it is not really the same as programming C. C is compiled and runs on the metal and Java is interpreted and runs in a sandbox. Completely different. The answer to the question is yes, you can. JwiK™ is an open source Java VM for 8 bit microcontrollers and is designed to work on micros without a decent stack: ie. 8051 and PIC.

What does a Java programmer do?

Java is a programming language originally developed by Sun Microsystems and released in 1995 as a core component of Sun's Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode which can run on any Java virtual machine (JVM) regardless of computer architecture. There were five primary goals in the creation of the Java language. It should use the object-oriented programming methodology. # It should allow the same program to be executed on multiple operating systems. # It should contain built-in support for using computer networks. # It should be designed to execute code from remote sources securely. # It should be easy to use by selecting what were considered the good parts of other object-oriented languages.

What is the component of pluggable look and feel in java?

"Pluggable look and feel" refers to the ability to change the look and feel (LnF) of a Java program on the fly. The term is actually quite descriptive. If you change the LnF of your program, all GUI elements will have a distinctly different look to them. Windows will be drawn differently, buttons and scroll bars will look (and may respond) differently, etc.

You can change the current LnF by invoking:

UIManager.setLookAndFeel(lookAndFeel);

Probably the most useful invocation of this method uses the UIManager class to figure out what the underlying operating system is, and to use the default LnF for your program:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

This will make programs run on a Windows machine look like a Windows application, programs run on a Mac look like a Mac application, etc.

Another useful function is the UIManager.getInstalledLookAndFeels(), which will return an array of all available LnFs.

Below is a simple sample program which will demonstrate these methods.

Two things to take note of:

# Once you change the look and feel, you need to call the updateUI method on all JComponents. The good people at Sun recommend calling SwingUtilities.updateComponentTreeUI(Component). If you call this on your top level components (main frame/window), it should update all components contained within it. # UIManager.setLookAndFeel can throw a lot of exceptions. Be prepared to have a large try-catch block (or a throws clause) everywhere you set the LnF.

try {

// Start off with the system default LnF

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

// Ugly, ugly try-catch block if you catch each type individually.

} catch (final ClassNotFoundException ex) {

} catch (final InstantiationException ex) {

} catch (final IllegalAccessException ex) {

} catch (final UnsupportedLookAndFeelException ex) {

} catch (final ClassCastException ex) {

}

// Create our frame

final JFrame frame = new JFrame("LnF Test Frame");

// Set up our simple panel

final JPanel panel = new JPanel();

panel.setLayout(new GridLayout(4, 4));

// Set up a button for each installed LookAndFeel.

// When a button is pressed, the LnF will change.

for (final LookAndFeelInfo lnfInfo : UIManager.getInstalledLookAndFeels()) {

final String lnfName = lnfInfo.getName();

final String lnfClassName = lnfInfo.getClassName();

final JButton button = new JButton(lnfName);

button.addActionListener(new ActionListener() {

// Here's where we change and update the LnF

public final void actionPerformed(final ActionEvent ev) {

try {

UIManager.setLookAndFeel(lnfClassName);

SwingUtilities.updateComponentTreeUI(frame);

} catch (final Exception ex) {

}

}

});

panel.add(button);

}

// Set up and display our frame

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// (adding a scroll panel just to see some more components)

frame.setContentPane(new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS));

frame.setSize(300, 300);

frame.setVisible(true);

What is difference between Adapter class and listeners in java?

An Adapter class is just a "blank" implementation of a Listener interface. They're convenience classes made so you don't need to implement all of the methods of an interface.

A good example is the MouseListener interface. Let's say you want to detect when a user clicks on your Component. You only need to implement the mouseClicked method to get that part working. This will leave you with...

public void mousePressed(MouseEvent e) {

}

public void mouseReleased(MouseEvent e) {

}

public void mouseEntered(MouseEvent e) {

}

public void mouseExited(MouseEvent e) {

}

...at the end of your implementation. Ugly. So Java gives us the MouseAdapter class (which gives us the same empty implementations as above). We can use this in place of a MouseListener to try to keep our code cleaner.

Write program java explain use abstract class multilevel inheritance?

Multilevel inheritance is a java feature where the properties of a class are inherited by a class which extends one or more classes which extend its features...

Example:

public class A {

public String getName(){

return "Vijay";

}

}

public class B extends A {

public int getAge() {

return 24;

}

}

public class C extends B {

public String getAddress(){

return "Utter Pradesh,INDIA";

}

}

public class D extends C {

public void print {

System.out.println(getName());

System.out.println(getAge());

System.out.println(getAddress());

}

}

This method would print the following in the console:

Vijay

24

Pradesh,INDIA

Here in class D you are calling methods that are available inside classes A, B & C. Though D extends only class C, it would in turn inherit the properties of the classes extended by C and its parents.

This is multi level inheritance.