Java Tutorial
🔍
What is OOP?Classes & ObjectsConstructorsAccess Modifiersthis Keywordstatic KeywordEncapsulationInheritancesuper KeywordMethod OverridingOverloading vs OverridingPolymorphismUpcasting & Downcastinginstanceof OperatorAbstractionAbstract ClassesInterfacesMarker InterfacesAbstract Class vs InterfaceObject ClasstoString() Methodequals() & hashCode()
Collections OverviewCollections HierarchyIterable InterfaceCollection InterfaceMap Interfaceequals() and hashCode()IteratorListIteratorFail-fast vs Fail-safe IteratorConcurrentModificationExceptionArrayListLinkedListHashSetLinkedHashSetTreeSetQueuePriorityQueueDequeArrayDequeHashMapLinkedHashMapTreeMapConcurrentHashMapCopyOnWriteArrayListList vs Set vs MapChoosing the Right CollectionComparableComparatorComparable vs ComparatorCollections Utility ClassArrays Utility ClassImmutable CollectionsCollection vs CollectionsVectorHashtableStackArrayList Internal WorkingLinkedList Internal WorkingHashMap Internal WorkingTreeMap Internal Working
Print Name in Java
beginner· Basics & I/O · Fundamentals
Problem
A string literal is fixed text written directly in the source code, surrounded by double quotes.
Store a name in a variable and print it to the console.
Input
John
Output
John
Java Program
Java
public class PrintName {
public static void main(String[] args) {
String name = "John"; // store the name in a variable
System.out.println(name);
}
}Output
John
Core Logic
Storing text in a String variable and printing that variable separates the data from the print statement, a small step up from hard-coding text directly into println().
How It Works
- 1
String name = "John";declares a variable and stores the text"John"in it. - 2
System.out.println(name)prints the variable's current value, not the literal wordname.
Changing the value assigned to
name changes what gets printed, without touching the println() call itself.💡
Key Point: Once a String is created in Java, its content can't change — reassigning name points it at a brand-new String object instead of modifying the original.
Key Concepts
String variableSystem.out.println()