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 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.

How to add a character to a string in java?

Reading text from the console in Java is easy--if you know the language.

Here's one way, you can create a class with the following code:

import java.io.*;

class lineScanner {

private static String prompt;

public lineScanner(String aPrompt) {

setPrompt(aPrompt);

}

public void setPrompt(String aPrompt) {

prompt=aPrompt;

}

public static String lineIn() throws IOException {

String CurLine = "";

System.out.println(prompt);

InputStreamReader converter = new InputStreamReader(System.in);

BufferedReader in = new BufferedReader(converter);

CurLine = in.readLine();

return CurLine;

}

}

This class can be used to create an object that reads text. Here's how it works:

create the object by using

lineScanner in = new lineScanner("a string");

And by using the lineScanner object you've just created, you can input the text like this:

string1 = in.lineIn();

This will set the variable named string1 to text that is entered from the keyboard. When you have tried this out, you may have realized that the computer displays a short prompt message, "a string", when text is inputted.

This is because when the object created, the message was set to "a string" by the constructor. You can change this message after it is set using

in.setPrompt("a different string);

If you want to see the program in action, create another class with the following code:

import java.io.IOException;

/**

* @author yourName

*/

public class mainClass {

/**

* @param args

* @throws IOException

*/

public static void main(String[] args) throws IOException {

lineScanner in = new lineScanner("Please enter a line.");

String inBuffer = null;

while (inBuffer != "exit") {

inBuffer = in.lineIn();

System.out.println("You entered: " + inBuffer);

}

}

}

Why to use overriding in java?

Overriding is closely connected to polymorphism. Redefining method is similar to Overriding but you cannot expect those redefined methods to deliver polymorphism.

The concept of redefining is used when it involves static methods.

When is update method called?

Whenever a screen needs redrawing (e.g., upon creation, resizing, validating) the update method is called. By default, the update method clears the screen and then calls the paint method, which normally contains all the drawing code.