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

Coding of calculator programme using switch case in java?

import java.io.*;


public class calculator{
public static void main(String[] args) throws Exception{
int x, y;
BufferedReader b = new BufferedReader(new InputStreamReader(System.in)) ;
System.out.println("Enter two numbers for operation:");


x = Integer.parseInt(b.readLine());
y = Integer.parseInt(b.readLine());
System.out.println("1. Add");
System.out.println("2. Subtract");
System.out.println("3. Multiply");
System.out.println("4. Divide");
System.out.println("enter your choice:");
int a= Integer.parseInt(b.readLine());
switch (a){
case 1:
System.out.println("Enter the number one=" + (x+y));
break;
case 2:
System.out.println("Enter the number two=" + (x-y));
break;
case 3:
System.out.println("Enetr the number three="+ (x*y));
break;
case 4:
System.out.println("Enter the number four="+ (x/y));
break;
default:
System.out.println("Invalid Entry!");
}






}
}

Write a program to display a table of 5?

#include <stdio.h>

#include<conio>

void main ()

{int a,i:,

printf("\n The Multiplication table of 5 is n"):,

For(i=1;i=20;i++)

Printf("%d",a*i);

getch();

}

Who discover java?

Java was originally developed by James Gosling at Sun Microsystems.

How much storage data exists today in characters or bytes?

It is impossible to conjure an accurate number. However, an assumption was made with the Digital Universe Study found in the related link, stating there were an estimated 1.8 Billion Terabytes in existence.

Create a program in java that will accept 2 strings and display in concatenated form?

class demo {

public static void main(String[] args) { if(args.length == 2) {

System.out.println(args[0] + args[1]);

} else {

System.out.println("Usage: demo Str1 Str2");

}

}

What is the magic behind good typing?

Just pay attention to the keyboard at all times and pay attention to your teacher

That goes for people in middle school

When a subclass can call a parent's class constructor?

A subclass invokes its base class constructor at the point of instantiation. That is; you cannot instantiate a subclass object without first constructing its base class, which is done automatically.

Who inverted the java?

java was invented by james gosling.

What is an anonymous class?

An anonymous class is a local class without a name. An anonymous class is defined and instantiated in a single succinct expression using the new operator. While a local class definition is a statement in a block of Java code, an anonymous class definition is an expression, which means that it can be included as part of a larger expression, such as a method call. When a local class is used only once, consider using anonymous class syntax, which places the definition and use of the class in exactly the same place.

New Syntax for Anonymous Classes

We've already seen examples of the syntax for defining and instantiating an anonymous class. We can express that syntax more formally as: new class-name ( [ argument-list ] ) { class-body }

or: new interface-name () { class-body }

For an if then else loop how do you include more than one condition?

You can combine more than one condition with AND or with OR. How this is written depends on the particular programming language.

You can also have several cases; example in Java:

if (condition1)

{

command1;

}

else if (condition2)

{

command2;

{

else

{

command3;

}

Does the derived class take the memory of base class in inheritance?

Yes, the derived class includes the memory of the base class. The derived class inherits everything in the base class, data and function, and provides additional data and function as needed.

What is the ' ' called in java?

' ' would be the character for a space in Java.

What is the difference between java ring and smart card?

iButtons have an advantage over conventional smart cards in term of durability and longevity.

iButtons are rugged enough to withstand harsh environments. iButton uses java as a common programming language.

What is logical statement?

A logical statement is one that will return a boolean or a logical "True" or "False" output. It is used in cases where conditions need to be executed.

For ex: lets say you write a system that checks the age of the visitors to a bar, the system should only allow people who are over 18 yrs of age. So the logical condition will be like below:

if(age > 18) then "Let the Customer Enter"

else "The customer is a minor, send them back to stay out of trouble"

If you don't supply any access specifier with class name than which specifier it should have?

It will have the default access which means - this class will be accessible only within the current package.

What benefits does inheritance bring to game programming?

It brings the general benefits of inheritance, which is that classes which are alike may share some features which are common for all of them.

example:

You are making a strategy game, and want to make lots of units to command and fight.

Class: Unit

has hitpoints, weapon strength, a name, etc..

Class: AirUnit

has all that Unit has, + a special flag that says that this unit can move trough places on the map with forest or ocean without penalty

Class: AttackHelicopter

has everything from Unit and AirUnit, + a flag that says the unit gets a bonus against enemy tank units, and does not require an airfield to land.

The benefits come from the fact that you can write one piece of code that can handle all types of units.

Your users can have a list of all their units

ArrayList army = new ArrayList();

task forces can be made as lists, build queues for bases can use the same technique, etc..

Is constractor create object?

No, that would be a constructor. A constructor is involved in creating objects.

Is it true that by base class pointer you can call only those functions of derived class which are inherited from the base class?

Yes, provided those functions are declared virtual. If they are not virtual, the base class method is implicitly called instead. The base class should be thought of as a common interface to the objects that derive from it, while the derived objects are "more specialised" forms of the base class, which can override the virtual base class methods to produce more specific behaviour. The less derived the object, the less specialised it becomes.

Certain functions can be predicted for all derived objects, but cannot be implemented in the base class. For instance, all shapes can be drawn, but a shape base class cannot implement a Draw() function unless it knows what type of shape it actually is. But by deriving specific shapes such as circles and squares from the shape class, they can each provide their own implementations for the Draw() function, which can then be declared pure-virtual in the base class. This not only ensures that every derived shape provides its own Draw() method, but also ensures that no instances of shape can be created other than by derived objects. The shape then becomes abstract; so shape is a conceptual object while circles and squares are actual objects.

What is the definition of object consistency?

It's where a person reads each action of another person as if there were no prior context.

What is anonymous object in java?

Objects without their declarations known as Anonymous Objects. these are known as use & throw objects because these are died after one time use.

What is the difference between reference variable and painter variable?

Reference Variable

  1. It does not have separate memory other than variable
  2. It is just an alias created to existing variable
  3. It is not present C language

Pointer Variable

  1. It has separate memory other than variable
  2. It actually stores address of the variable
  3. It is present in C as well as C++.