Java is a popular programming language, but it can take a bit to get it working on your machine. This is a helpful Tutorial on getting started.
https://www.youtube.com/watch?v=BB0gZFpukJU
Here is some basic Java to test your program.
class Main {
public static void main(String[] args) {
System.out.println("Hello my name is Dan.");
}
}
It is important to remember that the Java language has some specific rules around their identifiers, which the filename would be considered. Something with a space, or starting with a number will throw an invalud identifier error. Week1.java or Week_1.java should be fine.
Java is an object oriented program, which resolves around a few concepts like
Abstraction - using simple thigns to represent complex things. Many things in our life work this way - you know that a fridge keeps things cold, but you might not know HOW a fridge keeps things cold. Objects, Classes and Variable represent the complex things but are easy to write and understand.
Encapsulation: Keeps the fields in your classes private but providing public access. It's a barrier that keeps data and code safe within the class.
Inheritance - A feature of OOP in Java, lets' programmers create new classes that share some attributes of those that already exist. We can build on what already exists rather than reworking it each time. Extending classes to sub classes will copy in any variables or methods.
Polymorphism - Something can be displayed in more than one form. This is one of the more complicated concepts of OOP. An example of what Polymorphism represents in Java are the way classes work, and works hand in hand with Inheritance. If we have a parent class of vehicle, with method "Horn" output of "beep". We can extend the class to "bus". Calling Horn on bus will return "beep", but we can update it to "Honk" specifically for bus..
This Youtube tutorial does a good job of explaining the process:
https://www.youtube.com/watch?v=jhDUxynEQRI
public class Polymorphism {
public static void main(String[] args) {
Vehicle newVehilce = new Vehicle();
newVehicle.Horn();
Bus line1 = new Bus();
line1.Horn();
}
}
public class Vehicle {
public void horn () {
System.out.println("beep.");
}
}
public class Bus extends Vehicle {
/* this inherits the methods and variables from the parent class
public void horn () {
System.out.println("honk");
}
Removing this from being a comment will update bus to honk, leaving it as comment will return beep */
{

Comments
Post a Comment