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

Do single-quoted string literals have any characteristics difference from those of double-quoted string literals?

The literals with single quotes are Characters and can have a width of only one. Ex: 'y' or 'a' etc

Strings cannot be declared using single quotes. They have to be declared with double quotes.

What are different types of 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. Default is the access protection you get when you do not specifically mention an access modifier to be used for a java object.

Java programming does not run by just a single piece of class that has the whole functionality. You have hundreds of classes that interact with one another, passing data between them and returning output to the user of the system. So it is very important for members of one class to access members of another. Here members may refer to variables, methods and even classes. So, this is where the access modifiers come into picture. The modifier associated with every member of the class determines what level of visibility that member has.

What is a public name?

A public name is a name that is widely recognized and used by the general public, often associated with a brand, organization, or individual. It can serve as a form of identity that distinguishes a person or entity in the public sphere, and may be used in marketing, media, and social contexts. Public names can include stage names, company names, or even pseudonyms that enhance visibility and memorability.

What is the difference between generic collection and non generic collection in java?

Generic collections were introduced in Java 1.5 and since then have become preferable to non-generic collections. A non-generic collection defaults to being a collection of Objects, and in order to effectively use those Objects, you need to cast them as their correct data type during use. A generic collection knows what type of object it contains, and thus no casting is needed.

Difference between single valued and multivalued attribute?

single value attribute is one that holds a single value for a single entity.

example:- name, roll_number...

multivalued attribute is one that holds multiplevalues for a single entities.

example:- degree(phd, mca)

Can a processs BSS segment grow during program execution?

No. The size of the data segment (which includes the BSS) is determined at compile time and cannot change at runtime. The data segment stores all the program's constants, global variables and static variables, the total size of which can be determined at compile time and is therefore fixed at that point. BSS is an abbreviation of Block Start by Symbol and is used specifically to allocate all global and static variables that are either in an uninitialised state or are explicitly initialised to zero. Global and static variables initialised with non-zero values are allocated separately from the BSS, as are all the constants.

What is use of javap command?

The javap command is used to disassemble one or more class files. Its output depends on the options used. If no options are used, javap prints out the package, protected, and public fields and methods of the classes passed to it. javap prints its output to stdout.

For example: javap java.lang.String dumps all the methods for the String class.

How char data type is represented in the memory?

The char data type is a single 16-bit, unsigned Unicode character. It ranges from 0 to 65,535. They are not integral data type like int, short etc. i.e. the char data type can't hold the numeric values. The syntax of declaring a char type variable is shown as:

char caps = 'c';

What is 8478 in the latice method?

Since you did not specify a multiplier, I will use a multiplier of 15 for the purpose of illustrating a problem. So you would set up a lattice with 8478 on top and 15 down the left side. In the second row of the lattice, you would have the following: 0/8,0/4,0/7,and 0/8. The second row of the lattice would be filled in as follows: 4/0, 2/0,3/5,and 4/0. You would then add the diagonal columns, starting with the farthest right. Your answer would be 127,170.

Write a program to reverse a 5 digit number using function?

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

int reversenum(int original);

int main(int argc, char * argv[]){

int numval;

if(argc != 2){

printf("Please specify a number.\n");

exit(1);

}

numval = atoi(argv[1]);

printf("The reverse of %i is %i\n", numval, reversenum(numval));

return 0;

}

int reversenum(int original){

int returnval = 0;

int val = abs(original);

int sign = sgn(original);

while(val > 0){

returnval *= 10;

returnval += val % 10;

original /= 10;

}

returnval *= sign;

return returnval;

}

Which class has implicit instantiation?

All class from package java.lang is implicitly installed.

Why static variables are initialized to zero?

When a variable is declared, your computer assigns a section of memory to that variable. If the variable isn't initialized, there's no way of knowing what data is already stored in that section of memory, which can cause errors in your programs.

In managed languages, such as C#, this is done automatically at declaration. Although it's still good practice to initialize variables yourself.

Write a java program to show following pattern 5 5 4 5 4 3 5 4 3 2 5 4 3 2 1?

// num = the highest number to start with

final int num = 5;

// Go through each value from num through 1.

for (int n = num; n > 0; --n) {

// For each value, print each value from num all the way down to the value.

for (int m = num; m >= n; --m) {

System.out.print(m);

System.out.print(' ');

}

}

What do you do when you receive the command 'Write C code to read input from user and save the input to a sequential file'?

Learn C! :-)

There are several functions in C that can be used to read input from the user, such as getc(), getchar(), and scanf(). Files can be written to using fprintf() and putc(). They can be opened with fopen() and closed with fclose().

Explain what a random number is?

That means that a number is selected randomly from a certain set. For example, if you throw a die, you can randomly get any of the integers from 1 to 6. It is random, because you don't know the result in advance.

That means that a number is selected randomly from a certain set. For example, if you throw a die, you can randomly get any of the integers from 1 to 6. It is random, because you don't know the result in advance.

That means that a number is selected randomly from a certain set. For example, if you throw a die, you can randomly get any of the integers from 1 to 6. It is random, because you don't know the result in advance.

That means that a number is selected randomly from a certain set. For example, if you throw a die, you can randomly get any of the integers from 1 to 6. It is random, because you don't know the result in advance.

Sort the following list using selection sort and insertion sort show the list after each it eration and this is the list 10 6 1 23 56 22 3 17?

The difference between selection sort and insertion sort is simple: selection sort is an in place sort, while insertion sort builds the sorted array one element at a time.

Selection sort:

[10, 6, 1, 23, 56, 22, 3, 17]

[1, 10, 6, 23, 56, 22, 3, 17]//1 is placed in its final correct position

[1, 3, 10, 23, 56, 22, 6, 17]//3 is placed in its final correct position

[1, 3, 6, 23, 56, 22, 10, 17]//6 is placed in its final correct position

[1, 3, 6, 10, 56, 23, 22, 17]//10 is placed in its final correct position

[1, 3, 6, 10, 17, 56, 23, 22]//17 is placed in its final correct position

[1, 3, 6, 10, 17, 22, 56, 23]//22 is placed in its final correct position

[1, 3, 6, 10, 17, 22, 23, 56]//23 is placed in its final correct position

Insertion sort:

[10, 6, 1, 23, 56, 22, 3, 17]

[6, 10, 1, 23, 56, 22, 3, 17]//The first two elements of the list are correctly sorted

[1, 6, 10, 23, 56, 22, 3, 17]//The first three elements of the list are correctly sorted

[1, 6, 10, 23, 56, 22, 3, 17]//The first four elements of the list are correctly sorted

[1, 6, 10, 23, 56, 22, 3, 17]//The first five elements of the list are correctly sorted

[1, 6, 10, 22, 23, 56, 3, 17]//The first six elements of the list are correctly sorted

[1, 3, 6, 10, 22, 23, 56, 17]//The first seven elements of the list are correctly sorted

[1, 3, 6, 10, 17, 22, 23, 56]//The eight elements of the list are correctly sorted

Write a java program to print first 50 palindrome numbers?

Just change the number assigned to P if you want a different number of palindromes:

public class PalindromeNumbers {

public static final int P = 50;

public static void main(String[] args) {

getNums(P);

}

public static void getNums(int n) {

int count = 0, current = 1;

while(count < n) {

if(palindrome("" + current) {

System.out.println(current);

count++;

}

current++;

}

public static boolean palindrome(String s) {

if(s.length() s.charAt(s.length - 1) return palindrome(s.substring(1, s.length - 2)

else return false;

}

}

How do you use char in switch statement?

public class NewClass {

public static void main(String[] arg) {

char grade = 'b';

switch (grade) {

case 'a' : System.out.println("Great Work!");

break;

case 'b' : System.out.println("Good Job!");

break;

case 'c' : System.out.println("Maybe Next Time!");

break;

case 'd' : System.out.println("Try Again!");

break;

case 'f' : System.out.println("No Comment!");

break;

}

}

}

How does a try statement determine which catch clause should be used to handle an exception?

When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exception that was thrown, is executed. The remaining catch clauses are ignored

How do you run a java program form the command prompt?

The command is "java", followed by the class name. For example, if your compiled class is called myclass.class, you give the command:

java myclass