Monday, October 7, 2013

Yesterday I was trying to get a grip on making an interface that reads a text file, and possibly output a text file. But I reckon it was far too ambitious at this stage. I'm going to need to learn something more basic than that. This is the website I found that has several lessons that I can learn to get started with Java http://www.programmingsimplified.com/java-source-codes

It's pretty good and I think I'm going to start by just following the steps in that page. At this stage I'm a bit struggling because I haven't learned anything new in the last couple of years, so my brain's a bit sore trying to take things in. But it's all good, we'll see how I go in the next couple of hours.

Right now it's 10 pm and I'm feeling a bit hungry. So progress might be a bit slow. Regardless, this is the first code that I'm going to try to do. It's a simple Hello World program.

class First { public static void main(String[] arguments) { System.out.println("Let's do something using Java technology."); } }

OK. So with this, the class is defined as:
In the Java(TM) programming language, a type that defines the implementation of a particular kind of object. A class definition defines instance and class variables and methods, as well as specifying the interfaces the class implements and the immediate superclass of the class. If the superclass is not explicitly specified, the superclass will implicitly be Object

 So I'm guessing that First is the name of the class.

Public is A Java(TM) programming language keyword used in a method or variable declaration. It signifies that the method or variable can be accessed by elements residing in other classes.

  • Variable is An item of data named by an identifier. Each variable has a type, such as int or Object, and a scope. 
  • Method is A function defined in a class. See also instance method, class method. Unless specified otherwise, a method is not static.<-- this part is interesting, so public static void..

Static is A Java(TM) programming language keyword used to define a variable as a class variable. Classes maintain one copy of class variables regardless of how many instances exist of that class. "static" can also be used to define a method as a class method. Class methods are invoked by the class instead of a specific instance, and can only operate on class variables.

OK. So this is all pretty straightforward. Let's repeat that statement again:


class First { public static void main(String[] arguments) { System.out.println("Let's do something using Java technology."); } }



 The class is like the vessel.. not sure what public static void means at this stage. But hey, it works

Good description for Object, Class, methods and instance variables..
  • Object - Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class.
  • Class - A class can be defined as a template/ blue print that describes the behaviors/states that object of its type support.
  • Methods - A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.
  • Instance Variables - Each object has its unique set of instance variables. An object's state is created by the values assigned to these instance variables.

    From  http://www.tutorialspoint.com/java/java_basic_syntax.htm

    Great page by the way, will refer to this one.

    I'm writing this from work at 3.47 pm. So I'll just publish this one so I wont get confused. I finally got the first Hello World to work, turns out it's println (ln as in line with all lower case).
 
 

No comments:

Post a Comment