Skip to content

Instantly share code, notes, and snippets.

@MelulekiDube
Created August 13, 2019 15:38
Show Gist options
  • Save MelulekiDube/393c78a05078011c244d6a1239ea4e81 to your computer and use it in GitHub Desktop.
Save MelulekiDube/393c78a05078011c244d6a1239ea4e81 to your computer and use it in GitHub Desktop.
import java.util.Scanner;/*Always assume you will need this*/
public class Test1A /*Always create class with the file name*/{
public static void main( String[] arg){
/*Get rid of the scanner*/
Scanner sc = new Scanner(System.in);
/*start doing some work here
variable delcation follows here:
How to declare primitive which include int double float char boolean (these are not going to create objects):
type var_name; {type is in {int float double char boolean}}
type var_name = value; for delcaring and assigning
To assigning
var_name = value;
How to declare objects:
First you need to know the class names
Class_Name var_name; //var_name does not have a value
Assign value:
var_name = value; if value has been created before
otherwise:
var_name = new Class_Name(constructor parameters);
Accessing object methods and variables:
if you have the classes first check if the variable or method you are accessing is not private
You always need an object to access methods and variables in a class
lets say we have an object created as below:
ClassName var_name = ........; if the class has a method called public int getValue(){......return ...;}
then we can access getValue as:
int var_name1 = var_name.getValue();
the syntax will be:
variablename.methodname where variablename is an object and methodname is the method you want
always remember that if you usign a method end methodname with parenthesis ()
if we wanted to use a called set defined as in a class called Person like below
public class Person{
********
public void set(int a){
........;
}
********
}
1) always have an object that can that method
Person temp = new Person();
temp.set(1);
*/
/*
Using if statements:
if (conditional statement which results in a boolean value) example if(2>3) 2>3 is a conditional statement and is either true of false
*/
//example
/*
loops in java
for while do-while
//COPY THESES FROM YOUR NOTES
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment