JIYIK CN >

Current Location:Home > Learning > PROGRAM > Java >

console.log in Java

Author:JIYIK Last Updated:2025/04/14 Views:

This tutorial explains the function in Java console.log()and how to display logs to the console in Java.

console.log()is a function in JavaScript that is used to display log messages to the browser console. There is no such message in Java, but System.out.println()performs a similar task.

So remember, if someone asks you about this method and claims it belongs to Java, there is no such thing because Java does not have any method with this name.

We can System.out.println()display the message to the console as JavaScript in Java using the method. Let us understand through an example.


In Javaconsole.log

In Java, we can use println()the method as to console.log()display the log messages to the console. See the example below.

public class SimpleTesting {
  public static void main(String[] args) {
    System.out.println("Hello DelftStack");
  }
}

Output:

Hello DelftStack

console.log()Custom methods in Java

If you want to use the method in Java console.log(), you can create a Consoleclass and add a static log()method. This method has a print statement to print a message to the console.

After creating the class, you can call log()methods by the class name. See the example below.

public class SimpleTesting {
  public static void main(String[] args) {
    Console.log("Hello DelftStack");
  }
}
class Console {
  public static void log(Object obj) {
    System.out.println(obj);
  }
}

Output:

Hello DelftStack

Previous:Java Change Date Format

Next: None

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Java Change Date Format

Publish Date:2025/04/14 Views:65 Category:Java

There are various options available for converting date string to date format. The methods mentioned below can bring the desired result. Let us understand the various ways from the following code block. import java.text.ParseException ; imp

Calendar date in YYYY-MM-DD format in Java

Publish Date:2025/04/14 Views:72 Category:Java

Java Date encapsulates the current time and date. The Date class does this with the help of two constructors - Date() and Date(long millisec) constructor. We use Date() the constructor to initialize the object with the current time and date

Implementing a min-max heap in Java

Publish Date:2025/04/14 Views:53 Category:Java

In this article, we will implement a max heap and a min heap using PriorityQueue the class. We will also demonstrate inserting and removing elements from the heap. Introduction to Min-Max Heap in Java Heap is a tree-based data structure, wh

Implementing a Min Heap in Java

Publish Date:2025/04/14 Views:197 Category:Java

A min heap is a heap in which every internal node is less than or equal to the value of its child nodes. We will see in the following points how to implement a min heap with and without using a library. Minimal heap implementation in Java w

Increasing the heap space in Java

Publish Date:2025/04/14 Views:190 Category:Java

In Java, the heap space is mainly used for garbage collection and allocating memory for objects. A default heap space is allocated when JVM is installed on our machine, but it may be different. The following points show how we can increase

Detecting EOF in Java

Publish Date:2025/04/14 Views:91 Category:Java

In this tutorial, we will see how to while detect EOF( End OF File ) in Java using a loop. We will also discuss developing a program that continues reading content until it reaches the end of a file. From a programming perspective, EOF is a

Get resource URL and content in Java

Publish Date:2025/04/14 Views:97 Category:Java

getResource() This tutorial will demonstrate how to use the function to get the resource URL and read the resource file in Java . getResource() Use the function to get the resource URL in Java We will use the method in Java getResource() to

Getting the host name in Java

Publish Date:2025/04/14 Views:78 Category:Java

In this tutorial, we will see how to get the IP address and host name using Java API. InetAddress Get the host name in Java using The package java.net contains classes for handling the IP address and host name of the current machine InetAdd

Get the IP address of the current device in Java

Publish Date:2025/04/14 Views:53 Category:Java

An Internet Protocol (IP) address is an identifier for each device connected to a TCP/IP network. This identifier is used to identify and locate nodes in the middle of communication. The IP address format, such as 127.0.0.0, is a human-read

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial