-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path077-Create-a-String.java
More file actions
45 lines (37 loc) · 1.56 KB
/
Copy path077-Create-a-String.java
File metadata and controls
45 lines (37 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* ============================================================================
* Program Name : Create a String
* File Name : 077-Create-a-String.java
* Class Name : CreateAString
*
* Description:
* This program demonstrates different ways of creating a String in Java.
* It creates one String using a string literal and another using the
* String class constructor, then displays both strings.
*
* Objective:
* - Understand how to create String objects in Java.
* - Learn the difference between String literals and String objects.
* - Display String values.
*
* Author : Shaik Mahaboob Basha
* Repository : 01-Core-Java
* Folder : 08-Java-Programs
* ============================================================================
*/
public class CreateAString {
// The main() method is the entry point of every Java application.
public static void main(String[] args) {
// Create a String using a string literal.
String stringLiteral = "Hello, Java!";
// Create a String using the String class constructor.
String stringObject = new String("Welcome to Core Java");
// Display the String created using a string literal.
System.out.println("String Created Using Literal: " + stringLiteral);
// Display the String created using the String constructor.
System.out.println("String Created Using new Keyword: " + stringObject);
// Example Output:
// String Created Using Literal: Hello, Java!
// String Created Using new Keyword: Welcome to Core Java
}
}