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

Advantage of java on c?

For one: you cannot write applets (web-browser-extensions) in C.

Can you declare more than one single main method in java program why?

It doesn't really make sense. The JVM needs to know where to start running the program; that's what the "main" method is for. A class - one that can be run directly - needs to have a single entry point, to avoid ambiguity. This main method can then call any number of other methods.

I assume you can call a second method "main", but using a different signature. However, to avoid confusion, I would recommend you don't do this.

Why are operating systems written in the C language?

Speed, power, efficiency, well supported libraries, generally. Almost everything (But not absolutely everything.) has at least C bindings one can use.

Not to mention you're guaranteed to have the standard C library to handle a great deal of the core functionality of the program.

What is the difference between run time and compile time in c?

Compile time errors are detected at the compilation of a program. These are usually syntactical errors. A program cannot be compiled and hence executed if it contains a compile time error.

for example,

int a b=0;

above statement will produce a compile time error as a and b must be separated by a comma(,).

Runtime errors are logical errors. They don't affect the compilation of the program but causes a program to produce unwanted output. The program becomes buggy.

for example,

sum=sum-a[i];

in above statement, no syntactical error is present and hence the program will get executed successfully. But from a logical point of view, sum was supposed to be the addition of array elements. using minus(-) instead of plus(+) will give unwanted or incorrect output.

What is definite loop?

Definite interations: Repeated sequence of calculations/ operations for a fixed number of repetitions. (Do or For loop) Indefinite iteration: no set limit on iterations, generally "while" loops. multiple interations is the same as multiple repetitions or trials.

How do you write an algorithm for list of names in ascending order?

If they're in an array, use java.util.Arrays.sort(). If they're in a Collection, as in java.util.Collection, use java.util.Collections.sort().

If you want an actual algorithm, try a for-each loop with an equivalence operator and conditional switch.

Is java SE 6 safe to install?

Yes - that's the standard program used to run programs written for the Java technology. Just be sure you get the real Java download, and not some fake - in other words, download from the official Java site, or from a reputable site such as tucows, download.com, etc.

What are static objects in java?

There is no separate entity as a static object in java. The static keyword in java is used to signify that the member (either a variable or a method) is not associated to an object instance of the class. It signifies the fact that the member belongs to the class as a whole. The words static and objects are opposites of one another so you cannot have a static object.

However, you can declare an object as a class level variable which could be referred to as a static object but it will be referred to as a static or class variable and not a static object.

How do you declare a class?

An instance of a class is also known as an object. In the Java language, you use the new operator. Here is an example:

Integer x; // Using the wrapper class, Integer. This doesn't create the object yet.

x = new Integer(5); // This will create the instance.

These commands can be combined into one:

Integer x = new Integer(5);

What is inheritance in JAVA programming?

Inheritance in JAVA programming is the process by which one class takes the property of another class.

The new classes, known as derived classes or subclasses, take over the attributes and behavior of the pre-existing classes, which are referred to as base classes or super classes.

It helps the programmer to re-use the class just by modifying minor objects and methods in it.

class person

{

attribute-name,address

}

class Emp extends person

{

attribute-(same as parent class)name,address

own attribute-salary(modification)

}

Ascending order program for java?

public class BubbleSortAscendingOrderDemo

{

public static void main(String a[])

{

//Numbers which need to be sorted

int numbers[] = {23,5,23,1,7,12,3,34,0};

//Displaying the numbers before sorting

System.out.print("Before sorting, numbers are ");

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

{

System.out.print(numbers[i]+" ");

}

System.out.println();

//Sorting in ascending order using bubble sort

bubbleSortInAscendingOrder(numbers);

//Displaying the numbers after sorting

System.out.print("Before sorting, numbers are ");

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

{

System.out.print(numbers[i]+" ");

}

}

What is the difference between abstract class and normal class?

Any class which has one or more abstract methods is called an abstract class. But in the normal class we can't have any abstract methods.

We cannot create an object for the abstract classes.

When we inherit the abstract class we should implement the abstract method which we inherit.

Every complete statement ends with a?

Any teacher will expect you to answer by saying a semicolon (;), but this is not strictly true. First of all, the definition of a "line of code" varies from teacher to teacher and textbook to textbook. Second, even the Java Language Specification lists several types of Java statements which do not need to end in a semicolon.

In general, a complete Java statement will end in either of semicolon or a closing block brace.

How do you get a java compatible web browser?

Most browsers nowaday are compatible with Java. In some cases you need to install Java as a plug-in. In this case, the browser will usually ask you automatically, whether you want to install Java, as soon as it is needed - i.e., as soon as you access a Web page that requires Java support.

Access specifier in java?

There is no such thing as an access specifier in Java. There are access modifiers.

An Access Modifier is a key word in java that determines what level of access or visibility a particular java variable/method or class has. There are 4 basic access modifiers in java. They are:

1. Public

2. Protected

3. Default and

4. Private

Private is the most restrictive access modifier whereas public is the least restrictive. The default access modifier if unspecified is to allow access to classes in the current package only, except within an interface where the default is 'public'.

How many types are there in java?

The two basic data types in Java are primitives and objects.

Primitives: byte, char, short, int, long, float, double, boolean

Objects: Everything else.

Characteristics of Java?

Java is renouned as one of the most classic OOP engines. OOP or object oriented programming reduces all functions to various tasks of objects. A heirarcy of classes of objects all inherit the knowledge and aptitude of class they "extend". Eventually, every object can be traced back to the class "Object". Java is known as a very common language, with a structure that can be a good starting point to jump to almost any language.

When should a member of a class be declared public?

When the member needs to be accessible from outside of the class. Private members are only accessible from within the class itself, including friends of the class. Protected members are the same as private members but are also accessible to derived classes. Derived classes therefore inherit both the protected and public members of its base classes.

Why you need to declare main method as public static void main what happens if the method as private and non static?

That would require a detailed explanation of each of the keywords involved; if you are just starting to learn Java, suffice it to say that the Java Virtual Machine looks for a method that has that precise signature. As to what happens if you do otherwise, try it out! Probably you will get different error messages, depending on what keywords you omit or change.

What is the difference between is-a relationship and has-a relationship in java?

In database design, object-oriented programming, and knowledge representation, we often describe the relationship between two things as either "is-a" or "has-a" (but not both).

For example,

An avocado "is-a" fruit. (An avocado is a specific kind of fruit. A fruit is a generalization of things like an avocado. An avocado has all the things and characteristics that all fruit have -- an outer skin, an edible flesh, grows on plants, etc.)

An avocado "has-a" seed. (An avocado contains a seed. The seed is one of several parts of an avocado.)

(Many people find this "is-a" term more understandable than the terms "meronym" and "hyponym").

When writing computer programs, confusing these two kinds of relationships is a common source of bugs.

The "is-a" relationship is often represented in a program using "class inheritance", subclasses (and superclasses).

The "has-a" relationship is often represented in a program using a class variable.

The class variable is typically a basic type for exclusive things, such as "birthday".

The class variable is typically a reference to a class as a class variable for shared items, such as "mother".

What does a void method do?

In Java, this keyword is used to specify that the method has no return value.

Is string arr a non primitive data type?

Depends on the context of the question you were asking from, there are 2 distinct answers: Yes and NO.

In the narrowest definition, any array is NOT a primitive data type in C#. Hence a string array is NOT a primitive data type in that context.

A string itself, however, is a primitive data type. Some developers would like to extend the definition of "primitives" into the arrays, collections, and Enumeration. Thus, in this context, an array of string IS a primitive data type.

A java program for calculating telephone bill using inheritance concept?

import java.util.*;

class bill

{

public static void main (String arg[])

{

Scanner in = new Scanner (System.in);

int a,b=0,c=1;

while (c<=6)

{

System.out.print ("nt Enter bill of month no "+c+" = ");

a=in.nextInt();

b+=a;

++c;

}

int avg=b/6;

System.out.println ("nt Average bill = "+avg);

if (avg>5000)

System.out.println ("nt Government will pay ");

else

System.out.println ("nt Paid ");

}

}