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

Can a Java program use one or more command line arguments?

Command line arguments in Java are, as with most programming languages, a way to give information to a program at the point of invoking (starting to run) that program. The information is given in the form of a text string.

Command line arguments are accessible in a Java program as an array of String objects passed into the program's "main" method. Unlike some programming languages (such as C/C++), where the command used to invoke the program is passed into the first array location (index 0) and the arguments subsequently, in Java the first argument occupies index 0.

Command line arguments are a useful way of gathering information from the user when it is likely will know the information at the start of the program. For example, a Java application might copy a file from myFile.txt to myNewFile.txt by running the command "java CopyUtil myFile.txt myNewFile.txt". It is useful to allow such information to be passed in via command line arguments to make the program more scriptable: in other words, more conducive to scripted invocation, through a Desktop shortcut, through a batch file, through a shell script, etc.

What is Chomsky's classification of languages?

I believe it has something to do with the articulatory aspect (as opposed to other's acoustic and perceptual classifications).

> No, it is not. This is a hierarchy of formal grammars that rule the production of (human, computer, nature, etc.) "assertions". This approach is focused on a generative view of the meaningful sentences: each one of those could be generated by rules defined by a grammar, or syntactical rules. The classification is ordered by levels of expressiveness and complexity. See the related link on Wikipedia for further information.

How do you install Java 6?

Depends on the kind of java you want to use. But most java applications require you to have a JVM.

If it java programing developer then you will need java JDK

e.g if you want to use net beans as integrated developing environment(IDE) for java coding you must install JDK first before installing it.

What are the oops concepts in net?

the 4 oops concept are:

1. Encapsulation: The process of wrapping data into a single unit is called Encapsulation

2. Inheritance: This the process in which a properties of a predefined class can be inherited in a new class making the object of that class in the making class.

3. Polymorphism: This the process in which a program can have more than one function with the same name but different parameters.

4. Data Hiding: It is the process of creating a logical insulation between the program and the environment.

How do you search the given word in all files from the directory in java?

The program below will search all non-directory files in the starting directory. If you want to search all subdirectories, you'll have to modify it to recurse a bit.

Note that this will also only do plain text searches of files. It will most likely not find your string in a MS Word .doc file.

Also note that this will not find multiple-line search strings, since it reads and checks one line of the file at a time.

{

final String dirName; // path of directory you want to search

final String str = ""; // string to search for

final File dir = new File(dirName);

for (File f : dir.listFiles()) {

if (!f.isDirectory()) {

System.out.println(f + ": " + fileContains(f, str));

}

}

}

// returns true iff f contains str

private static final boolean fileContains(final File f, final String str) throws IOException {

final BufferedReader in = new BufferedReader(new FileReader(f));

String currentLine;

while ((currentLine = in.readLine()) != null) {

if (currentLine.contains(str)) {

in.close();return true;

}

}

in.close();

return false;

}

Why do you need other programming language other than java?

different languages has different purposes some are low level and some are high level e.g assembly language that is low level(not as a whole) works with machine but java didn't that's why we need other programming languages

What are the situations where overloading function can be an ambiguity?

***Function Overloading and Ambiguity ****

We know that compiler will decide which function to be invoked among the overloaded functions. When the compiler could not choose a function between two or more overloaded functions, the situation is called as an ambiguity in function overloading.

When the program contains ambiguity, the compiler will not compile the program.

The main cause of ambiguity in the program

· Type conversion

· Functions with default arguments

· Functions with pass by reference

Type conversion

#include

using namespace std;

#include

void fun(int i)

{ cout << i;}

void fun(float f)

{ cout << f;}

int main()

{

fun(10);

fun(10.2);

return 0;

}

In this example type conversion creates ambiguity. fun(10) will refer the first function.

We think the value 10.2 is floating point value. So fun(10.2) will refer the second function. But fun(10.2) will refer which function? It could not refer any function. Because 10.2 will be treated as double data type by the compiler. (In c++ all the floating point values are converted by the compiler as double data type.) This is type conversion of float to double. So now compiler could not search the function fun with double data type.

So the compiler will give error message call of overloaded 'fun(double)' is ambiguous.

This example clearly rises the ambiguity in the program because of the type conversion.

Functions with default arguments

#include

using namespace std;

#include

void fun(int i)

{ cout << i;}

void fun(int i, int j=8)

{ cout << i << j;}

int main()

{

fun(10);

fun(10.2f);

return 0;

}

This program will give error message that overloaded 'fun(int)' is ambiguous. Because the fun(int i, int j =8) is a function with default arguments. It can be called in two ways. They are

(i) function with one argument.

fun(2) now the value of i is 2 and j is 8 (8 is the default value).

(ii) function with two arguments fun(5,6). So i is 5 and j is 6.

fun(int i) is a function with one argument. It should be invoked with one argument. So

when we call a function with 1 argument the compiler could not select among the two functions fun(int i) and fun(int i, int j=8).

This example clearly illustrates the ambiguity in the program because of function with default arguments.

Function with reference parameter

#include

using namespace std;

#include

void fun(int i)

{ cout << i;}

void fun(int &i)

{cout <

int main()

{

fun(10);

return 0;

}

This program will show the error message call of overloaded 'fun(int)' is ambiguous.

First fun(int) takes one integer argument and second function fun(int &) takes a reference parameter. In this case, compilers do not know which function is intended by the user when it is called. Because there is no syntactical difference in calling the function between the function with single argument and function with single reference parameter.

So compiler could not decide which function should be invoked when it is called. So this leads ambiguity in the program.

What are the cordinates of java?

Java, one of the main islands of Indonesia, is centered near 7°30′10″ S, 111°15′47″ E and stretches from about 106° E to 114° E , along the northeast edge of the Indian Ocean in southeast Asia. The Indonesian capital of Jakarta is on Java.

What is Polymorphism and inheritance explain with example?

Polymorphism, is an object-oriented programming concept, which relates to the ability to create a variable, function or an object that has more than one form. This allows the object to invoke the correct instance of the variable, function or other object based upon the object type. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.

Here are some links to examples:

C++: http://www.cplusplus.com/forum/beginner/10884/

c#: http://msdn.microsoft.com/en-us/library/ms173152.aspx

Python: http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming

Java: http://www.tutorialspoint.com/java/java_polymorphism.htm

What is serializable class in JAVA?

The serializable interface is used to perform the serialization action. Serialization is the process by which the contents of an object are written to any form of storage - say a flat file. This data stored in the flat file can be de-serialized at any time to create the object.

Ex: public class Test implements Serializable {

…

//lots of code

}

What is the difference between throw and throws in Java?

Throw is used to actually throw the exception, whereas throws is declarative for the method. They are not interchangeable.

public void myMethod(int param) throws MyException

{

if (param < 10)

{

throw new MyException("Too low!);

}

//Blah, Blah, Blah...

} The Throw clause can be used in any part of code where you feel a specific exception needs to be thrown to the calling method.

If a method is throwing an exception, it should either be surrounded by a try catch block to catch it or that method should have the throws clause in its signature. Without the throws clause in the signature the Java compiler does not know what to do with the exception. The throws clause tells the compiler that this particular exception would be handled by the calling method.

How many packages available in java?

A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time. Programmers also typically use packages to organize classes belonging to the same category or providing similar functionality.

· A package provides a unique namespace for the types it contains.

· Classes in the same package can access each other's members.

package is a container in which similar classes are grouped together.

package avoid the redundance of classes. it also provide security to hide the code only by importing the packege which contains the required class.

Difference between base class and derived class?

The derived class derives, or inherits, from the base class. The derived class is like a "child", and the base class, the "parent". The child class has the attributes of the parent class - its variables (those defined at the class level) and methods. Changes done to the parent class (the base class) will affect the child class (the derived class).

What is java command?

A Java application can accept any number of arguments from the command line. This allows the user to specify configuration information when the application is launched.The user enters command-line arguments when invoking the application and specifies them after the name of the class to be run.

What is Keyword Research and Analysis?

Keyword research is important in order to be able to narrow you niche so that there is less competition for your page when it is crawled by the Search Engines. It is just one of many factors that may contribute to higher search engine rankings more traffic.

Google has a free keyword research tool to help you find the best keywords and phrases for your topics.

The best keywords have:

a) high search volume - lots of people searching for that phrase

b) low competition - not too many pages on the web that feature that phrase

What is difference between abstract class and interface in core java give brief answer with example?

Differences:

  1. Abstract class can also contain method definitions but an interface can contain only declarations
  2. All variables in an interface are by default public static and final whereas in Abstract class it is not

An interface can be considered as a pure abstract class that contains no method implementations and contains only declarations.

Reverse of a given string using recursion?

#include <stdio.h>

#include <conio.h>

#include <string.h>

void main()

{

char str[10],temp;

int i,len;

printf("Enter String : ");

scanf("%s",str);

len=strlen(str)-1;

for(i=0;i<strlen(str)/2;i++)

{

temp=str[i];

str[i]=str[len];

str[len--]=temp;

}

printf("%s",str);

getch();

}

Please do give your views on this.

With Regards,

Sumit Ranjan.

Analyst at RMSI Company.

What is a buzz number in java?

A number that ends with 7 and is also divisible by 7 is called buzz number.

How is Java different than any other OOP language lke C plus plus?

There are many differences between Java and other programs, as there are also similarities: - managed code: java does not produce native code, but some byte code that will make it runnable in something called "virtual machine". The best thing about that: compile on windows and deploy that application on UNIX. - full object oriented -- even more than C++ where global variables are possible. Here, in java, everything must take place in an object - works on many operating systems. - a lot of technologies grouped in J2EE, that covers many the aspects of enterprise programming - servlets, jsp, ejb, jdbc to access the database, etc. The list is huge, I don't want to get in too much detail about that.

I guess it features some of the most mature technologies on the market.

Answer to: which programming language is more robust C sharp or Java?While I generally prefer "C" as a more robust language, I also consider anything that is released by Microsoft to be unreliable and likely to fail. Java is the product of Sun Microsystems, and has a very good reputation. While I'm not a Java programmer, I have heard nothing but good reports about Java. Answer to: why is Java more secure than other languagesJava is considered more secure than other languages for several reasons:
  • The Java compiler catches more compile-time errors; other languages (like C++) will compile programs that produce unpredictable results.
  • Java does not allocate direct pointers to memory. This makes it impossible to accidentally reference memory that belongs to other programs or the kernel.
  • ... (can't think of anything else off the top of my head)
Answer to: what is the difference between .net javaThe Major Difference between .Net and Java is

1)Java is a purely Platform independent means the application that will work in any kind of Operating System.But .Net is platform independt software.

2).Net support to develop application in different languages and to develop application Rapidly. This feature is not exist in Java

Answer to why is Java more popular than CA long time ago, many people believed Java was slower than C because Java had to run through a virtual machine. Today however, Time and speed aren't really affected by the programming language or the used technology as much as affected by memory cards capacity and processors speed (Clock rate). Hench programmers and developers started looking for the most powerful yet easy to 'learn and work with' programming language. And there came Java with the multi-platform support, Object oriented methodology and other great capabilities and features.

On the other hand, General Purpose applications are still developed using C++ because it doesn't need any intermediate software to run.

and i think that java it's been improved everyday by the newest releases of the implementation of the virtual machine.

How do you write a program to find whether a number is a perfect square in java?

Example:

int x, y;

x = 5;

y = x * x; // square of x

System.out.println("The square of " + x + " = " + y);

Put all this in your main() method. Most Java IDEs will generate the main() method automatically.

Can you have more than 1 constructor in a class?

Yes. At least in Java, that's possible, as long as the constructors have a different number, or different types of, parameters.

Can a Volatile variable be static also?

Probably; I don't see anything in the standard that says you can't. However, the use of the volatile keyword is usually in embedded code, or multi-threading in which you don't want the compiler to do optimizations on the variable itself.

Yes, sure.

What is integer type array?

An array is a collection of similar data types. An integer array is nothing but a collection of integer data types.

Ex: int a[100], int arr[100][100]

There are several types. 1D array, 2D array, Multi-Dimensional array.

But array is a contiguous allocation. And array size will always be positive. It can be given in the declaration stage or we can specify it dynamically by using malloc function.

Ex: int *a;

a=(int*)malloc(sizeof(int)*HOW_MANY_NUMBERS_YOU_WANT);