Negro pl0x

Idfk i just wanna see what's going on in here
Thu Jan 22

Java

//java practice /* this is how you’d post a comment that is not generated when the app launches */ /* The next line displays how to define the scripts class and should be at the beginning of each app; in the form of : ‘class name’*/ class BeginnersApp { /* Each string in the array is called a command-line argument. Command-line arguments let users affect the operation of the application without recompiling it. For example, a sorting program might allow the user to specify that the data be sorted in descending order with this command-line argument: -descending The “Hello World!” application ignores its command-line arguments, but you should be aware of the fact that such arguments do exist. */ /*Finally, the line: System.out.println(“Hello World!”); */ /*The following is an appropriate example of java */ class HelloWorldApp { public static void main(String[] args) { System.out.println(“Hello World!”); // Display the string. /* Correct signature of the main method is: public static void main(String[] args) */ /* Objects define the state and behavior */ /* Example next… */ class Bicycle { int cadence = 0; int speed = 0; int gear = 1; void changeCadence(int newValue) { cadence = newValue; } void changeGear(int newValue) { gear = newValue; } void speedUp(int increment) { speed = speed + increment; } void applyBrakes(int decrement) { speed = speed - decrement; } void printStates() { System.out.println(“cadence:”+cadence+” speed:”+speed+” gear:”+gear); } } /* You may have noticed that the Bicycle class does not contain a main method. That’s because it’s not a complete application; it’s just the blueprint for bicycles that might be used in an application. The responsibility of creating and using new Bicycle objects belongs to some other class in your application. */ //Another example: class BicycleDemo { public static void main(String[] args) { // Create two different Bicycle objects Bicycle bike1 = new Bicycle(); Bicycle bike2 = new Bicycle(); // Invoke methods on those objects bike1.changeCadence(50); bike1.speedUp(10); bike1.changeGear(2); bike1.printStates(); bike2.changeCadence(50); bike2.speedUp(10); bike2.changeGear(2); bike2.changeCadence(40); bike2.speedUp(10); bike2.changeGear(3); bike2.printStates(); } } The output of this test prints the ending pedal cadence, speed, and gear for the two bicycles: cadence:50 speed:10 gear:2 cadence:40 speed:20 gear:3 /* The syntax for creating a subclass is simple. At the beginning of your class declaration, use the extends keyword, followed by the name of the class to inherit from: class MountainBike extends Bicycle { // new fields and methods defining a mountain bike would go here */ /* In its most common form, an interface is a group of related methods with empty bodies. A bicycle’s behavior, if specified as an interface, might appear as follows: interface Bicycle { void changeCadence(int newValue); void changeGear(int newValue); void speedUp(int increment); void applyBrakes(int decrement); } To implement this interface, the name of your class would change (to ACMEBicycle, for example), and you’d use the implements keyword in the class declaration: class ACMEBicycle implements Bicycle { // remainder of this class implemented as before } Implementing an interface allows a class to become more formal about the behavior it promises to provide. Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler. If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile. */ /* * A package is a namespace that organizes a set of related classes and interfaces.The Java platform provides * an enormous class library (a set of packages) suitable for use in your own applications. This library is * known as the “Application Programming Interface”, or “API” for short. Its packages represent the tasks most * commonly associated with general-purpose programming. For example, a String object contains state and behavior * for character strings; a File object allows a programmer to easily create, delete, inspect, compare, or modify * a file on the filesystem; a Socket object allows for the creation and use of network sockets; various GUI * objects control buttons and checkboxes and anything else related to graphical user interfaces. There are * literally thousands of classes to choose from. This allows you, the programmer, to focus on the design of your * particular application, rather than the infrastructure required to make it work. * */ /* Real-world objects contain state and behavior. * * A software object’s state is stored in fields. * * A software object’s behavior is exposed through methods. * * Hiding internal data from the outside world, and accessing it only through publicly exposed methods * is known as data encapsulation. * * A blueprint for a software object is called a class. * * Common behavior can be defined in a superclass and inherited into a subclass using the extends keyword. * * A collection of methods with no implementation is called an interface. * * A namespace that organizes classes and interfaces by functionality is called a package. * * The term API stands for Application Programming Interface. */