Giter VIP home page Giter VIP logo

modesto's Introduction

Modesto

Java explorations with my student Modesto.

// These two have the same value
new String("test").equals("test") // --> true 

// ... but they are not the same object
new String("test") == "test" // --> false 

// ... neither are these
new String("test") == new String("test") // --> false 

// This is the best way to check for string equalities. It checks for nulls and calls .equals()
import java.util.Objects
Objects.equals("CA", "TX") // --> false
Objects.equals("TX", "TX") // --> true
Objects.equals("test", new String("test")) // --> true
Objects.equals(null, "test") // --> false

// ... but these are because literals are interned by 
// the compiler and thus refer to the same object
"test" == "test" // --> true 

How do I write a function/method in Java?

/* public static <return data type> <name>(<data type> <variabe1Name>, <data type> <variable2Name> ...) {
    1. Declare data types: Ex --> 
        String hello; 
        int num; 
        double number1;
        ...
    2. Write the body of the function here...
    3. Make sure to add a return statement if the <return data type> is not void
    4. Close squigly to end the scope.
}
*/

public static double sum(double a, double b) {
    double result;
    result = a + b;
    return result;
}

... Okay so I have written a function/method in Java, now how do I call it?

// <functionName>(param1, param2, ...)
sum(1, 2)  // --> 3
sum(5, 5)  // --> 10

But it is not showing me anything!

System.out.println(sum(1, 2))

modesto's People

Contributors

cleverprogrammer avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.