CS 61B: Data Structures and Algorithms

Dimethyl

Something About Java

To run code in file.java, we should firstly compile the .java file into a .class file by command of javac file.java and then run java file.

Why we use .class file? .class file are graranteed to have been typed checked, more efficient to execute and protect the actual source code.

Java is a statically typed language which means that all variables, parameters and methods must have a declared type. Their type can never be changed after declaration.

Java compiler performs a static type check, contrast to dynamically typed languages like Python, where users can run into type errors during execution.

All code in Java has to be part of a class.

Defining functions in Java. Functions must belong to some class. Those functions that are part of a class are commonly called methods.

Defining and using classes. A class which uses another class is called a client. Class can be instantiated with new and its instances are called Objects. The class can have its own variables called instance variables or non-static variables, which must be declared inside the class.

Sometimes we have static variables which can only be accessed by the name of class rather than name of instance.

Methods created in class without keyword static are called instance methods or non-static methods. Instance methods are actionis that can only be taken by specific instances of a class while static methods are actions that are taken by the class itself such as Math.sqrt method.

Variables and methods of a class are called members of a class. They can be accessed by ..

Once an object is instantiated, it can be assigned to a declared variable of appropriate type.

Constructor functions, similar to __init__ method in Python, can parameterized the instantiation.

public static void main(String[] args).

References, Recursion and Lists

The Java language provides no way for you to know the location of the box, unlike C or C++.

Java does nothing to the memory allocated for the variable when being defined. Fortunately, Java compiler will prevent you from using a variable until after the box has been filled with data using assignment operator =.

  • Title: CS 61B: Data Structures and Algorithms
  • Author: Dimethyl
  • Created at : 2025-06-25 18:33:35
  • Updated at : 2025-06-28 10:54:51
  • Link: https://dimethyl.online/2025/06/25/CS-61B-Data-Structure/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
CS 61B: Data Structures and Algorithms