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

How do you print 1 121 1331 14641 in c?

#include


#include


void main()


{


clrscr();


for (int i=1;i<=5;i++) // this for loop controls the line


{


for(int

j=1;j<=i;j++) // this for loop controls the values(1,12,123..)


{


printf("%d",j);


}


printf("\n");


}



getch();


}


What are differences between user defined packages and predefined packages in java?

As we know, default package of java.lang.*; is implicitly called if it is not explicitly called Ok, So. Package is Collection Classes ( abstract or interfaces).

Package Creation :-

1 ) First line of the program, in which you want create a package must be a your desired package name starting with package keyword and followed by semicolon.

2 ) While creating package, it is not necessary to write public before each class name.

3 ) But, each and ever method must be public.

Creating or Compiling Package :-

Syntax :-

D:\Practice\Javac -d < Path of program > < .java file name >

Complete Example :-

package TYBCS;

class Mathematics

{

public int addNumbers(int num1,int num2)

{

return(num1+num2);

}

public static double addFloatNum(double num1,double num2,double num3)

{

return(num1+num2+num3);

}

}

class Maximum

{

public int getMaxOutofThree(int n1,int n2,int n3)

{

int num=0;

if(n1>n2 && n1>n3) { num=n1; }

if(n2>n1 && n2>n3) { num=n2; }

if(n3>n1 && n3>n2) { num=n3; }

return num;

}

}

class Practice

{

public static void main(String args[])

{

Mathematics m=new Mathematics();

Maximum mx=new Maximum();

System.out.println("Addition 5+5 : "+m.addNumbers(5,5));

System.out.println("Addition f 2.5+2.5 : "+m.addFloatNum(2.5,2.5,2.5));

System.out.println("Max Number 7, 8 , 1 : "+mx.getMaxOutofThree(7,8,1));

}

}

/*

Output:-

D:\Data>javac -d D:\Data\ Practice.java

D:\Data>java TYBCS.Practice

Addition 5+5 : 10

Addition 2.5+2.5 : 7.5

Max Number 7, 8 , 1 : 8

D:\Data>

*/

What is interface in a compouter?

In Java , Graphical User Interface (GUI) programming. Users interact with modern application programs using graphical components such as windows, buttons, text boxes, and menus. It would be difficult to write a GUI application from scratch. Luckily, most of the work has been done for you in a set of classes called Swing.

What is the source of apis?

In homeopathic medicine, apis is used as a remedy for many symptoms similar to those of bee stings.

Example a program using two dimensional array multiplication table?

#include <stdio.h>

int main() {

int TimesTable[12][12] = { {1,2,3,4,5,6,7,8,9,10,11,12}, {1,2,3,4,5,6,7,8,9,10,11,12} };

int a, b;

for (a = 1; a <= 12; ++a) {

for (b = 1; b <= 12; ++b) {

TimesTable[a][b] = a*b;

printf("%5d", a*b);

}

printf("\n\n");

}

return 0;

}

How is object oriented programming language easier to use than procerdural programming language?

object oriented programing helps better modeling the world as we humans see it, while functional and procedural programming is for the mathematicians P.O.V. harder to maintain the code, and for me , harder to understand imperative(functional) code over side effect code(OOP) OOP is more intuitive by the grasp of the model to the mind, as it stands to help better model the mind, though most developers i have see so far, can really make a good simulation for the world in order for the code to be more coherent. OOP is Object Oriented Programming P.O.V is Point Of View