Soluții

How to Create Object in Java

The object is a basic building block of an OOPS language. In Java, we cannot execute any program without creating an object. There is various way to create an obiect in java that we will discuss in this section, and also learn how to create an object in Java.

java provides five ways to create an object.

  • Using new Keyword
  • Using clone() method
  • Using newInstance() method of the Class class
  • Using newInstance() method of the Constructor class
  • Using Deserialization
Using new Keyword

Using the new keyword is the most popular way to create an object or instance of the class. When we create an instance of the class by using the new keyword, it allocates memory (heap) for the newly created object and also returns the reference of that object to that memory. The new keyword is also used to create an array. The syntax for creating an object is:

  • Using new Keyword
  • Using clone() method
  • Using newInstance() method of the Class class
  • Using newInstance() method of the Constructor class
  • Using Deserialization
[mai mult...]

How to Print ASCII Value in Java

ASCII acronym for American Standard Code for Information Interchange. It is a 7-bit character set contains 128 (0 to 127) characters. It represents the numerical value of a character. For example, the ASCII value of A is 65.

In this section, we will learn how to print ASCII value or code through a Java program.

There are two ways to print ASCII value in JAVA

  • Assigning a Variable to the int Variable
  • Using Type-Casting
Assigning a Variable to the int Variable

To print the ASCII value of a character, we need not use any method or class. Java internally converts the character value to an ASCII value. In the following program, we have assigned two characters a and b in the ch1 and ch2 variables, respectively. To find the ASCII value of a and b, we have assigned ch1 and ch2 variables to the integer variables asciivalue1 and asciivalue2, respectively. Finally, we have printed the variable asciivalue1 and asciivalue2 in which ASCII values of the characters are stored.

[mai mult...]

How to Use Your Apple Watch to Split the Bill and Calculate Tips

All Apple Watch models include a stock Calculator app that offers a couple of handy features for working out how much you should tip when eating out and how much each person in a group owes if you’re splitting the bill.

The two functions can be used together, but if it’s just yourself dining out then you can just leave the People field set to 1. The steps below show you how it works.

Note: If you see a standard percentage (%) button where the TIP button should be, you can change the calculator layout to replace it. Simply go to Settings -> Calculator and select Tip Function instead of Per cent.

[mai mult...]