throw and throws in Java
throw raises an exception now; throws declares that a method may raise one and leaves the handling to the caller.
Suitable for beginners.
104 notes tagged
throw raises an exception now; throws declares that a method may raise one and leaves the handling to the caller.
try guards a block, catch handles specific failures, finally always runs, and try with resources closes what you opened.
Errors, checked exceptions and unchecked exceptions sit in one hierarchy, and knowing which is which decides how you should react.
Packages give classes a unique name and a visibility boundary, and imports simply save you from writing that full name every time.
Inheritance lets a subclass acquire the members of a superclass, creating an is-a relationship that polymorphism is built on.
Encapsulation hides internal state behind a deliberate public surface, so a class can guarantee its own rules stay true.
static binds a member to the class rather than to any instance, which changes when it is created, how it is accessed and what it can see.
Inside an instance method, this is a reference to the object the method was called on, which resolves shadowing and enables chaining.
A constructor runs once when an object is created, and its job is to leave that object in a valid state.
A class describes the state and behaviour of a kind of thing, and an object is one concrete instance of that description held in memory.
String is an immutable object with a shared literal pool, and both facts explain how comparison, concatenation and performance behave.
An array is a fixed size object holding elements of one type, indexed from zero, with the length fixed at creation.