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 the difference between honor classes and regular classes?

Honor classes give you college credit, if you are stating from a High School standpoint. If not, honor classes give you more credits than regular classes.

What is a consecutive numbering method?

consecutive numbering method - A method in which consecutively numbered records are arranged in ascending number order - from the lowest number to the highest number.

Define an exception called NoMatchException that is thrown when a string is not equal to Symbiosis Write a Java program that uses this exception?

import java.util.Scanner;

class NoMatchException extends Exception {

static void method() throws Exception{

String s = "India";

String s2 = " ";

try {

if (!s.equals(s2)){

throw new NoMatchException();

//System.out.println("Strings are equal");

}

else {

System.out.println("Strings are equal");

//throw new NoMatchException();

}

}

catch(NoMatchException ne){

System.out.println("Exception Found For String");

}

finally {

System.out.println("In Finally Block");

}

}

}

public class BasicException {

static void myMethod(int x, int y) throws Exception{

try {

if(x < y ) {

System.out.println("Y is greater then X");

throw new Exception();

}

else

System.out.println("Y is smaller");

}

catch(Exception ex) {

System.out.println("exception found");

//System.out.println(ex.toString());

}

finally {

System.out.println("FINALLY block");

}

}

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

Scanner s = new Scanner(System.in);

int d, a, x, y;

System.out.println("Enter the value of x and y");

x = s.nextInt();

y = s.nextInt();

try {

BasicException.myMethod(x , y);

}catch(Exception e) {

System.out.println("main method exception");

System.out.println(e.toString());

}

try {

NoMatchException.method();

}

catch(NoMatchException e) {

System.out.println("Exception Caught");

}

try{

d=0;

a=42/d;

System.out.println("This will not be printed.");

}

catch(ArithmeticException e){

System.out.println("Division by zero.");

}

}

}

What are the different types of variables?

The exogenous ones, which are set by an outside agent, and the endogenous ones, which occur inside a problem.

So if you look at this formula for a wave in one dimension:

y = exp(-jkx), where k = 2pi / lambda

lambda and x are exogenous while k is endogenous (j and pi are constants).

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.

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

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.