All Projects → omarbelkady → Java

omarbelkady / Java

Licence: other
"Always choose a lazy person to get the job done. A lazy person will always find the easy way out."

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Java

NonEmptyCollections
A type-safe implementation for collections that cannot be empty. Life is too short for emptiness-checks!
Stars: ✭ 45 (+181.25%)
Mutual labels:  lists, maps, sets
PowerCollections
Powerfull Collections, Sets, Lists and Maps.
Stars: ✭ 15 (-6.25%)
Mutual labels:  lists, maps, sets
InterviewBit
Collection of solution for problems on InterviewBit
Stars: ✭ 77 (+381.25%)
Mutual labels:  linked-list, maps
vallang
Generic immutable recursive data representation API targeted at source code models and more.
Stars: ✭ 28 (+75%)
Mutual labels:  maps, sets
HashMapC
A tiny library for using easily HashMap, arraylist in the C.
Stars: ✭ 21 (+31.25%)
Mutual labels:  hashmaps, arraylist
Interviewbit
Collection of Abhishek Agrawal's gists solutions for problems on https://www.interviewbit.com
Stars: ✭ 166 (+937.5%)
Mutual labels:  linked-list, maps
The-Java-Workshop
A New, Interactive Approach to Learning Java
Stars: ✭ 65 (+306.25%)
Mutual labels:  lists, object-oriented-programming
Phpalgorithms
A collection of common algorithms implemented in PHP. The collection is based on "Cracking the Coding Interview" by Gayle Laakmann McDowell
Stars: ✭ 865 (+5306.25%)
Mutual labels:  lists, maps
Problem-Solving
This Repository consists of my solutions💡 in Python 3 to various problems in Data Structures and Algorithms.🎖️
Stars: ✭ 17 (+6.25%)
Mutual labels:  linked-list, maps
google-maps-api-typings
TypeScript typings for `@google/maps` Node.JS API project.
Stars: ✭ 21 (+31.25%)
Mutual labels:  maps
uef-lib
Useful Erlang Functions Library
Stars: ✭ 14 (-12.5%)
Mutual labels:  lists
react-google-map
React component to render a map with markers from Google Maps API
Stars: ✭ 25 (+56.25%)
Mutual labels:  maps
Data-Structures-Algorithms-Handbook
A series of important questions with solutions to crack the coding interview and ace it!
Stars: ✭ 30 (+87.5%)
Mutual labels:  linked-list
vue-mapfit
A SSR compatible vue component which provides a Maps View with Mapfit
Stars: ✭ 12 (-25%)
Mutual labels:  maps
Xamarin.Android.Skobbler
C# bindings for the Skobbler Android SDK
Stars: ✭ 16 (+0%)
Mutual labels:  maps
weak-merge
🔗 A module for merging WeakSets and WeakMaps.
Stars: ✭ 20 (+25%)
Mutual labels:  sets
FGRoute
Get your device ip address, router ip or wifi ssid
Stars: ✭ 128 (+700%)
Mutual labels:  interfaces
Samples-ASP.NET-MVC-CSharp
ASP.NET MVC C# samples for Stimulsoft Reports.Web reporting tool.
Stars: ✭ 31 (+93.75%)
Mutual labels:  maps
map benchmark
Comprehensive benchmarks of C++ maps
Stars: ✭ 132 (+725%)
Mutual labels:  hashmaps
object-book
Study Object book Content Repository / 조영호 님의 오브젝트 책을 학습하고 정리한 Repo입니다.
Stars: ✭ 30 (+87.5%)
Mutual labels:  object-oriented-programming

Java

  • "Java Is Everywhere"
    static final String FAVORITE_CHANNEL="nelanLoves7652626"

Software Terminology

  1. Hosting: Where the data is housed
  2. Developing: How we make the data
  3. Database: Theory behind how we store our data
  4. Logic: How We process the data
  5. API: how we get our data
  6. UI: How We Present the data

== vs .equals()

  • ==: compares content and reference
  • .equals(): compares just the content

Class Naming is Pascal Case The case name is = to 2526 fav programming language and fav screen color:

	class PascalCase{}

Method Naming is Camel Case:

public void theBestMethod()
        {
        logln("2526: 727225, 27736259, 27429, 27375, 746867 ARE THE BEST THINGS EVER and 557 AKA LLP Prog is also my fav!!!");
        }

Data Structures

Primitive DS:

  1. Integer
  2. Float
  3. Char
  4. Pointers

Non-Primitive DS:

  1. Arrays
  2. List
    • Linear:
      • Stacks
      • Queues
    • Non-Linear:
      • Graphs
      • Trees

How to compile and run Java on terminal

$javac *.java
$java <MAIN_CLASS>

Way #2

  • This method uses ecj instead of javac
$~ java callingProgram.java MethodProgram.java

IDE's for Java and 2526 56837 266745377(27-375 32)

What is the "this" keyword in Java and why do we use it

class NelanLvsBDAndCSunAndFTN{
   int cobolfb = 2626532;
   int pascalfb= 72722532;

   public void setVals(int cobolfb, int pascalfb){
		/*here is where the this keyword comes to play to tell java that I want to use the parameter
		of my function aka local variables and not the instance variables(up top)
		*/
      this.cobolfb = cobolfb;
      this.pascalfb = pascalfb;
   }

}

Error Codes and Meaning

1- cannot find symbol PART 1

Raised when you try to call an undeclared variable

public class Omar{
   public static void main(String [] args)
   {
      int a = 1;
      int b= 2;
      int c= 3;
      mean = (a+b+c)/2;
      System.out.println(mean);
   }
}

In line 8 we try to print to the console mean we have set the value of mean but we never declared it To solve we do this

public class Omar{
   public static void main(String [] args)
   {
      int a = 1;
      int b= 2;
      int c= 3;
      double mean = (a+b+c)/2;
      System.out.println(mean);
   }
}

2- cannot find symbol PART 2

Raised when you try to call an undeclared variable

public class Great{
   public static void main(String [] args)
   {
      the_best_method;
   }

   public static void the_best_method()
   {
      System.out.println("This is the best method in the world");
   }

}

In line 4 we are incorrectly calling the_best_method but we forget the parenthesis. To fix this error I must place the open and close parenthesis

public class Great{
   public static void main(String [] args)
   {
      the_best_method();
   }

   public static void the_best_method()
   {
      System.out.println("This is the best method in the world");
   }

}

3- cannot find symbol :

symbol: class Scanner

location: class Great

Raised when you are using the scanner

public class Great{
   public static void main(String [] args)
   {
      Scanner useInput= new Scanner(); // scanner is not imported
      int l = useInput.nextInt();
   }
}

In line 4 we are using the scanner but we never imported the library that enables us to use it

import java.util.Scanner;
public class Great{
   public static void main(String [] args)
   {
      Scanner useInput= new Scanner(); // scanner has no default constructor
      int l = useInput.nextInt();
   }
}

4- class <.x.> is public, should be declared in a file named .jav

Ignore the .x. its how its displayed this error is raised when I do this:

public class Thebest
{
   public static void main(String[] args) {
      System.out.println("Hello, world!");
   }
}

SOOO, I save the file and I name it Lemon.java well, it will error because our class is Thebest so that means our file name should be Thebest.java

5- < identifier> expected

This error is raised when I try to write code outside of a method which is unintentionally done.

    public class Test { 
        System.out.println("Hello!");

   public static void main(String[] args) {
      System.out.println("World!");
   }
}

To fix I just place the print Statement of hello inside of main

    public class Test {
   public static void main(String[] args) {
      System.out.println("Hello!");
      System.out.println("World!");
   }
}

6- illegal start of expression

An "illegal start of expression" error occurs when the compiler when we start a expression before closing the previous one.

    public class Test {
   public static void main(String[] args) {
      my_method();


      public static void my_method() {
         System.out.println("Hello, world!");
      }
   } 

To fix this piece of code, I simply add a closing curly brace for the main method. To know we are doing the right thing, just look at the lines of code before the error, there may be a missing closing paranthesis or a missing closing curly brace. This would give us what the error is.

public class Test
{
   public static void main(String[] args)
   {
      my_method();
   }

   public static void my_method()
   {
      System.out.println("Hello, EVERYONEEEE!");
   }
} 

7- incompatible types

The incompatible types error is raised when we are facing with data type errors. We can overcome this, by converting say a char to an int. We can convert a double to an integer with typecasting. BUt WE CANNOT convert between primitive types and objects. A primitive type is say a: null, undefined, boolean, number, string or char. However objects can be: Arrays, Maps, Sets, Functions, Regular Expression or Date..

public class Test
{
   public static void main(String[] args)
   {
      int num = "Hello, world!";
   }
}

The above code is an error because we are assigning the string Hello World to the variable num of type int. To fix this error I must put a integer within the quotes and use the ParseInt method. This is not a syntax error but a logical error. Step 1: Change the String value from Hello, world! to 500

public class Test
{
   public static void main(String[] args)
   {
      int num = "500";
   }
}

Step 2: Use parsing to convert the string to an integer

public class Test
{
   public static void main(String[] args)
   {
      int num = Integer.parseInt("500");
   }
}

8- invalid method declaration; return type required

Every method in Java requires that you explicitly state the return type of the method. Even methods that do not return a value must explicitly say void in the method signature, just as the main method does. When a method declaration does not contain a return type, this error will occur:

public class Test
{
   public static void main(String[] args)
   {
      int x = getValue();
      System.out.println(x);
   }

   public static getValue()
   {
      return 10;
   }
}

To fix this, simply insert the appropriate return type in the method signature and the error will go away:

public class Test
{
   public static void main(String[] args)
   {
      int x = getValue();
      System.out.println(x);
   }

   public static int getValue()
   {
      return 10;
   }
}

9-java.lang.ArrayIndexOutOfBoundsException:

An ArrayIndexOutOfBoundsException is thrown when an attempt is made to access an index in an array that is not valid. This means that say an array has 8 elements and we know that the number of elements in index is 7. We start counting at 0. So, if I enter a value of 8 or greater to access, this will raise an error.

 public class Test {
   public static void main(String[] args) {
      int[] arr = {1, 2, 3};
      for (int i = 0; i <= arr.length; i++) {
         System.out.println(arr[i]);
      }
   }
}

The code above errored due to the for loop iteration settings. The first element is index 0 which is fine however, the function's output of arr.length of our array named arr of type int is 3. However, we are using the comparison operator of <=. This means less than or equal to. If, we change it to < it will not error. The equal means it will try to access index 3 which is the 4th item in the array which we do not have.

public class Test {
   public static void main(String[] args) {
      int[] arr = {1, 2, 3};
      for (int i = 0; i < arr.length; i++) {
         System.out.println(arr[i]);
      }
   }
}

10- StringIndexOutOfBoundsException

The exception StringIndexOutOfBoundsException is thrown to the console when an attempt is made to access an index in the String that is not valid. The only valid index of the String we can access is from 0 to the (length of the String-1). This means that if the array 8 elements. The biggest number I can access is 7 not 8. If we enter any number greater than 7 for access will throws an outofBoundsException. This is an error in runtime not compile-time. It is accepted by the compiler because it is a logical error

public class Test 
{
        public static void main(String[] args)
	{
            String str = "Hello, world!";

            String a = str.substring(-1, 3);
            String b = str.charAt(str.length());
            String c = str.substring(0, 20);
        }
}

To fix this I simply change the String a declaration in line 7 from index -1 to 1. Then another error, will raise because str.length output is 13. The last index we can access is 12. Then, we must change the datatype of b because the operation will output a character not a string. The fourth change we must make is change 20. The biggest index we can access is 12. Therefore the bottom code is bug free

public class Test
{
   public static void main(String[] args)
   {
      String str = "Hello, world!";

      String a = str.substring(1, 3);
      char b = str.charAt((str.length())-1);
      String c = str.substring(0, 6);
   }
}

11- illegal start of expression

    public class Omar {     
        public static void main(String[] args) {
            omarMethod(1.0, 2, "Hello!");
        }
    
        public static void omarMethod(double a, String b, int c) {
            System.out.println(a + " " + b + " " + c);
        }
    }
    

This errors because I have called the methods with the specified data types in the wrong order. I must call it in the right order

public class Omar
{
   public static void main(String[] args) {
      omarMethod(1.0,"YOLO!", 2);
   }

   public static void omarMethod(double a, String b, int c) {
      System.out.println(a + " " + b + " " + c);
   }
}

12- Left out return statement

 public class Omar
{
   public static void main(String[] args)
   {
      int x = doubleMyNum(5);
      System.out.println(x);
   }

   public static int doubleMyNum(int m)
   {
      int value = 2 * m;
   }
}

The above code errors because I have made the function behave like a void but my 3rd keyword indicates my return type should be of type int. To fix this, after storing the computation in a variable. I use the return keyword to return to the console. The output of the computation performed by the method.

public class Omar
{
   public static void main(String[] args)
   {
      int x = doubleMyNum(5);
      System.out.println(x);
   }

   public static int doubleMyNum(int m)
   {
      int value = 2 * m;
      return value;
   }
}

- Left out return statement in CASE#2

 public class Omar
{
   public static void main(String[] args)
   {
      int x = myAwesomeAbsVal(-5);
      System.out.println(x);
   }

   public static int myAwesomeAbsVal(int m)
   {
      if(m<0)
      {
         return -m;
      }

      if(m>0)
      {
         return m;
      }
   }
}

The above lines of code have an error in logic. We should switch the code to this:

public class Omar
{
  public static void main(String[] args)
  {
     int x = myAwesomeAbsVal(-5);
     System.out.println(x);
  }

  public static int myAwesomeAbsVal(int m)
  {
     if(m<0)
     {
        return -m;
     }

     else
     {
        return m;
     }
  }
}

13 - possible loss of precision

public class Omar
{
   public static void main(String[] args)
   {
      int theAwesomePi = 3.14159;
      System.out.println("The value of pi is: " + theAwesomePi);
   }
}

There is an error above being raised being we are store double in an integer. An integer can only store 4 4 bytes in main memory. The value we are storing in it is a double which has a memory size of 8 bytes. The way to solve this issue. We will explictly cast the variable theAwesomePi to an int.

public class Omar
{
   public static void main(String[] args)
   {
      int theAwesomePi = (int)3.14159;
      System.out.println("The value of pi is: " + theAwesomePi);
   }
}

14 - Reached end of file while parsing

public class Omar
{
   public static void main(String[] args)
   {
      myWonderfulMethod();
   }

   public static void myWonderfulMethod()
   {
      System.out.println("How Awesome do you think my Method is?");
   }

There is an error above being raised being we are not properly closing our class. To solve this issue we add a closing curly brace. After, the closing curly brace of my method.

public class Omar
{
   public static void main(String[] args)
   {
      myWonderfulMethod();
   }

   public static void myWonderfulMethod()
   {
      System.out.println("How Awesome do you think my Method is?");
   }
}

15 - unreachable statement

An "unreachable statement" error takes place when the compiler sees that it is impossible to reacha a certain statement. This is caused by the following code.

public class Omar
{
   public static void main(String[] args)
   {
      int theAwesomeNum = doubleMe(5);
      System.out.println(theAwesomeNum);
   }

   public static int doubleMe(int a)
   {
      int doubleMe = 2 * a;
      return doubleMe;
      System.out.println("Returning " + doubleMe);
   }
}

The compiler will generate a number of errors. The first one to be listed is that it is unable to reach the print statement. This is because whenever we create a method and use the keyword return the compiler says you are done with the method therefore, we can exit out of the method and execute the next line of code. To fix this error I simply reverse the order of the print statement and the return statement.

public class Omar
{
   public static void main(String[] args)
   {
      int theAwesomeNum = doubleMe(5);
      System.out.println(theAwesomeNum);
   }

   public static int doubleMe(int a)
   {
      int doubleMe = 2 * a;
      System.out.println("Returning " + doubleMe);
      return doubleMe;
   }
}

16 - Variable might not have been initialized

An variable might not have been initialized error is triggered when we declare a variable and specify its type but never give it an initial value;

   public class Omar
{
   public static void main(String[] args) {
      int myNum = 16;
      int myNum2;
      System.out.println(myNum + myNum2);
   }
} 

The compiler will generate the error variable myNum2 might not have been initialized because we declared it with the specified data type but never gave it an initial value. To solve this, I simply give it an initial value.

public class Omar
{
   public static void main(String[] args)
   {
      int myNum = 16;
      int myNum2=3;
      System.out.println(myNum + myNum2);
   }
} 

17 - constructor X in class X cannot be applied to given types

Invoke the super method in your subclass constructor. super()

18 - Cannot make a static reference to the non-static method logLn(object) from the type Omar

public class Omar
{
   public void logLn(object o){
      System.out.println(o);
   }

   public static void main(String[] args)
   {
      int myNum = 16;
      int myNum2=3;
      logLn(myNum + myNum2);
   }
}

I am getting this error because logLn should me a static method

public class Omar
{
   public static void logLn(object o){
      System.out.println(o);
   }

   public static void main(String[] args)
   {
      int myNum = 16;
      int myNum2=3;
      logLn(myNum + myNum2);
   }
}

Default Values For DT:

1- byte: 0

2- short: 0

3- int: 0

4- long: 0L

5- float: 0.0f

6- double: 0.0d

7- String(or any obj): null

8- bool: false

Wrapper Classes In Java and their Corresponding Primitive Types

  1. Boolean: boolean ..... 1 bit
  2. Byte: byte ..... 1 byte = 8bits
  3. Character: char ..... 2 bytes = 16bits
  4. Short: short ..... 2 bytes = 16bits
  5. Integer: int ..... 4 bytes = 32bits
  6. Float: float ..... 4 bytes = 32bits
  7. Double: double ..... 8 bytes = 32bits
  8. Long: long ..... 8 bytes = 32bits

Lombok Important Stuff In Java

  • Thanks to annotations I shorten commented out code to the next code
/*


private int luckyNum = 3532;
public int getLuckyNum() {
 return luckyNum;
} 
public void setLuckyNum(int luckyNum) {
  this.luckyNum = luckyNum;
}
*/
@Getter
@Setter
private int luckyNum = 3532;

ToString Annotation

@ToString(exclude="f")
public class Example

Equals And Hash Code Annotation

@EqualsAndHashCode(
        exclude={"id1", "id2"})
public class Example {
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].