Skip to main content

BBj for Java, Python, and C# Developers

If you are coming from Java, Python, or C#, this page maps the patterns you already know to their BBj equivalents. Each row shows how to accomplish a common task across all four languages. For detailed examples of each BBj pattern, follow the links to the relevant tutorial chapters.

Variables and Types

TaskJavaPythonC#BBj
Declare stringString s = "hi";s = "hi"string s = "hi";s$ = "hi"
Declare numberint n = 42;n = 42int n = 42;n = 42
Declare booleanboolean b = true;b = Truebool b = true;b = 1 (0/1 convention)
Null checkif (x == null)if x is None:if (x == null)if x! = null()
String to numberInteger.parseInt(s)int(s)int.Parse(s)num(s$)
Number to stringString.valueOf(n)str(n)n.ToString()str(n)

BBj uses suffixes to indicate type: $ for strings, ! for objects, no suffix for numbers. There is no boolean type -- use 0 for false and 1 (or any nonzero value) for true.

Control Flow

TaskJavaPythonC#BBj
If/elseif (x > 0) { } else { }if x > 0:if (x > 0) { } else { }if x > 0 then ... else ... fi
For loopfor (int i=0; i<10; i++)for i in range(10):for (int i=0; i<10; i++)for i = 0 to 9 ... next i
While loopwhile (cond) { }while cond:while (cond) { }while cond ... wend
For-eachfor (var item : list)for item in list:foreach (var item in list)for i=0 to list!.size()-1; item!=list!.get(i); next i
Switch/matchswitch (x) { case 1: }match x: case 1:switch (x) { case 1: }switch x; case 1; ...; swend

See Getting Started for BBj control flow syntax in detail.

Error Handling

TaskJavaPythonC#BBj
Set error handlertry {try:try {seterr handler
Catch specific errorcatch (IOException e)except IOError as e:catch (IOException e)if err = 17 then ...
Catch all errorscatch (Exception e)except Exception as e:catch (Exception e)seterr handler (global)
Get error messagee.getMessage()str(e)e.Messageerrmes(-1)
Raise/throwthrow new Exception("msg")raise Exception("msg")throw new Exception("msg")throw "msg", 256
Skip on errorcatch (E e) { }except: passcatch { }err=*next
Cleanupfinally { }finally:finally { }Fall-through to cleanup label

BBj does not have try/catch blocks. All error handling uses seterr to set a handler label, err= on individual statements for inline trapping, and throw to raise custom errors. See Error Handling for the complete model.

Strings

TaskJavaPythonC#BBj
Get lengths.length()len(s)s.Lengthlen(s$)
Substrings.substring(1, 4)s[1:4]s.Substring(1, 3)s$(2, 3) (1-based)
Find in strings.indexOf("x")s.find("x")s.IndexOf("x")pos("x" = s$)
Replaces.replace("a", "b")s.replace("a", "b")s.Replace("a", "b")stbl("!REPLACE", s$, "a", "b")
Splits.split(",")s.split(",")s.Split(',')Manual with pos() loop
Trims.trim()s.strip()s.Trim()cvs(s$, 3)
Uppercases.toUpperCase()s.upper()s.ToUpper()cvs(s$, 4)
Regex matchPattern.matches(p, s)re.match(p, s)Regex.IsMatch(s, p)mask(s$, p$)

BBj string positions are 1-based, not 0-based. pos() uses the syntax pos(needle$ = haystack$) with the needle on the left side of the = sign. See Strings and Numbers for details.

Collections

TaskJavaPythonC#BBj
Create listnew ArrayList()[]new List<T>()BBjAPI().makeVector()
Add itemlist.add(item)list.append(item)list.Add(item)vec!.add(item)
Get by indexlist.get(i)list[i]list[i]vec!.get(i)
List sizelist.size()len(list)list.Countvec!.size()
Create mapnew HashMap(){}new Dictionary<K,V>()new HashMap() (Java)
Put key/valuemap.put(k, v)d[k] = vd[k] = vmap!.put(k, v)
Get by keymap.get(k)d[k]d[k]map!.get(k)
Check containsmap.containsKey(k)k in dd.ContainsKey(k)map!.containsKey(k)

BBj uses BBjVector for ordered lists and java.util.HashMap for key-value maps. Since BBj runs on the JVM, you can use Java collection classes directly. See Collections for complete examples.

Classes and Objects

TaskJavaPythonC#BBj
Define classclass Foo { }class Foo:class Foo { }class public Foo ... classend
ConstructorFoo() { }def __init__(self):Foo() { }method public Foo() ... methodend
Instance methodvoid bar() { }def bar(self):void Bar() { }method public void bar() ... methodend
Static methodstatic void baz() { }@staticmethodstatic void Baz() { }method public static void baz() ... methodend
Inheritanceclass B extends Aclass B(A):class B : Aclass public B extends A
Interfaceinterface I { }class I(ABC):interface I { }interface public I ... interfaceend
Create instancenew Foo()Foo()new Foo()new Foo()
Instance field accessthis.fieldself.fieldthis.field#field or #field!

BBj Custom Objects use # to reference instance fields (similar to this. in Java). Classes can extend Java classes and implement Java interfaces. See Object-Oriented Programming for the full syntax.

File and Database

TaskJavaPythonC#BBj
Open DB connectionDriverManager.getConnection()sqlite3.connect()SqlConnection.Open()SQLOPEN(chan)"DbName"
Prepared statementconn.prepareStatement(sql)cursor.execute(sql, params)new SqlCommand(sql)SQLPREP(chan)sql$
Execute with paramsstmt.setString(1, val)Passed as tuplecmd.Parameters.Add()SQLEXEC(chan)val$
Fetch resultsrs.next() + rs.getString()cursor.fetchone()reader.Read()rec$ = SQLFETCH(chan, END=lbl)
Close connectionconn.close()conn.close()conn.Close()SQLCLOSE(chan)
Read fileFiles.readString(path)open(f).read()File.ReadAllText(path)OPEN(chan)f$; READ RECORD(chan)rec$

BBj SQL uses verbs (SQLOPEN, SQLPREP, SQLEXEC, SQLFETCH, SQLCLOSE) rather than objects. Parameters use ? placeholders in SQLPREP and are passed as arguments to SQLEXEC. See Database and SQL for complete patterns.

Events and Callbacks

TaskJavaPythonC#BBj
Register handlerbtn.addActionListener(l)btn.bind("<Click>", fn)btn.Click += handler;btn!.setCallback(BBjAPI.ON_BUTTON_PUSH, obj!, "method")
Handle eventvoid actionPerformed(e)def fn(event):void handler(s, e)method public void onPush(BBjButtonPushEvent ev!)
Event loopAutomatic (Swing EDT)root.mainloop()Application.Run()process_events

BBj uses setCallback with a string method name and an object reference. The event handler method receives a typed event parameter. See Event Handling for the callback model.


For detailed examples of each BBj pattern, follow the chapter links above. This page is a quick-reference starting point -- the tutorial chapters provide working code samples, error handling patterns, and best practices for each topic.