Object Oriented Programming Articles

Page 480 of 589

What are the different compilation modes of a module in Java 9?

raja
raja
Updated on 03-Mar-2020 357 Views

A module is a container of packages and each module contains a module descriptor that includes module name, module dependencies,  it means that the name of other modules depends on and name of the packages it exports that can be used only by modules that depend on it.module com.tutorialspoint.app {    /** Modules upon which the module com.tutorialspoint.app depends on */    requires com.tutorialspoint.services;    /** Packages exposed by this module which can be used by other modules */    exports com.tutorialspoint.app.util; }There are three different compilation modes provided by Java 9 Module: Legacy mode, single module mode, and multi-module mode.Compilation modes of ...

Read More

How to declare a class and an interface in JShell in Java 9?

raja
raja
Updated on 03-Mar-2020 440 Views

JShell can provide an interactive shell for quickly prototyping, debugging, and learning Java and Java API without the need for the main() method or need to compile our code before executing it.Declaration of Class:We can declare a class just like we have written a code in Java Language. The JShell can detect when the class completes it.In the below code snippet, we can declare a class Employee with two parameters and one method.C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> class Employee { ...> String ...

Read More

What are rvalues, lvalues, xvalues, glvalues, and prvalues in C++?

Samual Sam
Samual Sam
Updated on 27-Feb-2020 666 Views

An lvalue has an address that your program can access. Examples of lvalue expressions include variable names, including const variables, array elements, function calls that return an lvalue reference, bit-fields, unions, and class members. A xvalue expression has no address but can be used to initialize an rvalue reference, which provides access to the expression. Examples include function calls that return an rvalue reference, the array subscript, etc. A glvalue (“generalized” lvalue) is an lvalue or an xvalue. An rvalue (so-called, historically, because rvalues could appear on the right-hand side of an assignment expression) is an xvalue, a temporary object ...

Read More

What is a string literal in C++?

Arjun Thakur
Arjun Thakur
Updated on 27-Feb-2020 625 Views

A string literal or anonymous string is a type of literal in programming for the representation of a string value within the source code. More simply put, a string literal is a bit of text between double quotes. For example,const char* var = "Hello";In this definition of var, "Hello" is a string literal. Using const in this way means you can use var to access the string but not to change it. A C++ compiler handles it in the same way as it would handle a character array.

Read More

Importance of transferTo() method of InputStream in Java 9?

raja
raja
Updated on 26-Feb-2020 2K+ Views

The transferTo() method has been added to the InputStream class in Java 9. This method has been used to copy data from input streams to output streams in Java. It means it reads all bytes from an input stream and writes the bytes to an output stream in the order in which they are reading.Syntaxpublic long transferTo(OutputStream out) throws IOExceptionExampleimport java.util.Arrays; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; public class TransferToMethodTest { public void testTransferTo() throws IOException { byte[] inBytes = "tutorialspoint".getBytes(); ByteArrayInputStream bis = ...

Read More

How to write "Hello World" Program in C++?

Ayyan
Ayyan
Updated on 26-Feb-2020 1K+ Views

To run the hello world program, you'll have to follow the following steps −Write a C++ programNow that you have a compiler installed, its time to write a C++ program. Let's start with the epitome of programming example's, it, the Hello world program. We'll print hello world to the screen using C++ in this example. Create a new file called hello.cpp and write the following code to it −#include int main() {    std::cout

Read More

What is the difference between transient and volatile in Java?

Rishi Raj
Rishi Raj
Updated on 26-Feb-2020 842 Views

transient: An instance variable is marked transient to indicate the JVM to skip the particular variable when serializing the object containing it.  This modifier is included in the statement that creates the variable, preceding the class or data type of the variable.Examplepublic transient int limit = 55;   // will not persist public int b;   // will persistvolatile: The volatile modifier is used to let the JVM know that a thread accessing the variable must always merge its own private copy of the variable with the master copy in the memory.Accessing a volatile variable synchronizes all the cached copied ...

Read More

What are the benefits of a module in Java 9?

raja
raja
Updated on 26-Feb-2020 771 Views

An important feature introduced in Java 9 is Module. By using a module, we can divide the code into smaller components called modules. It means each module has its own responsibility and declare its dependency on other modules to work correctly.Below are the steps to create a modular project in Java 9:Initially, we can create a file named "module-info.java" and add to a package(module) for which it is created. For instance, if our package name is com.mycompany.mypackage then the file goes to the same package (src/com.mycompany.mypackage/module-info.java). We can create a module by declaring "exports" and "requires" expressions.If our modules require another module ...

Read More

How to create String object in Java?

Moumita
Moumita
Updated on 26-Feb-2020 2K+ Views

You can create a String by -Assigning a string value wrapped in " " to a String type variable.String message = "Hello Welcome to Tutorialspoint";Creating an object of the String class using the new keyword by passing the string value as a parameter of its constructor.String message = new String ("Hello Welcome to Tutorialspoint");Passing a character array to the String constructor.char arr[] = {'H','e','l','l','o'}; String message = new String(arr);

Read More

Manipulating Strings in Java.

Manikanth Mani
Manikanth Mani
Updated on 26-Feb-2020 750 Views

Since String class is immutable once created we cannot modify the data of the string. But still if you want to manipulate string data you can rely on StringBuffer or StringBuilder classes.Examplepublic class Test { public static void main(String args[]) { String str = "Hi welcome "; StringBuffer sb= new StringBuffer(str); sb.append("to Tutorialspoint"); System.out.println(sb); } }OutputHi welcome to Tutorialspoint

Read More
Showing 4791–4800 of 5,881 articles
« Prev 1 478 479 480 481 482 589 Next »
Advertisements