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 method overriding in java?

Method overriding is when a child class redefines the same method as a parent class, with the same parameters.

For example, the standard Java class java.util.LinkedHashSet extends java.util.HashSet. The method add() is overridden in LinkedHashSet. If you have a variable that is of type HashSet, and you call its add() method, it will call the appropriate implementation of add(), based on whether it is a HashSet or a LinkedHashSet. This is called polymorphism.

Method overloading is defining several methods in the same class, that accept different numbers and types of parameters. In this case, the actual method called is decided at compile-time, based on the number and types of arguments. For instance, the method System.out.println() is overloaded, so that you can pass ints as well as Strings, and it will call a different version of the method.

Overriding is an example of run time polymorphism. The JVM does not know which version of method would be called until the type of reference will be passed to the reference variable. It is also called Dynamic Method Dispatch.

Overloading is an example of compile time polymorphism.

C program to generate parkside's triangle numbers?

this program is to generate pascal's triangle #include<stdio.h> #include<conio.h> main() { int n,i,j; clrscr(); printf("enter the number"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=i;j++) printf("%d",j); printf("\n"); } getch(); }

What is platform independent?

ANSWER:

Platform independence means executing a code irrespective of the Operating System on which it is being executed.

Java is called a platform independent language because

# The output of the JAVA compiler is bytecode which is not directly executable. # the bytecode is then interpreted by the JVM on respective OS. The bytecode generated after compilation can be executed on any machine with any OS with the help of JVM.

e.g. U write a simple java program ("samp.java") and compile it, u get a "samp.class" file after compiling without any errors, now you can execute this program on windows OS or Linux or Macintosh which generates the same output and runs fine on all OS.

What loop should no execute if the test expression is false to begin with?

for loop and while loop need the expression to be true for further execution of the program.

How do you identify the character in a string is uppercase?

In order to find whether a character in a string is in uppercase or not, you need to use the ascii\unicode values of the character.

You may want to use the following code--

String str="Your Sample String Here"; //(say you have this string)

int l=str.length();

for(int i=0;i<l;i++)

{

char ch=str.charAt(i);

if(ch>=65&&ch<=90)

//Since the values of block letters in ASCII are from 65 to 90

System.out.println(ch);

}

//This program basically prints out the block letters, but you can modify it as you like, by changing the statement after 'if' as you want

Which take a string as input and find its length?

strlen is the C library function that accepts a pointer to a char array and returns an integer specifying the number of characters (in bytes) of the array. This function is usually not used any more, because it does not support multi-byte characters, such as UTF-8.

Any method in a super class can be overridden in its subclass?

False.

Any method declared as final cannot be overridden by any subclasses.

You also cannot technically override a private method. While your subclass can have a method with the same definition as a private method in the superclass, it does not actually override that method.

What is generic class in java?

Generics allows a type for compile-time type safety means it helps detect errors at compile time and makes your code safe. Generics in Collections are the type of elements which it going to hold. It can be any Wrapper class or any user defined class.

Is it compulsory to write static with void main?

Every C# application is started on the startup class' static Main method. Yes, it must be static, but void is not the only returned type. The 4 signatures:

static void Main();

static void Main(string[] arguments);

static int Main();

static int Main(string[] arguments);

Ideally, there should be one and only one Main method in your application.

What is the difference between null array and an empty array?

There is no null array as such. However, a pointer to an array may be nullified (pointing to zero) before memory is allocated to it, or after that memory is released. But the same is true of any pointer. That is, the pointer is NULL, not what it previously pointed to.

An empty array usually refers to a dynamic array for which no memory has yet been allocated (in other words, a null pointer). However, the term can also apply to static arrays or dynamic arrays that have been allocated memory, where every element is initialised with a value that has no significance. For instance, an array of natural numbers (positive integers greater than 0) might be initialised with the value 0 (a non-natural number) in every element to indicate that the array is empty. By contrast, individual elements could be set to zero to indicate which elements are available (an empty element as opposed to an empty array).

What is the need to create an abstract class without abstract?

Actually there is no need & most importantly - you cannot create an abstract class without using the abstract keyword

What is the fundamental questions would you ask when designing forms and reports?

Without knowing the entire background to the form, can I -your customer- complete it without detailed help text? If not, consider using simpler/more common terms for frields.

Does it make sense considering your database design? If not, reconsider the form or your database.

Is it easy to program? If not, it could be more complex to a customer than you may think, or may be an incorrect way of approaching the problem at least.

Implementing stack operation using array representation with java program?

class MyStack implements Stack

{

private String a[]=new String[10];

private int top=0;

public void push(String value)

{

a[top]=value;

top++;

}

public String pop()

{

top--;

return a[top];

}

public int length()

{

return top;

}

public void print()

{

for(int i=0;i<top;i++)

System.out.println(a[i]);

}

}

public class StackOperations

{

public static void main(String args[])

{

MyStack ms = new MyStack();

ms.push("silpa");

ms.push("arti");

ms.print();

System.out.print("popped element is ");

System.out.println(ms.pop());

System.out.print("Now stack is with: ");

ms.print();

}

}

Why does an abstract class often define methods WITHOUT actually implementing them?

Because, it wants the implementing or child class to take care of the actual implementation details.

Whether sms is connectionless or connection oriented?

I would say it is connectionless, as it sends the message to the person to revive it without establishing the connection first so there's no way to know if they revived it.

How can i check a null at the end of an character array in java?

A character array, by nature, is a primitive-type data array. It can't contain a null value. You cannot cast a char as a null.

char[] charArray = {'1','2','s',null}; //this doesn't compile.

However, if you have an array of Character objects, then it's possible.

Character[] charArray = {'1','2','s',null}; //this DOES compile

A proposed algorithm is to initialize a test boolean as false, then use a for loop to iterate through the array. Set the flag to true (and break the loop) based upon whether one of the objects you run into is null. What you do from there is up to what the rest of your code says.

Why runtime exceptions are not checked at compile time in java?

Compile time error is any type of error that prevent a java program compile like a syntax error, a class not found, a bad file name for the defined class, a possible loss of precision when you are mixing different java data types and so on.

A runtime error means an error which happens, while the program is running. To deal with this kind of errors java define Exceptions. Exceptions are objects represents an abnormal condition in the flow of the program. It can be either checked or unchecked.

How do you determine which is outer loop or inner loop of the Baltimore beltway?

The outer loop goes counter clockwise, while the inner loop goes clockwise. For example, if you're driving from Fairfax, VA to Washington, DC you're going on the inner loop, and on the way back you're taking the outer loop.