Coder Social home page Coder Social logo

java's Introduction

Java

Loops

Print if a number is prime or not (Input n from the user). [In this problem you will learn how to check if a number is prime or not]

Patterns

Part-1, Part-2, Part-3, Part-4, Part-5, Part-6, Part-7, Part-8, Part-9.

Methods/Functions

A function is a block of code that performs a specific task. Why are functions used? a. If some functionality is performed at multiple places in software, then rather than writing the same code, again and again, we create a function and call it everywhere. This helps reduce code redundancy. b. Functions make maintenance of code easy as we have to change at one place if we make future changes to the functionality. c. Functions make the code more readable and easy to understand.

The syntax for function declaration is : return-type function_name (parameter 1, parameter2, …… parameter n){ //function_body } return-type The return type of a function is the data type of the variable that that function returns.

For eg - If we write a function that adds 2 integers and returns their sum then the return type of this function will be ‘int’ as we will return a sum that is an integer value. When a function does not return any value, in that case the return type of the function is ‘void’. function_name It is the unique name of that function. It is always recommended to declare a function before it is used.

Parameters A function can take some parameters as inputs. These parameters are specified along with their data types. For eg- if we are writing a function to add 2 integers, the parameters would be passed like – int add (int num1, int num2)

Time & Space Complexity

Explain a code working Time, and code spaces layers in storage tank. Time complexity of an algorithm quantifies the amount of time taken by an algorithm to run as a function of the length of the input.

Types of notations 1. O-notation: It is used to denote asymptotic upper bound. For a given function g(n), we denote it by O(g(n)). Pronounced as “big-oh of g of n”. It is also known as worst case time complexity as it denotes the upper bound in which the algorithm terminates. 2. Ω-notation: It is used to denote asymptotic lower bound. For a given function g(n), we denote it by Ω(g(n)). Pronounced as “big-omega of g of n”. It is also known as best case time complexity as it denotes the lower bound in which the algorithm terminates. 3. 𝚯-notation: It is used to denote the average time of a program.

Comparison of functions on the basis of time complexity

It follows the following order in case of time complexity:

O(n n) > O(n!) > O(n3) > O(n2) > O(n.log(n)) > O(n.log(log(n))) > O(n) > O(sqrt(n)) > O(log(n)) > O(1)

Note: Reverse is the order for better performance of a code with corresponding time complexity, i.e. a program with less time complexity is more efficient.

Space Complexity Space complexity of an algorithm quantifies the amount of time takenby a program to run as a function of length of the input. It is directly proportional to the largest memory your program acquires at any instance during run time. For example: int consumes 4 bytes of memory.

Arrays In Java

Arrays in Java are like a list of elements of the same type i.e. a list of integers, a list of booleans etc. a. Creating an Array (method 1) - with new keyword
int[] marks = new int[3];
marks[0] = 97;
marks[1] = 98;
marks[2] = 95;
b. Creating an Array (method 2) int[] marks = {98, 97, 95};

Strings (String Builder)

ALWAYS REMEMBER : Java Strings are Immutable.

Declaration
String name = "Ganesh";

Taking Input
Scanner sc = new Scanner(System.in);
String name = sc.next();

Concatenation (Joining 2 strings)
String firstName = "Ganesh";
String secondName = "Jadhav";
String fullName = firstName + " " + secondName;
System.out.println(fullName);

Print length of a String
String firstName = "Ganesh";
String secondName = "Jadhav";
String fullName = firstName + " " + secondName;
System.out.println(fullName.length());

Access characters of a string
String firstName = "Ganesh";
String secondName = "Jadhav";
String fullName = firstName + " " + secondName;
for(int i=0; i<fullName.length(); i++) {
System.out.println(fullName.charAt(i)); }

Join us for new Collabe and Adding Some new Features in JAVA and C++ PRojects.

java's People

Contributors

ganeshjadhav2402 avatar

Stargazers

 avatar

Watchers

 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.