What is the difference between a class and an object?
A class is a blueprint that defines a type’s data and behavior; an object is an instance of that class created during program execution.
Study Java Objects, Classes, and Strings with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is the difference between a class and an object?
A class is a blueprint that defines a type’s data and behavior; an object is an instance of that class created during program execution.
What does assignment copy for an object reference?
A class-type variable stores a reference to an object, not the object’s contents directly. Assigning one reference to another copies the reference.
What does null mean for a Java reference?
null means a reference does not currently refer to any object. Calling an instance method through that reference causes a NullPointerException.
What defines a Java constructor?
A constructor initializes a new object. It has the same name as its class, has no return type, and runs when invoked with new.
How does Java choose among overloaded constructors?
Java selects an overloaded constructor whose parameter types and number match the arguments. If any constructor is declared, Java does not automatically add a no-parameter constructor.
How do instance and static method calls differ?
An instance method is called on an object, such as text.length(). A static method belongs to the class and is called through its class name, such as Math.sqrt(81.0).
Why does word.toUpperCase() not change word?
String objects are immutable: their characters cannot be changed. Methods such as toUpperCase() return a new string, so the result must be saved to change a variable’s reference.
What does "computer".substring(0, 4) return?
substring(0, 4) returns characters at indices 0 through 3 because the start is inclusive and the end is exclusive. For "computer", the result is "comp".
How should Java compare String contents?
Use equals to compare string contents. The == operator compares object references, so it does not normally test whether two strings contain the same characters.
What are first and second after this trace?
first remains "AP" and second becomes "AP CSA". Because String is immutable, += creates a new string and assigns its reference only to second.
What are autoboxing and unboxing?
Autoboxing converts a primitive to its wrapper object, such as int to Integer. Unboxing converts a wrapper object back to its primitive, such as Integer to int.
How do parseInt and valueOf differ?
Integer.parseInt("123") returns the primitive int 123, while Integer.valueOf("123") returns an Integer wrapper object.
A progressive guide to how computing reshapes culture, economic life, public institutions, and individual opportunities, with frameworks for evaluating digital equity, bias, cybersecurity, encryption, and collective participation.
A medium-difficulty assessment of programming fundamentals, algorithmic problem solving, control flow, data structures, testing, debugging, complexity, and decidability. Questions progress from foundational understanding to applied reasoning.
A 14-question quiz on the social, economic, privacy, informational, health, and environmental risks of computing innovations, including strategies for responsible design and oversight.
A practical guide to recognizing cybersecurity threats, protecting accounts and devices, and responding safely when information or systems may be compromised.
A guided introduction to how encryption, authentication, hashing, secure protocols, and key management establish confidentiality, integrity, privacy, and trust while creating practical and legal trade-offs.
A focused review of propositional logic, quantifiers, sets, relations, functions, and foundational proof methods in discrete mathematics for computer science.
A practical guide to evaluating computing innovations by examining their benefits, risks, equity, security, participation, and long-term effects on people and communities.
A medium-difficulty quiz on integrating problem definition, representation, algorithms, complexity analysis, testing, correctness, ethical evaluation, and documentation in a computer science capstone.
A progressive guide to designing, operating, and testing systems that continue useful service despite component faults, overload, data loss, and recovery challenges.
A medium-difficulty quiz on how independently operated networks, protocols, addresses, naming systems, transport services, and routing mechanisms work together to form the Internet.
A progressive guide to how packet-switched networks encapsulate data, move it across links, and manage delay, throughput, queues, and congestion.
A structured guide to designing parallel and distributed systems through decomposition, communication, coordination, state management, scalability, and fault tolerance.